Ticket #26333: 26333.3.diff
File 26333.3.diff, 5.6 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/user-profile.js
1 /* global ajaxurl, pwsL10n , svgPainter*/1 /* global ajaxurl, pwsL10n */ 2 2 (function($){ 3 3 4 4 function check_pass_strength() { … … 99 99 $stylesheet.attr( 'href', $this.children( '.css_url' ).val() ); 100 100 101 101 // repaint icons 102 if ( typeof window. svgPainter !== 'undefined' ) {102 if ( typeof window.wp.svgPainter !== 'undefined' ) { 103 103 try { 104 104 colors = $.parseJSON( $this.children( '.icon_colors' ).val() ); 105 105 } catch ( error ) {} 106 106 107 107 if ( colors ) { 108 svgPainter.setColors( colors );109 svgPainter.paint();108 window.wp.svgPainter.setColors( colors ); 109 window.wp.svgPainter.paint(); 110 110 } 111 111 } 112 112 -
src/wp-includes/js/svg-painter.js
2 2 * Attempt to re-color SVG icons used in the admin menu or the toolbar 3 3 * 4 4 */ 5 var svgPainter = ( function( $, window, document, undefined ) { 5 6 window.wp = window.wp || {}; 7 8 wp.svgPainter = ( function( $, window, document, undefined ) { 6 9 'use strict'; 7 10 var selector, base64, 8 11 colorscheme = {}, … … 12 15 // detection for browser SVG capability 13 16 if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) { 14 17 $( document.body ).removeClass( 'no-svg' ).addClass( 'svg' ); 15 svgPainter.init();18 wp.svgPainter.init(); 16 19 } 17 20 }); 18 21 … … 35 38 r256 = [256], 36 39 i = 0; 37 40 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 } 44 49 } 45 50 46 51 function code( s, discard, alpha, beta, w1, w2 ) { … … 77 82 } 78 83 79 84 function btoa( plain ) { 85 if ( ! c ) { 86 init(); 87 } 88 80 89 plain = code( plain, false, r256, b64, 8, 6 ); 81 90 return plain + '===='.slice( ( plain.length % 4 ) || 4 ); 82 91 } … … 84 93 function atob( coded ) { 85 94 var i; 86 95 96 if ( ! c ) { 97 init(); 98 } 99 87 100 coded = coded.replace( /[^A-Za-z0-9\+\/\=]/g, '' ); 88 101 coded = String(coded).split('='); 89 102 i = coded.length; … … 133 146 }, 134 147 135 148 paint: function() { 149 var self = this; 150 136 151 // loop through all elements 137 152 $.each( elements, function( index, $element ) { 138 153 var $menuitem = $element.parent().parent(); … … 139 154 140 155 if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) { 141 156 // paint icon in 'current' color 142 s vgPainter.paintElement( $element, 'current' );157 self.paintElement( $element, 'current' ); 143 158 } else { 144 159 // paint icon in base color 145 s vgPainter.paintElement( $element, 'base' );160 self.paintElement( $element, 'base' ); 146 161 147 162 // set hover callbacks 148 163 $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 } 151 173 ); 152 174 } 153 175 }); … … 169 191 170 192 xml = $element.data( 'wp-ui-svg-' + color ); 171 193 194 if ( xml === 'none' ) { 195 return; 196 } 197 172 198 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\+\/\=]+)/ ); 174 200 175 201 if ( ! encoded || ! encoded[1] ) { 202 $element.data( 'wp-ui-svg-' + color, 'none' ); 176 203 return; 177 204 } 178 205 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 ) {} 184 213 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 + '"'); 187 217 188 // replace `style` attributes189 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');218 // replace `style` attributes 219 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"'); 190 220 191 // replace `fill` properties in `<style>` tags192 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');221 // replace `fill` properties in `<style>` tags 222 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';'); 193 223 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 ); 196 231 } else { 197 xml = base64.btoa( xml ); 232 $element.data( 'wp-ui-svg-' + color, 'none' ); 233 return; 198 234 } 199 200 $element.data( 'wp-ui-svg-' + color, xml );201 235 } 202 236 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;' ); 204 238 } 205 239 }; 206 240