Make WordPress Core

Ticket #26333: 26333.patch

File 26333.patch, 6.4 KB (added by azaozz, 11 years ago)
  • src/wp-admin/includes/misc.php

     
    613613        <?php
    614614}
    615615
    616 function set_color_scheme_json() {
     616function wp_color_scheme_settings() {
    617617        global $_wp_admin_css_colors;
    618618
    619619        $color_scheme = get_user_option( 'admin_color' );
    620620
    621         if ( isset( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
    622                 echo '<script type="text/javascript">var wp_color_scheme = ' . json_encode( array( 'icons' => $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) . ";</script>\n";
     621        if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) {
     622                echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) . ";</script>\n";
    623623        }
    624624}
    625 add_action( 'admin_head', 'set_color_scheme_json' );
     625add_action( 'admin_head', 'wp_color_scheme_settings' );
    626626
    627627function _ipad_meta() {
    628628        if ( wp_is_mobile() ) {
  • src/wp-includes/js/svg-painter.js

     
    11/* global wp_color_scheme:true */
    22var svgPainter = ( function( $, window, document, undefined ) {
    3 
    43        'use strict';
     4        var colorscheme, selector,
     5                elements = [];
    56
    67        $(document).ready( function() {
    7 
    88                // detection for browser SVG capability
    99                if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
    10                         document.body.className = document.body.className.replace( 'no-svg', 'svg' );
     10                        $( document.body ).removeClass( 'no-svg' ).addClass( 'svg' );
     11                        svgPainter.init();
    1112                }
    12 
    13                 svgPainter.init();
    14 
    1513        });
    1614
    1715        return {
     16                init: function() {
     17                        selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
    1818
    19                 elements : [],
    20 
    21                 init : function() {
    22 
    23                         this.selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
    24 
    2519                        this.setColors();
    2620                        this.findElements();
    2721                        this.paint();
    28 
    2922                },
    3023
    31                 setColors : function( colors ) {
     24                setColors: function( colors ) {
     25                        if ( typeof colors === 'undefined' && typeof window._wpColorScheme !== 'undefined' ) {
     26                                colors = window._wpColorScheme;
     27                        }
    3228
    33                         if ( typeof colors === 'undefined' && typeof wp_color_scheme !== 'undefined' ) {
    34                                 colors = wp_color_scheme;
     29                        if ( colors && colors.icons && colors.icons.base && colors.icons.current && colors.icons.focus ) {
     30                                colorscheme = colors.icons;
    3531                        }
    36 
    37                         this.colorscheme = colors;
    38 
    3932                },
    4033
    41                 findElements : function() {
     34                findElements: function() {
     35                        selector.each( function() {
     36                                var $this = $(this), bgImage = $this.css( 'background-image' );
    4237
    43                         this.selector.each(function() {
    44 
    45                                 var bgimg = $(this).css( 'background-image' );
    46 
    47                                 if ( bgimg.indexOf( 'data:image/svg+xml;base64' ) != -1 ) {
    48                                         svgPainter.elements.push( $(this) );
     38                                if ( bgImage && bgImage.indexOf( 'data:image/svg+xml;base64' ) != -1 ) {
     39                                        elements.push( $this );
    4940                                }
    50 
    5141                        });
    52 
    5342                },
    5443
    55                 paint : function() {
     44                paint: function() {
     45                        if ( ! colorscheme ) {
     46                                return;
     47                        }
    5648
    5749                        // loop through all elements
    58                         $.each( this.elements, function( index, $element ) {
    59 
     50                        $.each( elements, function( index, $element ) {
    6051                                var $menuitem = $element.parent().parent();
    6152
    6253                                if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
    63 
    6454                                        // paint icon in 'current' color
    65                                         svgPainter.paintElement( $element, svgPainter.colorscheme.icons.current );
    66 
     55                                        svgPainter.paintElement( $element, 'current' );
    6756                                } else {
    68 
    6957                                        // paint icon in base color
    70                                         svgPainter.paintElement( $element, svgPainter.colorscheme.icons.base );
     58                                        svgPainter.paintElement( $element, 'base' );
    7159
    7260                                        // set hover callbacks
    7361                                        $menuitem.hover(
    74                                                 function() { svgPainter.paintElement( $element, svgPainter.colorscheme.icons.focus ); },
    75                                                 function() { svgPainter.paintElement( $element, svgPainter.colorscheme.icons.base ); }
     62                                                function() { svgPainter.paintElement( $element, 'focus' ); },
     63                                                function() { svgPainter.paintElement( $element, 'base' ); }
    7664                                        );
    77 
    7865                                }
    79 
    8066                        });
    81 
    8267                },
    8368
    84                 paintElement : function( $element, color ) {
     69                paintElement: function( $element, colorType ) {
     70                        var xml, base64, color;
    8571
     72                        if ( ! colorType || ! colorscheme.hasOwnProperty( colorType ) ) {
     73                                return;
     74                        }
     75
     76                        color = colorscheme[ colorType ];
     77
    8678                        // only accept hex colors: #101 or #101010
    87                         if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) )
     79                        if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
    8880                                return;
     81                        }
    8982
    90                         var xml = $element.data( 'mp6-svg-' + color ),
    91                                 base64;
     83                        xml = $element.data( 'mp6-svg-' + color );
    9284
    9385                        if ( ! xml ) {
    94 
    9586                                base64 = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,(.+)\)/ );
    9687
    97                                 if ( ! base64 )
     88                                if ( ! base64 ) {
    9889                                        return;
     90                                }
    9991
    10092                                try {
    10193                                        xml = window.atob( base64[1] );
     
    119111                                }
    120112
    121113                                $element.data( 'mp6-svg-' + color, xml );
    122 
    123114                        }
    124115
    125116                        $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
    126 
    127117                }
    128118
    129119        };
  • src/wp-includes/script-loader.php

     
    392392        $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
    393393        $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 );
    394394
    395         $scripts->add( 'svg-painter', '/wp-includes/js/svg-painter.js' );
    396 
    397395        if ( is_admin() ) {
    398396                $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array('jquery', 'wp-ajax-response'), false, 1 );
    399397                did_action( 'init' ) && $scripts->localize( 'admin-tags', 'tagsl10n', array(
     
    516514                $scripts->add( 'custom-header', "/wp-admin/js/custom-header.js", array( 'jquery-masonry' ), false, 1 );
    517515                $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 );
    518516                $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 );
     517
     518                $scripts->add( 'svg-painter', '/wp-includes/js/svg-painter.js', array( 'jquery' ), false, 1 );
    519519        }
    520520}
    521521