script_msg.js 6.4 KB

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