script_msg.js 5.8 KB

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