5
|
1 |
/* global ajaxurl, pwsL10n */ |
0
|
2 |
(function($){ |
|
3 |
|
|
4 |
function check_pass_strength() { |
5
|
5 |
var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength; |
0
|
6 |
|
|
7 |
$('#pass-strength-result').removeClass('short bad good strong'); |
|
8 |
if ( ! pass1 ) { |
|
9 |
$('#pass-strength-result').html( pwsL10n.empty ); |
|
10 |
return; |
|
11 |
} |
|
12 |
|
|
13 |
strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 ); |
|
14 |
|
|
15 |
switch ( strength ) { |
|
16 |
case 2: |
5
|
17 |
$('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); |
0
|
18 |
break; |
|
19 |
case 3: |
5
|
20 |
$('#pass-strength-result').addClass('good').html( pwsL10n.good ); |
0
|
21 |
break; |
|
22 |
case 4: |
5
|
23 |
$('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); |
0
|
24 |
break; |
|
25 |
case 5: |
5
|
26 |
$('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); |
0
|
27 |
break; |
|
28 |
default: |
|
29 |
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
$(document).ready( function() { |
5
|
34 |
var $colorpicker, $stylesheet, user_id, current_user_id, |
|
35 |
select = $( '#display_name' ); |
0
|
36 |
|
5
|
37 |
$('#pass1').val('').on( 'input propertychange', check_pass_strength ); |
|
38 |
$('#pass2').val('').on( 'input propertychange', check_pass_strength ); |
0
|
39 |
$('#pass-strength-result').show(); |
|
40 |
$('.color-palette').click( function() { |
|
41 |
$(this).siblings('input[name="admin_color"]').prop('checked', true); |
|
42 |
}); |
|
43 |
|
|
44 |
if ( select.length ) { |
|
45 |
$('#first_name, #last_name, #nickname').bind( 'blur.user_profile', function() { |
|
46 |
var dub = [], |
|
47 |
inputs = { |
|
48 |
display_nickname : $('#nickname').val() || '', |
|
49 |
display_username : $('#user_login').val() || '', |
|
50 |
display_firstname : $('#first_name').val() || '', |
|
51 |
display_lastname : $('#last_name').val() || '' |
|
52 |
}; |
|
53 |
|
|
54 |
if ( inputs.display_firstname && inputs.display_lastname ) { |
5
|
55 |
inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname; |
|
56 |
inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname; |
0
|
57 |
} |
|
58 |
|
|
59 |
$.each( $('option', select), function( i, el ){ |
|
60 |
dub.push( el.value ); |
|
61 |
}); |
|
62 |
|
|
63 |
$.each(inputs, function( id, value ) { |
5
|
64 |
if ( ! value ) { |
0
|
65 |
return; |
5
|
66 |
} |
0
|
67 |
|
|
68 |
var val = value.replace(/<\/?[a-z][^>]*>/gi, ''); |
|
69 |
|
5
|
70 |
if ( inputs[id].length && $.inArray( val, dub ) === -1 ) { |
0
|
71 |
dub.push(val); |
|
72 |
$('<option />', { |
|
73 |
'text': val |
|
74 |
}).appendTo( select ); |
|
75 |
} |
|
76 |
}); |
|
77 |
}); |
|
78 |
} |
5
|
79 |
|
|
80 |
$colorpicker = $( '#color-picker' ); |
|
81 |
$stylesheet = $( '#colors-css' ); |
|
82 |
user_id = $( 'input#user_id' ).val(); |
|
83 |
current_user_id = $( 'input[name="checkuser_id"]' ).val(); |
|
84 |
|
|
85 |
$colorpicker.on( 'click.colorpicker', '.color-option', function() { |
|
86 |
var colors, |
|
87 |
$this = $(this); |
|
88 |
|
|
89 |
if ( $this.hasClass( 'selected' ) ) { |
|
90 |
return; |
|
91 |
} |
|
92 |
|
|
93 |
$this.siblings( '.selected' ).removeClass( 'selected' ); |
|
94 |
$this.addClass( 'selected' ).find( 'input[type="radio"]' ).prop( 'checked', true ); |
|
95 |
|
|
96 |
// Set color scheme |
|
97 |
if ( user_id === current_user_id ) { |
|
98 |
// Load the colors stylesheet. |
|
99 |
// The default color scheme won't have one, so we'll need to create an element. |
|
100 |
if ( 0 === $stylesheet.length ) { |
|
101 |
$stylesheet = $( '<link rel="stylesheet" />' ).appendTo( 'head' ); |
|
102 |
} |
|
103 |
$stylesheet.attr( 'href', $this.children( '.css_url' ).val() ); |
|
104 |
|
|
105 |
// repaint icons |
|
106 |
if ( typeof wp !== 'undefined' && wp.svgPainter ) { |
|
107 |
try { |
|
108 |
colors = $.parseJSON( $this.children( '.icon_colors' ).val() ); |
|
109 |
} catch ( error ) {} |
|
110 |
|
|
111 |
if ( colors ) { |
|
112 |
wp.svgPainter.setColors( colors ); |
|
113 |
wp.svgPainter.paint(); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
// update user option |
|
118 |
$.post( ajaxurl, { |
|
119 |
action: 'save-user-color-scheme', |
|
120 |
color_scheme: $this.children( 'input[name="admin_color"]' ).val(), |
|
121 |
nonce: $('#color-nonce').val() |
|
122 |
}).done( function( response ) { |
|
123 |
if ( response.success ) { |
|
124 |
$( 'body' ).removeClass( response.data.previousScheme ).addClass( response.data.currentScheme ); |
|
125 |
} |
|
126 |
}); |
|
127 |
} |
|
128 |
}); |
|
129 |
}); |
|
130 |
|
|
131 |
$( '#destroy-sessions' ).on( 'click', function( e ) { |
|
132 |
var $this = $(this); |
|
133 |
|
|
134 |
wp.ajax.post( 'destroy-sessions', { |
|
135 |
nonce: $( '#_wpnonce' ).val(), |
|
136 |
user_id: $( '#user_id' ).val() |
|
137 |
}).done( function( response ) { |
|
138 |
$this.prop( 'disabled', true ); |
|
139 |
$this.siblings( '.notice' ).remove(); |
|
140 |
$this.before( '<div class="notice notice-success inline"><p>' + response.message + '</p></div>' ); |
|
141 |
}).fail( function( response ) { |
|
142 |
$this.siblings( '.notice' ).remove(); |
|
143 |
$this.before( '<div class="notice notice-error inline"><p>' + response.message + '</p></div>' ); |
|
144 |
}); |
|
145 |
|
|
146 |
e.preventDefault(); |
0
|
147 |
}); |
|
148 |
|
|
149 |
})(jQuery); |