script_msg.js 6.4 KB

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