script_msg.js 6.3 KB

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