wp/wp-admin/js/svg-painter.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    11 	var selector, base64, painter,
    11 	var selector, base64, painter,
    12 		colorscheme = {},
    12 		colorscheme = {},
    13 		elements = [];
    13 		elements = [];
    14 
    14 
    15 	$(document).ready( function() {
    15 	$(document).ready( function() {
    16 		// detection for browser SVG capability
    16 		// Detection for browser SVG capability.
    17 		if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
    17 		if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
    18 			$( document.body ).removeClass( 'no-svg' ).addClass( 'svg' );
    18 			$( document.body ).removeClass( 'no-svg' ).addClass( 'svg' );
    19 			wp.svgPainter.init();
    19 			wp.svgPainter.init();
    20 		}
    20 		}
    21 	});
    21 	});
   146 				}
   146 				}
   147 			});
   147 			});
   148 		},
   148 		},
   149 
   149 
   150 		paint: function() {
   150 		paint: function() {
   151 			// loop through all elements
   151 			// Loop through all elements.
   152 			$.each( elements, function( index, $element ) {
   152 			$.each( elements, function( index, $element ) {
   153 				var $menuitem = $element.parent().parent();
   153 				var $menuitem = $element.parent().parent();
   154 
   154 
   155 				if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
   155 				if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
   156 					// paint icon in 'current' color
   156 					// Paint icon in 'current' color.
   157 					painter.paintElement( $element, 'current' );
   157 					painter.paintElement( $element, 'current' );
   158 				} else {
   158 				} else {
   159 					// paint icon in base color
   159 					// Paint icon in base color.
   160 					painter.paintElement( $element, 'base' );
   160 					painter.paintElement( $element, 'base' );
   161 
   161 
   162 					// set hover callbacks
   162 					// Set hover callbacks.
   163 					$menuitem.hover(
   163 					$menuitem.hover(
   164 						function() {
   164 						function() {
   165 							painter.paintElement( $element, 'focus' );
   165 							painter.paintElement( $element, 'focus' );
   166 						},
   166 						},
   167 						function() {
   167 						function() {
   168 							// Match the delay from hoverIntent
   168 							// Match the delay from hoverIntent.
   169 							window.setTimeout( function() {
   169 							window.setTimeout( function() {
   170 								painter.paintElement( $element, 'base' );
   170 								painter.paintElement( $element, 'base' );
   171 							}, 100 );
   171 							}, 100 );
   172 						}
   172 						}
   173 					);
   173 					);
   182 				return;
   182 				return;
   183 			}
   183 			}
   184 
   184 
   185 			color = colorscheme[ colorType ];
   185 			color = colorscheme[ colorType ];
   186 
   186 
   187 			// only accept hex colors: #101 or #101010
   187 			// Only accept hex colors: #101 or #101010.
   188 			if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
   188 			if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
   189 				return;
   189 				return;
   190 			}
   190 			}
   191 
   191 
   192 			xml = $element.data( 'wp-ui-svg-' + color );
   192 			xml = $element.data( 'wp-ui-svg-' + color );
   210 						xml = base64.atob( encoded[1] );
   210 						xml = base64.atob( encoded[1] );
   211 					}
   211 					}
   212 				} catch ( error ) {}
   212 				} catch ( error ) {}
   213 
   213 
   214 				if ( xml ) {
   214 				if ( xml ) {
   215 					// replace `fill` attributes
   215 					// Replace `fill` attributes.
   216 					xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
   216 					xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
   217 
   217 
   218 					// replace `style` attributes
   218 					// Replace `style` attributes.
   219 					xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
   219 					xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
   220 
   220 
   221 					// replace `fill` properties in `<style>` tags
   221 					// Replace `fill` properties in `<style>` tags.
   222 					xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
   222 					xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
   223 
   223 
   224 					if ( 'btoa' in window ) {
   224 					if ( 'btoa' in window ) {
   225 						xml = window.btoa( xml );
   225 						xml = window.btoa( xml );
   226 					} else {
   226 					} else {