script.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //jQuery time
  2. var current_fs, next_fs, previous_fs; //fieldsets
  3. var left, opacity, scale; //fieldset properties which we will animate
  4. var animating; //flag to prevent quick multi-click glitches
  5. $(".next").click(function(){
  6. if( !validate() ){
  7. return false;
  8. }
  9. if(animating) return false;
  10. animating = true;
  11. current_fs = $(this).parent();
  12. next_fs = $(this).parent().next();
  13. //activate next step on progressbar using the index of next_fs
  14. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  15. //show the next fieldset
  16. next_fs.show();
  17. //hide the current fieldset with style
  18. current_fs.animate({opacity: 0}, {
  19. step: function(now, mx) {
  20. //as the opacity of current_fs reduces to 0 - stored in "now"
  21. //1. scale current_fs down to 80%
  22. scale = 1 - (1 - now) * 0.2;
  23. //2. bring next_fs from the right(50%)
  24. left = (now * 50)+"%";
  25. //3. increase opacity of next_fs to 1 as it moves in
  26. opacity = 1 - now;
  27. current_fs.css({
  28. 'transform': 'scale('+scale+')',
  29. 'position': 'absolute'
  30. });
  31. next_fs.css({'left': left, 'opacity': opacity});
  32. },
  33. duration: 800,
  34. complete: function(){
  35. current_fs.hide();
  36. animating = false;
  37. },
  38. //this comes from the custom easing plugin
  39. easing: 'easeInOutBack'
  40. });
  41. });
  42. $(".previous").click(function(){
  43. if(animating) return false;
  44. animating = true;
  45. current_fs = $(this).parent();
  46. previous_fs = $(this).parent().prev();
  47. //de-activate current step on progressbar
  48. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  49. //show the previous fieldset
  50. previous_fs.show();
  51. //hide the current fieldset with style
  52. current_fs.animate({opacity: 0}, {
  53. step: function(now, mx) {
  54. //as the opacity of current_fs reduces to 0 - stored in "now"
  55. //1. scale previous_fs from 80% to 100%
  56. scale = 0.8 + (1 - now) * 0.2;
  57. //2. take current_fs to the right(50%) - from 0%
  58. left = ((1-now) * 50)+"%";
  59. //3. increase opacity of previous_fs to 1 as it moves in
  60. opacity = 1 - now;
  61. current_fs.css({'left': left});
  62. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  63. },
  64. duration: 800,
  65. complete: function(){
  66. current_fs.hide();
  67. animating = false;
  68. },
  69. //this comes from the custom easing plugin
  70. easing: 'easeInOutBack'
  71. });
  72. });
  73. $("input[name=submit]").click(function(){
  74. let stop;
  75. console.log($("#msform").serialize());
  76. if( $('input[name="q9"]:visible').val() !== undefined && !$('input[name="q9"]:visible').prop('checked') ) {
  77. stop = 1;
  78. $('#term-error').text('必須同意免責聲明與隱私使用政策');
  79. }else {
  80. stop = 0;
  81. $('#term-error').text('');
  82. }
  83. if(stop == 0) {
  84. /* $.ajax({
  85. url: '/step_questions/submit',
  86. type: 'post',
  87. dataType: 'json',
  88. data: $("#msform").serialize(),
  89. success: function(data) {
  90. showThankyou();
  91. },
  92. error: function (error) {
  93. console.error(error)
  94. }
  95. }); */
  96. showThankyou();
  97. }
  98. });
  99. // 依據管道導頁
  100. function showThankyou() {
  101. axios.get('http://q.ptt.cx/coffee').then(res => {
  102. if(res.data.coffee == 1) {
  103. document.location = '/a1/index_complete_line.html';
  104. } else {
  105. document.location = '/a1/index_complete_line_after.html';
  106. }
  107. });
  108. // document.location = '/a1/index_complete_line.html';
  109. }
  110. // 跳離頁面
  111. $('.btn-exit').click(function() {
  112. document.location = 'https://hhh.com.tw/';
  113. })
  114. $('.btn-term-exit').click(function () {
  115. self.opener = null;
  116. self.close();
  117. })
  118. function show_input_text(checkbox_id, input_id) {
  119. var checkBox = document.getElementById(checkbox_id);
  120. var inp = document.getElementById(input_id);
  121. if (checkBox.checked == true){
  122. inp.style.display = "block";
  123. } else {
  124. inp.style.display = "none";
  125. }
  126. }
  127. function validate() {
  128. function q2_validate() {
  129. let phoneno = /^\d{10}$/;
  130. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  131. $('input[name="q2"]:visible').addClass('error');
  132. if( !$('.error-text').length )
  133. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  134. return false;
  135. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  136. $('input[name="q2"]:visible').addClass('error');
  137. if( !$('.error-text').length )
  138. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  139. return false;
  140. }else {
  141. $('input[name="q2"]:visible').removeClass('error');
  142. $('.error-text').remove();
  143. return true;
  144. }
  145. }
  146. function q3_validate() {
  147. let emailPattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  148. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  149. $('input[name="q3"]:visible').addClass('error');
  150. if( !$('.error-text').length )
  151. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  152. return false;
  153. } else if ( $('input[name="q3"]:visible').val() !== undefined && !emailPattern.test($('input[name="q3"]:visible').val()) ){
  154. $('input[name="q3"]:visible').addClass('error');
  155. if( !$('.error-text').length )
  156. $('input.error').after('<p class="error-text">請輸入正確email格式</p>');
  157. return false;
  158. }
  159. else {
  160. $('input[name="q3"]:visible').removeClass('error');
  161. $('.error-text').remove();
  162. return true;
  163. }
  164. }
  165. function q4_validate() {
  166. if( $('input[name="q4"]:visible').val() !== undefined && $('input[name="q4"]:visible').val().length <= 0 ) {
  167. $('input[name="q4"]:visible').addClass('error');
  168. if( !$('.error-text').length )
  169. $('input.error').after('<p class="error-text">請輸入建案名稱</p>');
  170. return false;
  171. }
  172. else {
  173. $('input[name="q4"]:visible').removeClass('error');
  174. $('.error-text').remove();
  175. return true;
  176. }
  177. }
  178. return q2_validate() && q3_validate() && q4_validate();
  179. }