Changeset 26693
- Timestamp:
- 12/05/2013 10:00:17 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/svg-painter.js
r26690 r26693 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 var selector, base64, 10 var selector, base64, painter, 8 11 colorscheme = {}, 9 12 elements = []; … … 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 }); … … 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 … … 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 ); … … 84 93 function atob( coded ) { 85 94 var i; 95 96 if ( ! c ) { 97 init(); 98 } 86 99 87 100 coded = coded.replace( /[^A-Za-z0-9\+\/\=]/g, '' ); … … 106 119 return { 107 120 init: function() { 121 painter = this; 108 122 selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' ); 109 123 … … 140 154 if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) { 141 155 // paint icon in 'current' color 142 svgPainter.paintElement( $element, 'current' );156 painter.paintElement( $element, 'current' ); 143 157 } else { 144 158 // paint icon in base color 145 svgPainter.paintElement( $element, 'base' );159 painter.paintElement( $element, 'base' ); 146 160 147 161 // set hover callbacks 148 162 $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 } 151 172 ); 152 173 } … … 170 191 xml = $element.data( 'wp-ui-svg-' + color ); 171 192 193 if ( xml === 'none' ) { 194 return; 195 } 196 172 197 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\+\/\=]+)/ ); 174 199 175 200 if ( ! encoded || ! encoded[1] ) { 201 $element.data( 'wp-ui-svg-' + color, 'none' ); 176 202 return; 177 203 } 178 204 179 if ( 'atob' in window ) { 180 xml = window.atob( encoded[1] ); 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 ) {} 212 213 if ( xml ) { 214 // replace `fill` attributes 215 xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"'); 216 217 // replace `style` attributes 218 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"'); 219 220 // replace `fill` properties in `<style>` tags 221 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';'); 222 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 ); 181 230 } else { 182 xml = base64.atob( encoded[1] ); 183 } 184 185 // replace `fill` attributes 186 xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"'); 187 188 // replace `style` attributes 189 xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"'); 190 191 // replace `fill` properties in `<style>` tags 192 xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';'); 193 194 if ( 'btoa' in window ) { 195 xml = window.btoa( xml ); 196 } else { 197 xml = base64.btoa( xml ); 198 } 199 200 $element.data( 'wp-ui-svg-' + color, xml ); 201 } 202 203 $element.css( 'background-image', 'url("data:image/svg+xml;base64,' + xml + '")' ); 231 $element.data( 'wp-ui-svg-' + color, 'none' ); 232 return; 233 } 234 } 235 236 $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' ); 204 237 } 205 238 }; -
trunk/src/wp-admin/js/user-profile.js
r26601 r26693 1 /* global ajaxurl, pwsL10n , svgPainter*/1 /* global ajaxurl, pwsL10n */ 2 2 (function($){ 3 3 … … 100 100 101 101 // repaint icons 102 if ( typeof w indow.svgPainter !== 'undefined') {102 if ( typeof wp !== 'undefined' && wp.svgPainter ) { 103 103 try { 104 104 colors = $.parseJSON( $this.children( '.icon_colors' ).val() ); … … 106 106 107 107 if ( colors ) { 108 svgPainter.setColors( colors );109 svgPainter.paint();108 wp.svgPainter.setColors( colors ); 109 wp.svgPainter.paint(); 110 110 } 111 111 } -
trunk/src/wp-includes/script-loader.php
r26605 r26693 516 516 $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 ); 517 517 518 $scripts->add( 'svg-painter', '/wp- includes/js/svg-painter.js', array( 'jquery' ), false, 1 );518 $scripts->add( 'svg-painter', '/wp-admin/js/svg-painter.js', array( 'jquery' ), false, 1 ); 519 519 } 520 520 }
Note: See TracChangeset
for help on using the changeset viewer.