Вход Регистрация
Файл: wordpress/wp-admin/js/svg-painter.js
Строк: 209
<?php
/**
 * Attempt to re-color SVG icons used in the admin menu or the toolbar
 *
 */

window.wp window.wp || {};

wp.svgPainter = ( function( $, windowdocumentundefined ) {
    
'use strict';
    var 
selectorbase64painter,
        
colorscheme = {},
        
elements = [];

    $(
document).ready( function() {
        
// detection for browser SVG capability
        
if ( document.implementation.hasFeature'http://www.w3.org/TR/SVG11/feature#Image''1.1' ) ) {
            $( 
document.body ).removeClass'no-svg' ).addClass'svg' );
            
wp.svgPainter.init();
        }
    });

    
/**
     * Needed only for IE9
     *
     * Based on jquery.base64.js 0.0.3 - https://github.com/yckart/jquery.base64.js
     *
     * Based on: https://gist.github.com/Yaffle/1284012
     *
     * Copyright (c) 2012 Yannick Albert (http://yckart.com)
     * Licensed under the MIT license
     * http://www.opensource.org/licenses/mit-license.php
     */
    
base64 = ( function() {
        var 
c,
            
b64 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
            
a256 '',
            
r64 = [256],
            
r256 = [256],
            
0;

        function 
init() {
            while( 
256 ) {
                
String.fromCharCode(i);
                
a256 += c;
                
r256[i] = i;
                
r64[i] = b64.indexOf(c);
                ++
i;
            }
        }

        function 
codesdiscardalphabetaw1w2 ) {
            var 
tmplength,
                
buffer 0,
                
0,
                
result '',
                
bitsInBuffer 0;

            
String(s);
            
length s.length;

            while( 
length ) {
                
s.charCodeAt(i);
                
256 alpha[c] : -1;

                
buffer = ( buffer << w1 ) + c;
                
bitsInBuffer += w1;

                while( 
bitsInBuffer >= w2 ) {
                    
bitsInBuffer -= w2;
                    
tmp buffer >> bitsInBuffer;
                    
result += beta.charAt(tmp);
                    
buffer ^= tmp << bitsInBuffer;
                }
                ++
i;
            }

            if ( ! 
discard && bitsInBuffer ) {
                
result += beta.charAtbuffer << ( w2 bitsInBuffer ) );
            }

            return 
result;
        }

        function 
btoaplain ) {
            if ( ! 
) {
                
init();
            }

            
plain codeplainfalser256b648);
            return 
plain '===='.slice( ( plain.length ) || );
        }

        function 
atobcoded ) {
            var 
i;

            if ( ! 
) {
                
init();
            }

            
coded coded.replace( /[^A-Za-z0-9+/=]/g'' );
            
coded String(coded).split('=');
            
coded.length;

            do {
                --
i;
                
coded[i] = codecoded[i], truer64a2566);
            } while ( 
);

            
coded coded.join('');
            return 
coded;
        }

        return {
            
atobatob,
            
btoabtoa
        
};
    })();

    return {
        
init: function() {
            
painter this;
            
selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );

            
this.setColors();
            
this.findElements();
            
this.paint();
        },

        
setColors: function( colors ) {
            if ( 
typeof colors === 'undefined' && typeof window._wpColorScheme !== 'undefined' ) {
                
colors window._wpColorScheme;
            }

            if ( 
colors && colors.icons && colors.icons.base && colors.icons.current && colors.icons.focus ) {
                
colorscheme colors.icons;
            }
        },

        
findElements: function() {
            
selector.each( function() {
                var 
$this = $(this), bgImage $this.css'background-image' );

                if ( 
bgImage && bgImage.indexOf'data:image/svg+xml;base64' ) != -) {
                    
elements.push$this );
                }
            });
        },

        
paint: function() {
            
// loop through all elements
            
$.eachelements, function( index$element ) {
                var 
$menuitem $element.parent().parent();

                if ( 
$menuitem.hasClass'current' ) || $menuitem.hasClass'wp-has-current-submenu' ) ) {
                    
// paint icon in 'current' color
                    
painter.paintElement$element'current' );
                } else {
                    
// paint icon in base color
                    
painter.paintElement$element'base' );

                    
// set hover callbacks
                    
$menuitem.hover(
                        function() {
                            
painter.paintElement$element'focus' );
                        },
                        function() {
                            
// Match the delay from hoverIntent
                            
window.setTimeout( function() {
                                
painter.paintElement$element'base' );
                            }, 
100 );
                        }
                    );
                }
            });
        },

        
paintElement: function( $elementcolorType ) {
            var 
xmlencodedcolor;

            if ( ! 
colorType || ! colorscheme.hasOwnPropertycolorType ) ) {
                return;
            }

            
color colorschemecolorType ];

            
// only accept hex colors: #101 or #101010
            
if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
                
return;
            }

            
xml $element.data'wp-ui-svg-' color );

            if ( 
xml === 'none' ) {
                return;
            }

            if ( ! 
xml ) {
                
encoded $element.css'background-image' ).match( /.+data:image/svg+xml;base64,([A-Za-z0-9+/=]+)/ );

                if ( ! 
encoded || ! encoded[1] ) {
                    
$element.data'wp-ui-svg-' color'none' );
                    return;
                }

                try {
                    if ( 
'atob' in window ) {
                        
xml window.atobencoded[1] );
                    } else {
                        
xml base64.atobencoded[1] );
                    }
                } catch ( 
error ) {}

                if ( 
xml ) {
                    
// replace `fill` attributes
                    
xml xml.replace( /fill="(.+?)"/g'fill="' color '"');

                    
// replace `style` attributes
                    
xml xml.replace( /style="(.+?)"/g'style="fill:' color '"');

                    
// replace `fill` properties in `<style>` tags
                    
xml xml.replace( /fill:.*?;/g'fill: ' color ';');

                    if ( 
'btoa' in window ) {
                        
xml window.btoaxml );
                    } else {
                        
xml base64.btoaxml );
                    }

                    
$element.data'wp-ui-svg-' colorxml );
                } else {
                    
$element.data'wp-ui-svg-' color'none' );
                    return;
                }
            }

            
$element.attr'style''background-image: url("data:image/svg+xml;base64,' xml '") !important;' );
        }
    };

})( 
jQuerywindowdocument );
?>
Онлайн: 0
Реклама