PluginProbe
Authorizer / 2.8.0
Authorizer v2.8.0
3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 2.9.6 All 126 releases
authorizer / js / authorizer-login.js

authorizer-login.js in Authorizer 2.8.0, at js/authorizer-login.js

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Small style tweaks for login form, and show a counter if user triggered login
3 * protections (too many failed attempts).
4 */
5
6 /* global document */
7 /* eslint-env browser */
8 ( function( $ ) {
9
10 $( document ).ready( function() {
11 // Move any external service buttons into top of login form.
12 var loginform = document.getElementById( 'loginform' );
13 var externals = document.getElementById( 'auth-external-service-login' );
14 if ( null !== loginform && null !== externals ) {
15 loginform.insertBefore( externals, loginform.firstChild );
16 }
17
18 // Decrement seconds counter if it exists
19 var secondsElement = document.getElementById( 'seconds_remaining' );
20 if ( null !== secondsElement ) {
21 var secondsInterval = setInterval( function() {
22 var seconds = secondsElement.getAttribute( 'data-seconds' );
23 if ( 1 > seconds ) {
24 clearInterval( secondsInterval );
25 return;
26 }
27 seconds = parseInt( seconds, 10 ) - 1;
28 secondsElement.innerHTML = secondsAsSentence( seconds );
29 secondsElement.setAttribute( 'data-seconds', seconds );
30 }, 1000 );
31 }
32 });
33
34 function secondsAsSentence( seconds ) {
35 var units = {
36 week: 3600 * 24 * 7,
37 day: 3600 * 24,
38 hour: 3600,
39 minute: 60,
40 second: 1,
41 };
42
43 // specifically handle zero
44 if ( 0 === seconds ) {
45 return '0 seconds';
46 }
47
48 // Construct sentence, e.g., '1 week, 2 hours, 5 minutes, 10 seconds, '
49 var phrase = '';
50 for ( var name in units ) {
51 if ( units.hasOwnProperty( name ) ) {
52 var divisor = units[name];
53 var quot = Math.floor( seconds / divisor );
54 if ( quot ) {
55 phrase += quot + ' ' + name;
56 if ( 1 < Math.abs( quot ) ) {
57 phrase += 's';
58 }
59 phrase += ', ';
60 seconds -= quot * divisor;
61 }
62 }
63 }
64
65 return phrase.substring( 0, phrase.length - 2 ); // trim off last ', '
66 }
67
68 } )( jQuery );
69