Advertisement
Guest User

Untitled

a guest
Jan 14th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         // Login Form & Validation
  18.         neonLogin.$container.validate({
  19.             rules: {
  20.                 username: {
  21.                     required: true 
  22.                 },
  23.                
  24.                 password: {
  25.                     required: true
  26.                 },
  27.                
  28.             },
  29.            
  30.             highlight: function(element){
  31.                 $(element).closest('.input-group').addClass('validate-has-error');
  32.             },
  33.            
  34.            
  35.             unhighlight: function(element)
  36.             {
  37.                 $(element).closest('.input-group').removeClass('validate-has-error');
  38.             },
  39.            
  40.             submitHandler: function(ev)
  41.             {
  42.                 neonLogin.setPercentage(10);// this is just how you want to show users login process, it can be any value from 0-100
  43.                
  44.                 // Now send the login data to the server
  45.                 var submitted_username = $("#username").val(),
  46.                     submitted_password = $("#password").val();
  47.                
  48.                 // Do login via ajax
  49.                 $.ajax({
  50.                     url: "your-login-process-file.php", // Your php script to wait for login connections and set login sessions
  51.                     type: "POST",
  52.                     // You can access the user and pass with $_POST['username'] and $_POST['password']
  53.                     data: {
  54.                         username: submitted_username,
  55.                         password: submitted_password
  56.                     },
  57.                
  58.                     success: function(response_text) // response_text - is what you output based on user login information, lets suggest you output numbers i.e. 1 means logged in, 2 password incorred, 3 any other reason...
  59.                     {
  60.                         if(response_text)
  61.                         {
  62.                             neonLogin.setPercentage(100); // update the percentage to 100%
  63.                
  64.                             // We will wait (not necessary) till the animation is finished and then redirect to dashboard
  65.                             setTimeout(function()
  66.                             {
  67.                                 window.location.href = 'logged-in.php'; // after this, its done!
  68.                             }, 1000);
  69.                         }
  70.                     }
  71.                 });
  72.             }
  73.         });
  74.        
  75.        
  76.        
  77.        
  78.         // Lockscreen & Validation
  79.         var is_lockscreen = $(".login-page").hasClass('is-lockscreen');
  80.        
  81.         if(is_lockscreen)
  82.         {
  83.             neonLogin.$container = $("#form_lockscreen");
  84.             neonLogin.$ls_thumb = neonLogin.$container.find('.lockscreen-thumb');
  85.            
  86.             neonLogin.$container.validate({
  87.                 rules: {
  88.                
  89.                     password: {
  90.                         required: true
  91.                     },
  92.                    
  93.                 },
  94.                
  95.                 highlight: function(element){
  96.                     $(element).closest('.input-group').addClass('validate-has-error');
  97.                 },
  98.                
  99.                
  100.                 unhighlight: function(element)
  101.                 {
  102.                     $(element).closest('.input-group').removeClass('validate-has-error');
  103.                 },
  104.                
  105.                 submitHandler: function(ev)
  106.                 {  
  107.                     /*
  108.                         Demo Purpose Only
  109.                        
  110.                         Here you can handle the page login, currently it does not process anything, just fills the loader.
  111.                     */
  112.                    
  113.                     $(".login-page").addClass('logging-in-lockscreen'); // This will hide the login form and init the progress bar
  114.    
  115.                     // We will wait till the transition ends               
  116.                     setTimeout(function()
  117.                     {
  118.                         var random_pct = 25 + Math.round(Math.random() * 30);
  119.                        
  120.                         neonLogin.setPercentage(random_pct, function()
  121.                         {
  122.                             // Just an example, this is phase 1
  123.                             // Do some stuff...
  124.                            
  125.                             // After 0.77s second we will execute the next phase
  126.                             setTimeout(function()
  127.                             {
  128.                                 neonLogin.setPercentage(100, function()
  129.                                 {
  130.                                     // Just an example, this is phase 2
  131.                                     // Do some other stuff...
  132.                                    
  133.                                     // Redirect to the page
  134.                                     setTimeout("window.location.href = '../../'", 600);
  135.                                 }, 2);
  136.                                
  137.                             }, 820);
  138.                         });
  139.                        
  140.                     }, 650);
  141.                 }
  142.             });
  143.         }
  144.        
  145.        
  146.        
  147.        
  148.        
  149.        
  150.         // Login Form Setup
  151.         neonLogin.$body = $(".login-page");
  152.         neonLogin.$login_progressbar_indicator = $(".login-progressbar-indicator h3");
  153.         neonLogin.$login_progressbar = neonLogin.$body.find(".login-progressbar div");
  154.        
  155.         neonLogin.$login_progressbar_indicator.html('0%');
  156.        
  157.         if(neonLogin.$body.hasClass('login-form-fall'))
  158.         {
  159.             var focus_set = false;
  160.            
  161.             setTimeout(function(){
  162.                 neonLogin.$body.addClass('login-form-fall-init')
  163.                
  164.                 setTimeout(function()
  165.                 {
  166.                     if( !focus_set)
  167.                     {
  168.                         neonLogin.$container.find('input:first').focus();
  169.                         focus_set = true;
  170.                     }
  171.                    
  172.                 }, 550);
  173.                
  174.             }, 0);
  175.         }
  176.         else
  177.         {
  178.             neonLogin.$container.find('input:first').focus();
  179.         }
  180.        
  181.         // Focus Class
  182.         neonLogin.$container.find('.form-control').each(function(i, el)
  183.         {
  184.             var $this = $(el),
  185.                 $group = $this.closest('.input-group');
  186.            
  187.             $this.prev('.input-group-addon').click(function()
  188.             {
  189.                 $this.focus();
  190.             });
  191.            
  192.             $this.on({
  193.                 focus: function()
  194.                 {
  195.                     $group.addClass('focused');
  196.                 },
  197.                
  198.                 blur: function()
  199.                 {
  200.                     $group.removeClass('focused');
  201.                 }
  202.             });
  203.         });
  204.        
  205.         // Functions
  206.         $.extend(neonLogin, {
  207.             setPercentage: function(pct, callback)
  208.             {
  209.                 pct = parseInt(pct / 100 * 100, 10) + '%';
  210.                
  211.                 // Lockscreen
  212.                 if(is_lockscreen)
  213.                 {
  214.                     neonLogin.$lockscreen_progress_indicator.html(pct);
  215.                    
  216.                     var o = {
  217.                         pct: currentProgress
  218.                     };
  219.                    
  220.                     TweenMax.to(o, .7, {
  221.                         pct: parseInt(pct, 10),
  222.                         roundProps: ["pct"],
  223.                         ease: Sine.easeOut,
  224.                         onUpdate: function()
  225.                         {
  226.                             neonLogin.$lockscreen_progress_indicator.html(o.pct + '%');
  227.                             drawProgress(parseInt(o.pct, 10)/100);
  228.                         },
  229.                         onComplete: callback
  230.                     });
  231.                     return;
  232.                 }
  233.                
  234.                 // Normal Login
  235.                 neonLogin.$login_progressbar_indicator.html(pct);
  236.                 neonLogin.$login_progressbar.width(pct);
  237.                
  238.                 var o = {
  239.                     pct: parseInt(neonLogin.$login_progressbar.width() / neonLogin.$login_progressbar.parent().width() * 100, 10)
  240.                 };
  241.                
  242.                 TweenMax.to(o, .7, {
  243.                     pct: parseInt(pct, 10),
  244.                     roundProps: ["pct"],
  245.                     ease: Sine.easeOut,
  246.                     onUpdate: function()
  247.                     {
  248.                         neonLogin.$login_progressbar_indicator.html(o.pct + '%');
  249.                     },
  250.                     onComplete: callback
  251.                 });
  252.             }
  253.         });
  254.        
  255.        
  256.         // Lockscreen Create Canvas
  257.         if(is_lockscreen)
  258.         {
  259.             neonLogin.$lockscreen_progress_canvas = $('<canvas></canvas>');
  260.             neonLogin.$lockscreen_progress_indicator =  neonLogin.$container.find('.lockscreen-progress-indicator');
  261.            
  262.             neonLogin.$lockscreen_progress_canvas.appendTo(neonLogin.$ls_thumb);
  263.            
  264.             var thumb_size = neonLogin.$ls_thumb.width();
  265.            
  266.             neonLogin.$lockscreen_progress_canvas.attr({
  267.                 width: thumb_size,
  268.                 height: thumb_size
  269.             });
  270.            
  271.            
  272.             neonLogin.lockscreen_progress_canvas = neonLogin.$lockscreen_progress_canvas.get(0);
  273.            
  274.             // Create Progress Circle
  275.             var bg = neonLogin.lockscreen_progress_canvas,
  276.                 ctx = ctx = bg.getContext('2d'),
  277.                 imd = null,
  278.                 circ = Math.PI * 2,
  279.                 quart = Math.PI / 2,
  280.                 currentProgress = 0;
  281.            
  282.             ctx.beginPath();
  283.             ctx.strokeStyle = '#eb7067';
  284.             ctx.lineCap = 'square';
  285.             ctx.closePath();
  286.             ctx.fill();
  287.             ctx.lineWidth = 3.0;
  288.            
  289.             imd = ctx.getImageData(0, 0, thumb_size, thumb_size);
  290.            
  291.             var drawProgress = function(current) {
  292.                 ctx.putImageData(imd, 0, 0);
  293.                 ctx.beginPath();
  294.                 ctx.arc(thumb_size/2, thumb_size/2, 70, -(quart), ((circ) * current) - quart, false);
  295.                 ctx.stroke();
  296.                
  297.                 currentProgress = current * 100;
  298.             }
  299.            
  300.             drawProgress(0/100);
  301.            
  302.            
  303.             neonLogin.$lockscreen_progress_indicator.html('0%');
  304.            
  305.             ctx.restore();
  306.         }
  307.        
  308.     });
  309.    
  310. })(jQuery, window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement