PageRenderTime 25ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 1ms

/public/theme/neon/assets/js/neon-forgotpassword.js

https://gitlab.com/Arevico/personal-finance
JavaScript | 236 lines | 166 code | 50 blank | 20 comment | 5 complexity | b3deabe76910830912959b04309ad0ae MD5 | raw file
  1. /**
  2. * Neon Register Script
  3. *
  4. * Developed by Arlind Nushi - www.laborator.co
  5. */
  6. var neonForgotPassword = neonForgotPassword || {};
  7. ;(function($, window, undefined)
  8. {
  9. "use strict";
  10. $(document).ready(function()
  11. {
  12. neonForgotPassword.$container = $("#form_forgot_password");
  13. neonForgotPassword.$steps = neonForgotPassword.$container.find(".form-steps");
  14. neonForgotPassword.$steps_list = neonForgotPassword.$steps.find(".step");
  15. neonForgotPassword.step = 'step-1'; // current step
  16. neonForgotPassword.$container.validate({
  17. rules: {
  18. email: {
  19. required: true,
  20. email: true
  21. }
  22. },
  23. messages: {
  24. email: {
  25. email: 'Invalid E-mail.'
  26. }
  27. },
  28. highlight: function(element){
  29. $(element).closest('.input-group').addClass('validate-has-error');
  30. },
  31. unhighlight: function(element)
  32. {
  33. $(element).closest('.input-group').removeClass('validate-has-error');
  34. },
  35. submitHandler: function(ev)
  36. {
  37. $(".login-page").addClass('logging-in');
  38. // We consider its 30% completed form inputs are filled
  39. neonForgotPassword.setPercentage(30, function()
  40. {
  41. // Lets move to 98%, meanwhile ajax data are sending and processing
  42. neonForgotPassword.setPercentage(98, function()
  43. {
  44. // Send data to the server
  45. $.ajax({
  46. url: baseurl + 'data/sample-forgotpassword-form.php',
  47. method: 'POST',
  48. dataType: 'json',
  49. data: {
  50. email: $("input#email").val(),
  51. },
  52. error: function()
  53. {
  54. alert("An error occoured!");
  55. },
  56. success: function(response)
  57. {
  58. // From response you can fetch the data object retured
  59. var email = response.submitted_data.email;
  60. // Form is fully completed, we update the percentage
  61. neonForgotPassword.setPercentage(100);
  62. // We will give some time for the animation to finish, then execute the following procedures
  63. setTimeout(function()
  64. {
  65. // Hide the description title
  66. $(".login-page .login-header .description").slideUp();
  67. // Hide the register form (steps)
  68. neonForgotPassword.$steps.slideUp('normal', function()
  69. {
  70. // Remove loging-in state
  71. $(".login-page").removeClass('logging-in');
  72. // Now we show the success message
  73. $(".form-forgotpassword-success").slideDown('normal');
  74. // You can use the data returned from response variable
  75. });
  76. }, 1000);
  77. }
  78. });
  79. });
  80. });
  81. }
  82. });
  83. // Steps Handler
  84. neonForgotPassword.$steps.find('[data-step]').on('click', function(ev)
  85. {
  86. ev.preventDefault();
  87. var $current_step = neonForgotPassword.$steps_list.filter('.current'),
  88. next_step = $(this).data('step'),
  89. validator = neonForgotPassword.$container.data('validator'),
  90. errors = 0;
  91. neonForgotPassword.$container.valid();
  92. errors = validator.numberOfInvalids();
  93. if(errors)
  94. {
  95. validator.focusInvalid();
  96. }
  97. else
  98. {
  99. var $next_step = neonForgotPassword.$steps_list.filter('#' + next_step),
  100. $other_steps = neonForgotPassword.$steps_list.not( $next_step ),
  101. current_step_height = $current_step.data('height'),
  102. next_step_height = $next_step.data('height');
  103. TweenMax.set(neonForgotPassword.$steps, {css: {height: current_step_height}});
  104. TweenMax.to(neonForgotPassword.$steps, 0.6, {css: {height: next_step_height}});
  105. TweenMax.to($current_step, .3, {css: {autoAlpha: 0}, onComplete: function()
  106. {
  107. $current_step.attr('style', '').removeClass('current');
  108. var $form_elements = $next_step.find('.form-group');
  109. TweenMax.set($form_elements, {css: {autoAlpha: 0}});
  110. $next_step.addClass('current');
  111. $form_elements.each(function(i, el)
  112. {
  113. var $form_element = $(el);
  114. TweenMax.to($form_element, .2, {css: {autoAlpha: 1}, delay: i * .09});
  115. });
  116. setTimeout(function()
  117. {
  118. $form_elements.add($next_step).add($next_step).attr('style', '');
  119. $form_elements.first().find('input').focus();
  120. }, 1000 * (.5 + ($form_elements.length - 1) * .09));
  121. }});
  122. }
  123. });
  124. neonForgotPassword.$steps_list.each(function(i, el)
  125. {
  126. var $this = $(el),
  127. is_current = $this.hasClass('current'),
  128. margin = 20;
  129. if(is_current)
  130. {
  131. $this.data('height', $this.outerHeight() + margin);
  132. }
  133. else
  134. {
  135. $this.addClass('current').data('height', $this.outerHeight() + margin).removeClass('current');
  136. }
  137. });
  138. // Login Form Setup
  139. neonForgotPassword.$body = $(".login-page");
  140. neonForgotPassword.$login_progressbar_indicator = $(".login-progressbar-indicator h3");
  141. neonForgotPassword.$login_progressbar = neonForgotPassword.$body.find(".login-progressbar div");
  142. neonForgotPassword.$login_progressbar_indicator.html('0%');
  143. if(neonForgotPassword.$body.hasClass('login-form-fall'))
  144. {
  145. var focus_set = false;
  146. setTimeout(function(){
  147. neonForgotPassword.$body.addClass('login-form-fall-init')
  148. setTimeout(function()
  149. {
  150. if( !focus_set)
  151. {
  152. neonForgotPassword.$container.find('input:first').focus();
  153. focus_set = true;
  154. }
  155. }, 550);
  156. }, 0);
  157. }
  158. else
  159. {
  160. neonForgotPassword.$container.find('input:first').focus();
  161. }
  162. // Functions
  163. $.extend(neonForgotPassword, {
  164. setPercentage: function(pct, callback)
  165. {
  166. pct = parseInt(pct / 100 * 100, 10) + '%';
  167. // Normal Login
  168. neonForgotPassword.$login_progressbar_indicator.html(pct);
  169. neonForgotPassword.$login_progressbar.width(pct);
  170. var o = {
  171. pct: parseInt(neonForgotPassword.$login_progressbar.width() / neonForgotPassword.$login_progressbar.parent().width() * 100, 10)
  172. };
  173. TweenMax.to(o, .7, {
  174. pct: parseInt(pct, 10),
  175. roundProps: ["pct"],
  176. ease: Sine.easeOut,
  177. onUpdate: function()
  178. {
  179. neonForgotPassword.$login_progressbar_indicator.html(o.pct + '%');
  180. },
  181. onComplete: callback
  182. });
  183. }
  184. });
  185. });
  186. })(jQuery, window);