script_msg.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. document.location = '/a1/index_complete_msg.html';
  102. // document.location = '/a1/index_complete_line.html';
  103. }
  104. // 跳離頁面
  105. $('.btn-exit').click(function() {
  106. document.location = 'https://hhh.com.tw/';
  107. })
  108. $('.btn-term-exit').click(function () {
  109. self.opener = null;
  110. self.close();
  111. })
  112. function show_input_text(checkbox_id, input_id) {
  113. var checkBox = document.getElementById(checkbox_id);
  114. var inp = document.getElementById(input_id);
  115. if (checkBox.checked == true){
  116. inp.style.display = "block";
  117. } else {
  118. inp.style.display = "none";
  119. }
  120. }
  121. function validate() {
  122. function q2_validate() {
  123. let phoneno = /^\d{10}$/;
  124. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  125. $('input[name="q2"]:visible').addClass('error');
  126. if( !$('.error-text').length )
  127. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  128. return false;
  129. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  130. $('input[name="q2"]:visible').addClass('error');
  131. if( !$('.error-text').length )
  132. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  133. return false;
  134. }else {
  135. $('input[name="q2"]:visible').removeClass('error');
  136. $('.error-text').remove();
  137. return true;
  138. }
  139. }
  140. function q3_validate() {
  141. 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,}))$/;
  142. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  143. $('input[name="q3"]:visible').addClass('error');
  144. if( !$('.error-text').length )
  145. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  146. return false;
  147. } else if ( $('input[name="q3"]:visible').val() !== undefined && !emailPattern.test($('input[name="q3"]:visible').val()) ){
  148. $('input[name="q3"]:visible').addClass('error');
  149. if( !$('.error-text').length )
  150. $('input.error').after('<p class="error-text">請輸入正確email格式</p>');
  151. return false;
  152. }
  153. else {
  154. $('input[name="q3"]:visible').removeClass('error');
  155. $('.error-text').remove();
  156. return true;
  157. }
  158. }
  159. function q4_validate() {
  160. if( $('input[name="q4"]:visible').val() !== undefined && $('input[name="q4"]:visible').val().length <= 0 ) {
  161. $('input[name="q4"]:visible').addClass('error');
  162. if( !$('.error-text').length )
  163. $('input.error').after('<p class="error-text">請輸入建案名稱</p>');
  164. return false;
  165. }
  166. else {
  167. $('input[name="q4"]:visible').removeClass('error');
  168. $('.error-text').remove();
  169. return true;
  170. }
  171. }
  172. return q2_validate() && q3_validate() && q4_validate();
  173. }