~canonical-sysadmins/wordpress/4.7.4

« back to all changes in this revision

Viewing changes to wp-admin/js/user-profile.js

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* global ajaxurl, pwsL10n */
 
2
(function($){
 
3
 
 
4
        function check_pass_strength() {
 
5
                var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength;
 
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:
 
17
                                $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
 
18
                                break;
 
19
                        case 3:
 
20
                                $('#pass-strength-result').addClass('good').html( pwsL10n.good );
 
21
                                break;
 
22
                        case 4:
 
23
                                $('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
 
24
                                break;
 
25
                        case 5:
 
26
                                $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
 
27
                                break;
 
28
                        default:
 
29
                                $('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
 
30
                }
 
31
        }
 
32
 
 
33
        $(document).ready( function() {
 
34
                var $colorpicker, $stylesheet, user_id, current_user_id,
 
35
                        select = $( '#display_name' );
 
36
 
 
37
                $('#pass1').val('').keyup( check_pass_strength );
 
38
                $('#pass2').val('').keyup( check_pass_strength );
 
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 ) {
 
55
                                        inputs.display_firstlast = inputs.display_firstname + ' ' + inputs.display_lastname;
 
56
                                        inputs.display_lastfirst = inputs.display_lastname + ' ' + inputs.display_firstname;
 
57
                                }
 
58
 
 
59
                                $.each( $('option', select), function( i, el ){
 
60
                                        dub.push( el.value );
 
61
                                });
 
62
 
 
63
                                $.each(inputs, function( id, value ) {
 
64
                                        if ( ! value ) {
 
65
                                                return;
 
66
                                        }
 
67
 
 
68
                                        var val = value.replace(/<\/?[a-z][^>]*>/gi, '');
 
69
 
 
70
                                        if ( inputs[id].length && $.inArray( val, dub ) === -1 ) {
 
71
                                                dub.push(val);
 
72
                                                $('<option />', {
 
73
                                                        'text': val
 
74
                                                }).appendTo( select );
 
75
                                        }
 
76
                                });
 
77
                        });
 
78
                }
 
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
                                });
 
123
                        }
 
124
                });
 
125
        });
 
126
 
 
127
})(jQuery);