script_msg.js 6.4 KB

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