script_msg.js 5.8 KB

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