Make WordPress Core

Ticket #26333: 26333.3.diff

File 26333.3.diff, 5.6 KB (added by azaozz, 11 years ago)
  • src/wp-admin/js/user-profile.js

     
    1 /* global ajaxurl, pwsL10n, svgPainter */
     1/* global ajaxurl, pwsL10n */
    22(function($){
    33
    44        function check_pass_strength() {
     
    9999                                $stylesheet.attr( 'href', $this.children( '.css_url' ).val() );
    100100
    101101                                // repaint icons
    102                                 if ( typeof window.svgPainter !== 'undefined' ) {
     102                                if ( typeof window.wp.svgPainter !== 'undefined' ) {
    103103                                        try {
    104104                                                colors = $.parseJSON( $this.children( '.icon_colors' ).val() );
    105105                                        } catch ( error ) {}
    106106
    107107                                        if ( colors ) {
    108                                                 svgPainter.setColors( colors );
    109                                                 svgPainter.paint();
     108                                                window.wp.svgPainter.setColors( colors );
     109                                                window.wp.svgPainter.paint();
    110110                                        }
    111111                                }
    112112
  • src/wp-includes/js/svg-painter.js

     
    22 * Attempt to re-color SVG icons used in the admin menu or the toolbar
    33 *
    44 */
    5 var svgPainter = ( function( $, window, document, undefined ) {
     5
     6window.wp = window.wp || {};
     7
     8wp.svgPainter = ( function( $, window, document, undefined ) {
    69        'use strict';
    710        var selector, base64,
    811                colorscheme = {},
     
    1215                // detection for browser SVG capability
    1316                if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
    1417                        $( document.body ).removeClass( 'no-svg' ).addClass( 'svg' );
    15                         svgPainter.init();
     18                        wp.svgPainter.init();
    1619                }
    1720        });
    1821
     
    3538                        r256 = [256],
    3639                        i = 0;
    3740
    38                 while( i < 256 ) {
    39                         c = String.fromCharCode(i);
    40                         a256 += c;
    41                         r256[i] = i;
    42                         r64[i] = b64.indexOf(c);
    43                         ++i;
     41                function init() {
     42                        while( i < 256 ) {
     43                                c = String.fromCharCode(i);
     44                                a256 += c;
     45                                r256[i] = i;
     46                                r64[i] = b64.indexOf(c);
     47                                ++i;
     48                        }
    4449                }
    4550
    4651                function code( s, discard, alpha, beta, w1, w2 ) {
     
    7782                }
    7883
    7984                function btoa( plain ) {
     85                        if ( ! c ) {
     86                                init();
     87                        }
     88
    8089                        plain = code( plain, false, r256, b64, 8, 6 );
    8190                        return plain + '===='.slice( ( plain.length % 4 ) || 4 );
    8291                }
     
    8493                function atob( coded ) {
    8594                        var i;
    8695
     96                        if ( ! c ) {
     97                                init();
     98                        }
     99
    87100                        coded = coded.replace( /[^A-Za-z0-9\+\/\=]/g, '' );
    88101                        coded = String(coded).split('=');
    89102                        i = coded.length;
     
    133146                },
    134147
    135148                paint: function() {
     149                        var self = this;
     150
    136151                        // loop through all elements
    137152                        $.each( elements, function( index, $element ) {
    138153                                var $menuitem = $element.parent().parent();
     
    139154
    140155                                if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
    141156                                        // paint icon in 'current' color
    142                                         svgPainter.paintElement( $element, 'current' );
     157                                        self.paintElement( $element, 'current' );
    143158                                } else {
    144159                                        // paint icon in base color
    145                                         svgPainter.paintElement( $element, 'base' );
     160                                        self.paintElement( $element, 'base' );
    146161
    147162                                        // set hover callbacks
    148163                                        $menuitem.hover(
    149                                                 function() { svgPainter.paintElement( $element, 'focus' ); },
    150                                                 function() { svgPainter.paintElement( $element, 'base' ); }
     164                                                function() {
     165                                                        self.paintElement( $element, 'focus' );
     166                                                },
     167                                                function() {
     168                                                        // Match the delay from hoverIntent
     169                                                        window.setTimeout( function() {
     170                                                                self.paintElement( $element, 'base' );
     171                                                        }, 100 );
     172                                                }
    151173                                        );
    152174                                }
    153175                        });
     
    169191
    170192                        xml = $element.data( 'wp-ui-svg-' + color );
    171193
     194                        if ( xml === 'none' ) {
     195                                return;
     196                        }
     197
    172198                        if ( ! xml ) {
    173                                 encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,(.+?)['"]? ?\)/ );
     199                                encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/ );
    174200
    175201                                if ( ! encoded || ! encoded[1] ) {
     202                                        $element.data( 'wp-ui-svg-' + color, 'none' );
    176203                                        return;
    177204                                }
    178205
    179                                 if ( 'atob' in window ) {
    180                                         xml = window.atob( encoded[1] );
    181                                 } else {
    182                                         xml = base64.atob( encoded[1] );
    183                                 }
     206                                try {
     207                                        if ( 'atob' in window ) {
     208                                                xml = window.atob( encoded[1] );
     209                                        } else {
     210                                                xml = base64.atob( encoded[1] );
     211                                        }
     212                                } catch ( error ) {}
    184213
    185                                 // replace `fill` attributes
    186                                 xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
     214                                if ( xml ) {
     215                                        // replace `fill` attributes
     216                                        xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
    187217
    188                                 // replace `style` attributes
    189                                 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
     218                                        // replace `style` attributes
     219                                        xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
    190220
    191                                 // replace `fill` properties in `<style>` tags
    192                                 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
     221                                        // replace `fill` properties in `<style>` tags
     222                                        xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
    193223
    194                                 if ( 'btoa' in window ) {
    195                                         xml = window.btoa( xml );
     224                                        if ( 'btoa' in window ) {
     225                                                xml = window.btoa( xml );
     226                                        } else {
     227                                                xml = base64.btoa( xml );
     228                                        }
     229
     230                                        $element.data( 'wp-ui-svg-' + color, xml );
    196231                                } else {
    197                                         xml = base64.btoa( xml );
     232                                        $element.data( 'wp-ui-svg-' + color, 'none' );
     233                                        return;
    198234                                }
    199 
    200                                 $element.data( 'wp-ui-svg-' + color, xml );
    201235                        }
    202236
    203                         $element.css( 'background-image', 'url("data:image/svg+xml;base64,' + xml + '")' );
     237                        $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
    204238                }
    205239        };
    206240