Make WordPress Core

Ticket #26333: 26333.4.diff

File 26333.4.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 wp !== 'undefined' && wp.svgPainter ) {
    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                                                wp.svgPainter.setColors( colors );
     109                                                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';
    7         var selector, base64,
     10        var selector, base64, painter,
    811                colorscheme = {},
    912                elements = [];
    1013
     
    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;
     
    105118
    106119        return {
    107120                init: function() {
     121                        painter = this;
    108122                        selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
    109123
    110124                        this.setColors();
     
    139153
    140154                                if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
    141155                                        // paint icon in 'current' color
    142                                         svgPainter.paintElement( $element, 'current' );
     156                                        painter.paintElement( $element, 'current' );
    143157                                } else {
    144158                                        // paint icon in base color
    145                                         svgPainter.paintElement( $element, 'base' );
     159                                        painter.paintElement( $element, 'base' );
    146160
    147161                                        // set hover callbacks
    148162                                        $menuitem.hover(
    149                                                 function() { svgPainter.paintElement( $element, 'focus' ); },
    150                                                 function() { svgPainter.paintElement( $element, 'base' ); }
     163                                                function() {
     164                                                        painter.paintElement( $element, 'focus' );
     165                                                },
     166                                                function() {
     167                                                        // Match the delay from hoverIntent
     168                                                        window.setTimeout( function() {
     169                                                                painter.paintElement( $element, 'base' );
     170                                                        }, 100 );
     171                                                }
    151172                                        );
    152173                                }
    153174                        });
     
    169190
    170191                        xml = $element.data( 'wp-ui-svg-' + color );
    171192
     193                        if ( xml === 'none' ) {
     194                                return;
     195                        }
     196
    172197                        if ( ! xml ) {
    173                                 encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,(.+?)['"]? ?\)/ );
     198                                encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/ );
    174199
    175200                                if ( ! encoded || ! encoded[1] ) {
     201                                        $element.data( 'wp-ui-svg-' + color, 'none' );
    176202                                        return;
    177203                                }
    178204
    179                                 if ( 'atob' in window ) {
    180                                         xml = window.atob( encoded[1] );
    181                                 } else {
    182                                         xml = base64.atob( encoded[1] );
    183                                 }
     205                                try {
     206                                        if ( 'atob' in window ) {
     207                                                xml = window.atob( encoded[1] );
     208                                        } else {
     209                                                xml = base64.atob( encoded[1] );
     210                                        }
     211                                } catch ( error ) {}
    184212
    185                                 // replace `fill` attributes
    186                                 xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
     213                                if ( xml ) {
     214                                        // replace `fill` attributes
     215                                        xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
    187216
    188                                 // replace `style` attributes
    189                                 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
     217                                        // replace `style` attributes
     218                                        xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
    190219
    191                                 // replace `fill` properties in `<style>` tags
    192                                 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
     220                                        // replace `fill` properties in `<style>` tags
     221                                        xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
    193222
    194                                 if ( 'btoa' in window ) {
    195                                         xml = window.btoa( xml );
     223                                        if ( 'btoa' in window ) {
     224                                                xml = window.btoa( xml );
     225                                        } else {
     226                                                xml = base64.btoa( xml );
     227                                        }
     228
     229                                        $element.data( 'wp-ui-svg-' + color, xml );
    196230                                } else {
    197                                         xml = base64.btoa( xml );
     231                                        $element.data( 'wp-ui-svg-' + color, 'none' );
     232                                        return;
    198233                                }
    199 
    200                                 $element.data( 'wp-ui-svg-' + color, xml );
    201234                        }
    202235
    203                         $element.css( 'background-image', 'url("data:image/svg+xml;base64,' + xml + '")' );
     236                        $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
    204237                }
    205238        };
    206239