2013-12-04 05:37:09 +01:00
|
|
|
/**
|
|
|
|
* Attempt to re-color SVG icons used in the admin menu or the toolbar
|
|
|
|
*
|
2018-06-28 04:30:15 +02:00
|
|
|
* @output wp-admin/js/svg-painter.js
|
2013-12-04 05:37:09 +01:00
|
|
|
*/
|
2013-12-05 23:01:10 +01:00
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
wp.svgPainter = ( function( $, window, document, undefined ) {
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
'use strict';
|
2024-09-08 00:44:17 +02:00
|
|
|
var selector, painter,
|
2013-12-04 05:37:09 +01:00
|
|
|
colorscheme = {},
|
2013-12-04 05:13:11 +01:00
|
|
|
elements = [];
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2021-03-18 20:01:03 +01:00
|
|
|
$( function() {
|
2024-09-08 00:44:17 +02:00
|
|
|
wp.svgPainter.init();
|
2013-12-04 05:13:11 +01:00
|
|
|
});
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
return {
|
|
|
|
init: function() {
|
2013-12-05 23:01:10 +01:00
|
|
|
painter = this;
|
2013-12-04 05:13:11 +01:00
|
|
|
selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2024-09-08 00:44:17 +02:00
|
|
|
painter.setColors();
|
|
|
|
painter.findElements();
|
|
|
|
painter.paint();
|
2013-12-04 05:13:11 +01:00
|
|
|
},
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
setColors: function( colors ) {
|
|
|
|
if ( typeof colors === 'undefined' && typeof window._wpColorScheme !== 'undefined' ) {
|
|
|
|
colors = window._wpColorScheme;
|
|
|
|
}
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
if ( colors && colors.icons && colors.icons.base && colors.icons.current && colors.icons.focus ) {
|
|
|
|
colorscheme = colors.icons;
|
|
|
|
}
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
},
|
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
findElements: function() {
|
|
|
|
selector.each( function() {
|
|
|
|
var $this = $(this), bgImage = $this.css( 'background-image' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
if ( bgImage && bgImage.indexOf( 'data:image/svg+xml;base64' ) != -1 ) {
|
|
|
|
elements.push( $this );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
paint: function() {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Loop through all elements.
|
2013-12-04 05:13:11 +01:00
|
|
|
$.each( elements, function( index, $element ) {
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
var $menuitem = $element.parent().parent();
|
|
|
|
|
|
|
|
if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Paint icon in 'current' color.
|
2013-12-05 23:01:10 +01:00
|
|
|
painter.paintElement( $element, 'current' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
} else {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Paint icon in base color.
|
2013-12-05 23:01:10 +01:00
|
|
|
painter.paintElement( $element, 'base' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Set hover callbacks.
|
2021-02-23 20:45:04 +01:00
|
|
|
$menuitem.on( 'mouseenter', function() {
|
|
|
|
painter.paintElement( $element, 'focus' );
|
|
|
|
} ).on( 'mouseleave', function() {
|
|
|
|
// Match the delay from hoverIntent.
|
|
|
|
window.setTimeout( function() {
|
|
|
|
painter.paintElement( $element, 'base' );
|
|
|
|
}, 100 );
|
|
|
|
} );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
paintElement: function( $element, colorType ) {
|
|
|
|
var xml, encoded, color;
|
|
|
|
|
|
|
|
if ( ! colorType || ! colorscheme.hasOwnProperty( colorType ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
color = colorscheme[ colorType ];
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Only accept hex colors: #101 or #101010.
|
2013-12-04 05:13:11 +01:00
|
|
|
if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
return;
|
2013-12-04 05:13:11 +01:00
|
|
|
}
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 22:16:11 +01:00
|
|
|
xml = $element.data( 'wp-ui-svg-' + color );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-05 23:01:10 +01:00
|
|
|
if ( xml === 'none' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
if ( ! xml ) {
|
2013-12-05 23:01:10 +01:00
|
|
|
encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/ );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-04 05:13:11 +01:00
|
|
|
if ( ! encoded || ! encoded[1] ) {
|
2013-12-05 23:01:10 +01:00
|
|
|
$element.data( 'wp-ui-svg-' + color, 'none' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
return;
|
2013-12-04 05:13:11 +01:00
|
|
|
}
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-05 23:01:10 +01:00
|
|
|
try {
|
2024-09-08 00:44:17 +02:00
|
|
|
xml = window.atob( encoded[1] );
|
2013-12-05 23:01:10 +01:00
|
|
|
} catch ( error ) {}
|
|
|
|
|
|
|
|
if ( xml ) {
|
2020-01-29 01:45:18 +01:00
|
|
|
// Replace `fill` attributes.
|
2013-12-05 23:01:10 +01:00
|
|
|
xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Replace `style` attributes.
|
2013-12-05 23:01:10 +01:00
|
|
|
xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Replace `fill` properties in `<style>` tags.
|
2013-12-05 23:01:10 +01:00
|
|
|
xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2024-09-08 00:44:17 +02:00
|
|
|
xml = window.btoa( xml );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
|
2013-12-05 23:01:10 +01:00
|
|
|
$element.data( 'wp-ui-svg-' + color, xml );
|
2013-12-04 05:13:11 +01:00
|
|
|
} else {
|
2013-12-05 23:01:10 +01:00
|
|
|
$element.data( 'wp-ui-svg-' + color, 'none' );
|
|
|
|
return;
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-05 23:01:10 +01:00
|
|
|
$element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
|
Say hello to a fresh new look for the WordPress admin.
Still to come: more color schemes, a responsive component, and more.
see #25858.
props iammattthomas, tillkruess, EmpireOfLight, melchoyce, ryelle, joen, mitchoyoshitaka, sirbrillig, andypeatling, isaackeyet, Otto42, dd32, matt, helen.
Built from https://develop.svn.wordpress.org/trunk@26072
git-svn-id: http://core.svn.wordpress.org/trunk@25992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-11-10 01:27:10 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})( jQuery, window, document );
|