Advertisement
Guest User

Untitled

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