Guest User

Untitled

a guest
Apr 3rd, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | None | 0 0
  1. /**
  2. * Neon Login Script
  3. *
  4. * Developed by Arlind Nushi - www.laborator.co
  5. */
  6.  
  7. var neonLogin = neonLogin || {};
  8.  
  9. ;(function($, window, undefined)
  10. {
  11. "use strict";
  12.  
  13. $(document).ready(function()
  14. {
  15. neonLogin.$container = $("#form_login");
  16.  
  17.  
  18. // Login Form & Validation
  19. neonLogin.$container.validate({
  20. rules: {
  21. username: {
  22. required: true
  23. },
  24.  
  25. password: {
  26. required: true
  27. },
  28.  
  29. },
  30.  
  31. highlight: function(element){
  32. $(element).closest('.input-group').addClass('validate-has-error');
  33. },
  34.  
  35.  
  36. unhighlight: function(element)
  37. {
  38. $(element).closest('.input-group').removeClass('validate-has-error');
  39. },
  40.  
  41. submitHandler: function(ev)
  42. {
  43. /*
  44. Updated on v1.1.4
  45. Login form now processes the login data, here is the file: data/sample-login-form.php
  46. */
  47.  
  48. $(".login-page").addClass('logging-in'); // This will hide the login form and init the progress bar
  49.  
  50.  
  51. // Hide Errors
  52. $(".form-login-error").slideUp('fast');
  53.  
  54. // We will wait till the transition ends
  55. setTimeout(function()
  56. {
  57. var random_pct = 25 + Math.round(Math.random() * 30);
  58.  
  59. // The form data are subbmitted, we can forward the progress to 70%
  60. neonLogin.setPercentage(40 + random_pct);
  61.  
  62. // Send data to the server
  63.  
  64. $.ajax({
  65. url: baseurl + 'data/sample-login-form.php',
  66. method: 'POST',
  67. dataType: 'json',
  68. data: {
  69. username: $("#username").val(),
  70. password: $("#password").val(),
  71. },
  72. error: function()
  73. {
  74. alert("An error occoured!");
  75. },
  76. success: function(response)
  77. {
  78. // Login status [success|invalid]
  79. var login_status = response.login_status;
  80.  
  81. // Form is fully completed, we update the percentage
  82. neonLogin.setPercentage(100);
  83.  
  84.  
  85. // We will give some time for the animation to finish, then execute the following procedures
  86. setTimeout(function()
  87. {
  88. // If login is invalid, we store the
  89. if(login_status == 'invalid')
  90. {
  91. $(".login-page").removeClass('logging-in');
  92. neonLogin.resetProgressBar(true);
  93. }
  94. else
  95. if(login_status == 'success')
  96. {
  97. // Redirect to login page
  98. setTimeout(function()
  99. {
  100. var redirect_url = baseurl;
  101.  
  102. if(response.redirect_url && response.redirect_url.length)
  103. {
  104. redirect_url = response.redirect_url;
  105. }
  106.  
  107. window.location.href = redirect_url;
  108. }, 400);
  109. }
  110.  
  111. }, 1000);
  112. }
  113. });
  114.  
  115.  
  116. }, 650);
  117. }
  118. });
  119.  
  120.  
  121.  
  122.  
  123. // Lockscreen & Validation
  124. var is_lockscreen = $(".login-page").hasClass('is-lockscreen');
  125.  
  126. if(is_lockscreen)
  127. {
  128. neonLogin.$container = $("#form_lockscreen");
  129. neonLogin.$ls_thumb = neonLogin.$container.find('.lockscreen-thumb');
  130.  
  131. neonLogin.$container.validate({
  132. rules: {
  133.  
  134. password: {
  135. required: true
  136. },
  137.  
  138. },
  139.  
  140. highlight: function(element){
  141. $(element).closest('.input-group').addClass('validate-has-error');
  142. },
  143.  
  144.  
  145. unhighlight: function(element)
  146. {
  147. $(element).closest('.input-group').removeClass('validate-has-error');
  148. },
  149.  
  150. submitHandler: function(ev)
  151. {
  152. /*
  153. Demo Purpose Only
  154.  
  155. Here you can handle the page login, currently it does not process anything, just fills the loader.
  156. */
  157.  
  158. $(".login-page").addClass('logging-in-lockscreen'); // This will hide the login form and init the progress bar
  159.  
  160. // We will wait till the transition ends
  161. setTimeout(function()
  162. {
  163. var random_pct = 25 + Math.round(Math.random() * 30);
  164.  
  165. neonLogin.setPercentage(random_pct, function()
  166. {
  167. // Just an example, this is phase 1
  168. // Do some stuff...
  169.  
  170. // After 0.77s second we will execute the next phase
  171. setTimeout(function()
  172. {
  173. neonLogin.setPercentage(100, function()
  174. {
  175. // Just an example, this is phase 2
  176. // Do some other stuff...
  177.  
  178. // Redirect to the page
  179. setTimeout("window.location.href = '../../'", 600);
  180. }, 2);
  181.  
  182. }, 820);
  183. });
  184.  
  185. }, 650);
  186. }
  187. });
  188. }
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. // Login Form Setup
  196. neonLogin.$body = $(".login-page");
  197. neonLogin.$login_progressbar_indicator = $(".login-progressbar-indicator h3");
  198. neonLogin.$login_progressbar = neonLogin.$body.find(".login-progressbar div");
  199.  
  200. neonLogin.$login_progressbar_indicator.html('0%');
  201.  
  202. if(neonLogin.$body.hasClass('login-form-fall'))
  203. {
  204. var focus_set = false;
  205.  
  206. setTimeout(function(){
  207. neonLogin.$body.addClass('login-form-fall-init')
  208.  
  209. setTimeout(function()
  210. {
  211. if( !focus_set)
  212. {
  213. neonLogin.$container.find('input:first').focus();
  214. focus_set = true;
  215. }
  216.  
  217. }, 550);
  218.  
  219. }, 0);
  220. }
  221. else
  222. {
  223. neonLogin.$container.find('input:first').focus();
  224. }
  225.  
  226. // Focus Class
  227. neonLogin.$container.find('.form-control').each(function(i, el)
  228. {
  229. var $this = $(el),
  230. $group = $this.closest('.input-group');
  231.  
  232. $this.prev('.input-group-addon').click(function()
  233. {
  234. $this.focus();
  235. });
  236.  
  237. $this.on({
  238. focus: function()
  239. {
  240. $group.addClass('focused');
  241. },
  242.  
  243. blur: function()
  244. {
  245. $group.removeClass('focused');
  246. }
  247. });
  248. });
  249.  
  250. // Functions
  251. $.extend(neonLogin, {
  252. setPercentage: function(pct, callback)
  253. {
  254. pct = parseInt(pct / 100 * 100, 10) + '%';
  255.  
  256. // Lockscreen
  257. if(is_lockscreen)
  258. {
  259. neonLogin.$lockscreen_progress_indicator.html(pct);
  260.  
  261. var o = {
  262. pct: currentProgress
  263. };
  264.  
  265. TweenMax.to(o, .7, {
  266. pct: parseInt(pct, 10),
  267. roundProps: ["pct"],
  268. ease: Sine.easeOut,
  269. onUpdate: function()
  270. {
  271. neonLogin.$lockscreen_progress_indicator.html(o.pct + '%');
  272. drawProgress(parseInt(o.pct, 10)/100);
  273. },
  274. onComplete: callback
  275. });
  276. return;
  277. }
  278.  
  279. // Normal Login
  280. neonLogin.$login_progressbar_indicator.html(pct);
  281. neonLogin.$login_progressbar.width(pct);
  282.  
  283. var o = {
  284. pct: parseInt(neonLogin.$login_progressbar.width() / neonLogin.$login_progressbar.parent().width() * 100, 10)
  285. };
  286.  
  287. TweenMax.to(o, .7, {
  288. pct: parseInt(pct, 10),
  289. roundProps: ["pct"],
  290. ease: Sine.easeOut,
  291. onUpdate: function()
  292. {
  293. neonLogin.$login_progressbar_indicator.html(o.pct + '%');
  294. },
  295. onComplete: callback
  296. });
  297. },
  298.  
  299. resetProgressBar: function(display_errors)
  300. {
  301. TweenMax.set(neonLogin.$container, {css: {opacity: 0}});
  302.  
  303. setTimeout(function()
  304. {
  305. TweenMax.to(neonLogin.$container, .6, {css: {opacity: 1}, onComplete: function()
  306. {
  307. neonLogin.$container.attr('style', '');
  308. }});
  309.  
  310. neonLogin.$login_progressbar_indicator.html('0%');
  311. neonLogin.$login_progressbar.width(0);
  312.  
  313. if(display_errors)
  314. {
  315. var $errors_container = $(".form-login-error");
  316.  
  317. $errors_container.show();
  318. var height = $errors_container.outerHeight();
  319.  
  320. $errors_container.css({
  321. height: 0
  322. });
  323.  
  324. TweenMax.to($errors_container, .45, {css: {height: height}, onComplete: function()
  325. {
  326. $errors_container.css({height: 'auto'});
  327. }});
  328.  
  329. // Reset password fields
  330. neonLogin.$container.find('input[type="password"]').val('');
  331. }
  332.  
  333. }, 800);
  334. }
  335. });
  336.  
  337.  
  338. // Lockscreen Create Canvas
  339. if(is_lockscreen)
  340. {
  341. neonLogin.$lockscreen_progress_canvas = $('<canvas></canvas>');
  342. neonLogin.$lockscreen_progress_indicator = neonLogin.$container.find('.lockscreen-progress-indicator');
  343.  
  344. neonLogin.$lockscreen_progress_canvas.appendTo(neonLogin.$ls_thumb);
  345.  
  346. var thumb_size = neonLogin.$ls_thumb.width();
  347.  
  348. neonLogin.$lockscreen_progress_canvas.attr({
  349. width: thumb_size,
  350. height: thumb_size
  351. });
  352.  
  353.  
  354. neonLogin.lockscreen_progress_canvas = neonLogin.$lockscreen_progress_canvas.get(0);
  355.  
  356. // Create Progress Circle
  357. var bg = neonLogin.lockscreen_progress_canvas,
  358. ctx = ctx = bg.getContext('2d'),
  359. imd = null,
  360. circ = Math.PI * 2,
  361. quart = Math.PI / 2,
  362. currentProgress = 0;
  363.  
  364. ctx.beginPath();
  365. ctx.strokeStyle = '#eb7067';
  366. ctx.lineCap = 'square';
  367. ctx.closePath();
  368. ctx.fill();
  369. ctx.lineWidth = 3.0;
  370.  
  371. imd = ctx.getImageData(0, 0, thumb_size, thumb_size);
  372.  
  373. var drawProgress = function(current) {
  374. ctx.putImageData(imd, 0, 0);
  375. ctx.beginPath();
  376. ctx.arc(thumb_size/2, thumb_size/2, 70, -(quart), ((circ) * current) - quart, false);
  377. ctx.stroke();
  378.  
  379. currentProgress = current * 100;
  380. }
  381.  
  382. drawProgress(0/100);
  383.  
  384.  
  385. neonLogin.$lockscreen_progress_indicator.html('0%');
  386.  
  387. ctx.restore();
  388. }
  389.  
  390. });
  391.  
  392. })(jQuery, window);
Add Comment
Please, Sign In to add comment