Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: svg-painter.js
/**
[0] Fix | Delete
* Attempt to re-color SVG icons used in the admin menu or the toolbar
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-admin/js/svg-painter.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
window.wp = window.wp || {};
[6] Fix | Delete
[7] Fix | Delete
wp.svgPainter = ( function( $, window, document, undefined ) {
[8] Fix | Delete
'use strict';
[9] Fix | Delete
var selector, base64, painter,
[10] Fix | Delete
colorscheme = {},
[11] Fix | Delete
elements = [];
[12] Fix | Delete
[13] Fix | Delete
$(document).ready( function() {
[14] Fix | Delete
// Detection for browser SVG capability.
[15] Fix | Delete
if ( document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
[16] Fix | Delete
$( document.body ).removeClass( 'no-svg' ).addClass( 'svg' );
[17] Fix | Delete
wp.svgPainter.init();
[18] Fix | Delete
}
[19] Fix | Delete
});
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Needed only for IE9
[23] Fix | Delete
*
[24] Fix | Delete
* Based on jquery.base64.js 0.0.3 - https://github.com/yckart/jquery.base64.js
[25] Fix | Delete
*
[26] Fix | Delete
* Based on: https://gist.github.com/Yaffle/1284012
[27] Fix | Delete
*
[28] Fix | Delete
* Copyright (c) 2012 Yannick Albert (http://yckart.com)
[29] Fix | Delete
* Licensed under the MIT license
[30] Fix | Delete
* http://www.opensource.org/licenses/mit-license.php
[31] Fix | Delete
*/
[32] Fix | Delete
base64 = ( function() {
[33] Fix | Delete
var c,
[34] Fix | Delete
b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
[35] Fix | Delete
a256 = '',
[36] Fix | Delete
r64 = [256],
[37] Fix | Delete
r256 = [256],
[38] Fix | Delete
i = 0;
[39] Fix | Delete
[40] Fix | Delete
function init() {
[41] Fix | Delete
while( i < 256 ) {
[42] Fix | Delete
c = String.fromCharCode(i);
[43] Fix | Delete
a256 += c;
[44] Fix | Delete
r256[i] = i;
[45] Fix | Delete
r64[i] = b64.indexOf(c);
[46] Fix | Delete
++i;
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
function code( s, discard, alpha, beta, w1, w2 ) {
[51] Fix | Delete
var tmp, length,
[52] Fix | Delete
buffer = 0,
[53] Fix | Delete
i = 0,
[54] Fix | Delete
result = '',
[55] Fix | Delete
bitsInBuffer = 0;
[56] Fix | Delete
[57] Fix | Delete
s = String(s);
[58] Fix | Delete
length = s.length;
[59] Fix | Delete
[60] Fix | Delete
while( i < length ) {
[61] Fix | Delete
c = s.charCodeAt(i);
[62] Fix | Delete
c = c < 256 ? alpha[c] : -1;
[63] Fix | Delete
[64] Fix | Delete
buffer = ( buffer << w1 ) + c;
[65] Fix | Delete
bitsInBuffer += w1;
[66] Fix | Delete
[67] Fix | Delete
while( bitsInBuffer >= w2 ) {
[68] Fix | Delete
bitsInBuffer -= w2;
[69] Fix | Delete
tmp = buffer >> bitsInBuffer;
[70] Fix | Delete
result += beta.charAt(tmp);
[71] Fix | Delete
buffer ^= tmp << bitsInBuffer;
[72] Fix | Delete
}
[73] Fix | Delete
++i;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
if ( ! discard && bitsInBuffer > 0 ) {
[77] Fix | Delete
result += beta.charAt( buffer << ( w2 - bitsInBuffer ) );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
return result;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
function btoa( plain ) {
[84] Fix | Delete
if ( ! c ) {
[85] Fix | Delete
init();
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
plain = code( plain, false, r256, b64, 8, 6 );
[89] Fix | Delete
return plain + '===='.slice( ( plain.length % 4 ) || 4 );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
function atob( coded ) {
[93] Fix | Delete
var i;
[94] Fix | Delete
[95] Fix | Delete
if ( ! c ) {
[96] Fix | Delete
init();
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
coded = coded.replace( /[^A-Za-z0-9\+\/\=]/g, '' );
[100] Fix | Delete
coded = String(coded).split('=');
[101] Fix | Delete
i = coded.length;
[102] Fix | Delete
[103] Fix | Delete
do {
[104] Fix | Delete
--i;
[105] Fix | Delete
coded[i] = code( coded[i], true, r64, a256, 6, 8 );
[106] Fix | Delete
} while ( i > 0 );
[107] Fix | Delete
[108] Fix | Delete
coded = coded.join('');
[109] Fix | Delete
return coded;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
return {
[113] Fix | Delete
atob: atob,
[114] Fix | Delete
btoa: btoa
[115] Fix | Delete
};
[116] Fix | Delete
})();
[117] Fix | Delete
[118] Fix | Delete
return {
[119] Fix | Delete
init: function() {
[120] Fix | Delete
painter = this;
[121] Fix | Delete
selector = $( '#adminmenu .wp-menu-image, #wpadminbar .ab-item' );
[122] Fix | Delete
[123] Fix | Delete
this.setColors();
[124] Fix | Delete
this.findElements();
[125] Fix | Delete
this.paint();
[126] Fix | Delete
},
[127] Fix | Delete
[128] Fix | Delete
setColors: function( colors ) {
[129] Fix | Delete
if ( typeof colors === 'undefined' && typeof window._wpColorScheme !== 'undefined' ) {
[130] Fix | Delete
colors = window._wpColorScheme;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
if ( colors && colors.icons && colors.icons.base && colors.icons.current && colors.icons.focus ) {
[134] Fix | Delete
colorscheme = colors.icons;
[135] Fix | Delete
}
[136] Fix | Delete
},
[137] Fix | Delete
[138] Fix | Delete
findElements: function() {
[139] Fix | Delete
selector.each( function() {
[140] Fix | Delete
var $this = $(this), bgImage = $this.css( 'background-image' );
[141] Fix | Delete
[142] Fix | Delete
if ( bgImage && bgImage.indexOf( 'data:image/svg+xml;base64' ) != -1 ) {
[143] Fix | Delete
elements.push( $this );
[144] Fix | Delete
}
[145] Fix | Delete
});
[146] Fix | Delete
},
[147] Fix | Delete
[148] Fix | Delete
paint: function() {
[149] Fix | Delete
// Loop through all elements.
[150] Fix | Delete
$.each( elements, function( index, $element ) {
[151] Fix | Delete
var $menuitem = $element.parent().parent();
[152] Fix | Delete
[153] Fix | Delete
if ( $menuitem.hasClass( 'current' ) || $menuitem.hasClass( 'wp-has-current-submenu' ) ) {
[154] Fix | Delete
// Paint icon in 'current' color.
[155] Fix | Delete
painter.paintElement( $element, 'current' );
[156] Fix | Delete
} else {
[157] Fix | Delete
// Paint icon in base color.
[158] Fix | Delete
painter.paintElement( $element, 'base' );
[159] Fix | Delete
[160] Fix | Delete
// Set hover callbacks.
[161] Fix | Delete
$menuitem.on( 'mouseenter', function() {
[162] Fix | Delete
painter.paintElement( $element, 'focus' );
[163] Fix | Delete
} ).on( 'mouseleave', function() {
[164] Fix | Delete
// Match the delay from hoverIntent.
[165] Fix | Delete
window.setTimeout( function() {
[166] Fix | Delete
painter.paintElement( $element, 'base' );
[167] Fix | Delete
}, 100 );
[168] Fix | Delete
} );
[169] Fix | Delete
}
[170] Fix | Delete
});
[171] Fix | Delete
},
[172] Fix | Delete
[173] Fix | Delete
paintElement: function( $element, colorType ) {
[174] Fix | Delete
var xml, encoded, color;
[175] Fix | Delete
[176] Fix | Delete
if ( ! colorType || ! colorscheme.hasOwnProperty( colorType ) ) {
[177] Fix | Delete
return;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
color = colorscheme[ colorType ];
[181] Fix | Delete
[182] Fix | Delete
// Only accept hex colors: #101 or #101010.
[183] Fix | Delete
if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) {
[184] Fix | Delete
return;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
xml = $element.data( 'wp-ui-svg-' + color );
[188] Fix | Delete
[189] Fix | Delete
if ( xml === 'none' ) {
[190] Fix | Delete
return;
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
if ( ! xml ) {
[194] Fix | Delete
encoded = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,([A-Za-z0-9\+\/\=]+)/ );
[195] Fix | Delete
[196] Fix | Delete
if ( ! encoded || ! encoded[1] ) {
[197] Fix | Delete
$element.data( 'wp-ui-svg-' + color, 'none' );
[198] Fix | Delete
return;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
try {
[202] Fix | Delete
if ( 'atob' in window ) {
[203] Fix | Delete
xml = window.atob( encoded[1] );
[204] Fix | Delete
} else {
[205] Fix | Delete
xml = base64.atob( encoded[1] );
[206] Fix | Delete
}
[207] Fix | Delete
} catch ( error ) {}
[208] Fix | Delete
[209] Fix | Delete
if ( xml ) {
[210] Fix | Delete
// Replace `fill` attributes.
[211] Fix | Delete
xml = xml.replace( /fill="(.+?)"/g, 'fill="' + color + '"');
[212] Fix | Delete
[213] Fix | Delete
// Replace `style` attributes.
[214] Fix | Delete
xml = xml.replace( /style="(.+?)"/g, 'style="fill:' + color + '"');
[215] Fix | Delete
[216] Fix | Delete
// Replace `fill` properties in `<style>` tags.
[217] Fix | Delete
xml = xml.replace( /fill:.*?;/g, 'fill: ' + color + ';');
[218] Fix | Delete
[219] Fix | Delete
if ( 'btoa' in window ) {
[220] Fix | Delete
xml = window.btoa( xml );
[221] Fix | Delete
} else {
[222] Fix | Delete
xml = base64.btoa( xml );
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
$element.data( 'wp-ui-svg-' + color, xml );
[226] Fix | Delete
} else {
[227] Fix | Delete
$element.data( 'wp-ui-svg-' + color, 'none' );
[228] Fix | Delete
return;
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
$element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' );
[233] Fix | Delete
}
[234] Fix | Delete
};
[235] Fix | Delete
[236] Fix | Delete
})( jQuery, window, document );
[237] Fix | Delete
[238] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function