script.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. if(animating) return false;
  10. animating = true;
  11. current_fs = $(this).parent();
  12. next_fs = $(this).parent().next();
  13. //activate next step on progressbar using the index of next_fs
  14. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  15. //show the next fieldset
  16. next_fs.show();
  17. //hide the current fieldset with style
  18. current_fs.animate({opacity: 0}, {
  19. step: function(now, mx) {
  20. //as the opacity of current_fs reduces to 0 - stored in "now"
  21. //1. scale current_fs down to 80%
  22. scale = 1 - (1 - now) * 0.2;
  23. //2. bring next_fs from the right(50%)
  24. left = (now * 50)+"%";
  25. //3. increase opacity of next_fs to 1 as it moves in
  26. opacity = 1 - now;
  27. current_fs.css({
  28. 'transform': 'scale('+scale+')',
  29. 'position': 'absolute'
  30. });
  31. next_fs.css({'left': left, 'opacity': opacity});
  32. },
  33. duration: 800,
  34. complete: function(){
  35. current_fs.hide();
  36. animating = false;
  37. },
  38. //this comes from the custom easing plugin
  39. easing: 'easeInOutBack'
  40. });
  41. });
  42. $(".previous").click(function(){
  43. if(animating) return false;
  44. animating = true;
  45. current_fs = $(this).parent();
  46. previous_fs = $(this).parent().prev();
  47. //de-activate current step on progressbar
  48. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  49. //show the previous fieldset
  50. previous_fs.show();
  51. //hide the current fieldset with style
  52. current_fs.animate({opacity: 0}, {
  53. step: function(now, mx) {
  54. //as the opacity of current_fs reduces to 0 - stored in "now"
  55. //1. scale previous_fs from 80% to 100%
  56. scale = 0.8 + (1 - now) * 0.2;
  57. //2. take current_fs to the right(50%) - from 0%
  58. left = ((1-now) * 50)+"%";
  59. //3. increase opacity of previous_fs to 1 as it moves in
  60. opacity = 1 - now;
  61. current_fs.css({'left': left});
  62. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  63. },
  64. duration: 800,
  65. complete: function(){
  66. current_fs.hide();
  67. animating = false;
  68. },
  69. //this comes from the custom easing plugin
  70. easing: 'easeInOutBack'
  71. });
  72. });
  73. $("input[name=submit]").click(function(){
  74. /* console.log($("#msform").serialize());
  75. $.ajax({
  76. url: 'http://127.0.0.1:8000/step_questions/submit',
  77. type: 'post',
  78. dataType: 'json',
  79. data: $("#msform").serialize(),
  80. success: function(data) {
  81. showThankyou();
  82. }
  83. });
  84. return false; */
  85. showThankyou();
  86. })
  87. function showThankyou() {
  88. $('#overlay').show();
  89. }
  90. $('.btn-exit').click(function() {
  91. document.location = 'https://hhh.com.tw/'
  92. })
  93. function show_input_text(checkbox_id, input_id) {
  94. var checkBox = document.getElementById(checkbox_id);
  95. var inp = document.getElementById(input_id);
  96. if (checkBox.checked == true){
  97. inp.style.display = "block";
  98. } else {
  99. inp.style.display = "none";
  100. }
  101. }
  102. function validate() {
  103. function q2_validate() {
  104. let phoneno = /^\d{10}$/;
  105. if( $('input[name="q2"]:visible').val() !== undefined && $('input[name="q2"]:visible').val().length <= 0) {
  106. $('input[name="q2"]:visible').addClass('error');
  107. if( !$('.error-text').length )
  108. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  109. return false;
  110. } else if($('input[name="q2"]:visible').val() !== undefined && !phoneno.test($('input[name="q2"]:visible').val())){
  111. $('input[name="q2"]:visible').addClass('error');
  112. if( !$('.error-text').length )
  113. $('input.error').after('<p class="error-text">請輸入正確手機號碼</p>');
  114. return false;
  115. }else {
  116. $('input[name="q2"]:visible').removeClass('error');
  117. $('.error-text').remove();
  118. return true;
  119. }
  120. }
  121. function q3_validate() {
  122. if( $('input[name="q3"]:visible').val() !== undefined && $('input[name="q3"]:visible').val().length <= 0) {
  123. $('input[name="q3"]:visible').addClass('error');
  124. if( !$('.error-text').length )
  125. $('input.error').after('<p class="error-text">請輸入E-mail</p>');
  126. return false;
  127. }
  128. else {
  129. $('input[name="q3"]:visible').removeClass('error');
  130. $('.error-text').remove();
  131. return true;
  132. }
  133. }
  134. return q2_validate() && q3_validate()
  135. }