script.js 6.7 KB

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