From 54c6e4c1e0e70f675954aeb322ea494db8404448 Mon Sep 17 00:00:00 2001 From: Matt Thomas Date: Wed, 13 Nov 2013 15:26:10 +0000 Subject: [PATCH] Clean up the new svg-painter.js so that it passes our jshint; see #25858. Props jorbin. Built from https://develop.svn.wordpress.org/trunk@26131 git-svn-id: http://core.svn.wordpress.org/trunk@26043 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/svg-painter.js | 36 +++++++++++++++++-------------- wp-includes/js/svg-painter.min.js | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/wp-includes/js/svg-painter.js b/wp-includes/js/svg-painter.js index 126942f6b6..36b6fe1a2c 100644 --- a/wp-includes/js/svg-painter.js +++ b/wp-includes/js/svg-painter.js @@ -1,4 +1,5 @@ -;var svgPainter = ( function( $, window, document, undefined ) { +/* global mp6_color_scheme:true */ +var svgPainter = ( function( $, window, document, undefined ) { 'use strict'; @@ -30,7 +31,7 @@ setColors : function( colors ) { if ( typeof colors === 'undefined' && typeof mp6_color_scheme !== 'undefined' ) { - var colors = mp6_color_scheme; + colors = mp6_color_scheme; } this.colorscheme = colors; @@ -86,19 +87,20 @@ if ( ! color.match( /^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i ) ) return; - var xml = $element.data( 'mp6-svg-' + color ); + var xml = $element.data( 'mp6-svg-' + color ), + base64; if ( ! xml ) { - var base64 = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,(.+)\)/ ); + base64 = $element.css( 'background-image' ).match( /.+data:image\/svg\+xml;base64,(.+)\)/ ); if ( ! base64 ) return; try { - var xml = window.atob( base64[1] ); + xml = window.atob( base64[1] ); } catch ( e ) { - var xml = $.base64.atob( base64[1] ); + xml = $.base64.atob( base64[1] ); } // replace `fill` attributes @@ -120,7 +122,7 @@ } - $element.attr( 'style', "background-image: url('data:image/svg+xml;base64," + xml + "') !important;" ); + $element.attr( 'style', 'background-image: url("data:image/svg+xml;base64,' + xml + '") !important;' ); } @@ -141,14 +143,15 @@ **/ ;(function($) { - var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", + var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', a256 = '', r64 = [256], r256 = [256], - i = 0; + i = 0, + c, Plugin; while(i < 256) { - var c = String.fromCharCode(i); + c = String.fromCharCode(i); a256 += c; r256[i] = i; r64[i] = b64.indexOf(c); @@ -161,10 +164,11 @@ i = 0, length = s.length, result = '', - bitsInBuffer = 0; + bitsInBuffer = 0, + tmp; while(i < length) { - var c = s.charCodeAt(i); + c = s.charCodeAt(i); c = c < 256 ? alpha[c] : -1; buffer = (buffer << w1) + c; @@ -172,7 +176,7 @@ while(bitsInBuffer >= w2) { bitsInBuffer -= w2; - var tmp = buffer >> bitsInBuffer; + tmp = buffer >> bitsInBuffer; result += beta.charAt(tmp); buffer ^= tmp << bitsInBuffer; } @@ -182,7 +186,7 @@ return result; } - var Plugin = $.base64 = function(dir, input, encode) { + Plugin = $.base64 = function(dir, input, encode) { return input ? Plugin[dir](input, encode) : dir ? null : this; }; @@ -191,8 +195,8 @@ return plain + '===='.slice((plain.length % 4) || 4); }; - $.base64.atob = function(coded, utf8decode) { - coded = coded.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + $.base64.atob = function(coded) { + coded = coded.replace(/[^A-Za-z0-9\+\/\=]/g, ''); coded = String(coded).split('='); var i = coded.length; do {--i; diff --git a/wp-includes/js/svg-painter.min.js b/wp-includes/js/svg-painter.min.js index dd3bd1b022..89ab4a1635 100644 --- a/wp-includes/js/svg-painter.min.js +++ b/wp-includes/js/svg-painter.min.js @@ -1 +1 @@ -var svgPainter=function(a,b,c){"use strict";return a(c).ready(function(){c.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")&&(c.body.className=c.body.className.replace("no-svg","svg")),svgPainter.init()}),{elements:[],init:function(){this.selector=a("#adminmenu .wp-menu-image, #wpadminbar .ab-item"),this.setColors(),this.findElements(),this.paint()},setColors:function(a){if("undefined"==typeof a&&"undefined"!=typeof mp6_color_scheme)var a=mp6_color_scheme;this.colorscheme=a},findElements:function(){this.selector.each(function(){var b=a(this).css("background-image");-1!=b.indexOf("data:image/svg+xml;base64")&&svgPainter.elements.push(a(this))})},paint:function(){a.each(this.elements,function(a,b){var c=b.parent().parent();c.hasClass("current")||c.hasClass("wp-has-current-submenu")?svgPainter.paintElement(b,svgPainter.colorscheme.icons.current):(svgPainter.paintElement(b,svgPainter.colorscheme.icons.base),c.hover(function(){svgPainter.paintElement(b,svgPainter.colorscheme.icons.focus)},function(){svgPainter.paintElement(b,svgPainter.colorscheme.icons.base)}))})},paintElement:function(c,d){if(d.match(/^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i)){var e=c.data("mp6-svg-"+d);if(!e){var f=c.css("background-image").match(/.+data:image\/svg\+xml;base64,(.+)\)/);if(!f)return;try{var e=b.atob(f[1])}catch(g){var e=a.base64.atob(f[1])}e=e.replace(/fill="(.+?)"/g,'fill="'+d+'"'),e=e.replace(/style="(.+?)"/g,'style="fill:'+d+'"'),e=e.replace(/fill:.*?;/g,"fill: "+d+";");try{e=b.btoa(e)}catch(g){e=a.base64.btoa(e)}c.data("mp6-svg-"+d,e)}c.attr("style","background-image: url('data:image/svg+xml;base64,"+e+"') !important;")}}}}(jQuery,window,document);!function(a){function b(a,b,c,d,e,f){a=String(a);for(var g=0,h=0,i=a.length,j="",k=0;i>h;){var l=a.charCodeAt(h);for(l=256>l?c[l]:-1,g=(g<=f;){k-=f;var m=g>>k;j+=d.charAt(m),g^=m<0&&(j+=d.charAt(g<g;){var h=String.fromCharCode(g);d+=h,f[g]=g,e[g]=c.indexOf(h),++g}var i=a.base64=function(a,b,c){return b?i[a](b,c):a?null:this};a.base64.btoa=function(a){return a=b(a,!1,f,c,8,6),a+"====".slice(a.length%4||4)},a.base64.atob=function(a){a=a.replace(/[^A-Za-z0-9\+\/\=]/g,""),a=String(a).split("=");var c=a.length;do--c,a[c]=b(a[c],!0,e,d,6,8);while(c>0);return a=a.join("")}}(jQuery); \ No newline at end of file +var svgPainter=function(a,b,c){"use strict";return a(c).ready(function(){c.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")&&(c.body.className=c.body.className.replace("no-svg","svg")),svgPainter.init()}),{elements:[],init:function(){this.selector=a("#adminmenu .wp-menu-image, #wpadminbar .ab-item"),this.setColors(),this.findElements(),this.paint()},setColors:function(a){"undefined"==typeof a&&"undefined"!=typeof mp6_color_scheme&&(a=mp6_color_scheme),this.colorscheme=a},findElements:function(){this.selector.each(function(){var b=a(this).css("background-image");-1!=b.indexOf("data:image/svg+xml;base64")&&svgPainter.elements.push(a(this))})},paint:function(){a.each(this.elements,function(a,b){var c=b.parent().parent();c.hasClass("current")||c.hasClass("wp-has-current-submenu")?svgPainter.paintElement(b,svgPainter.colorscheme.icons.current):(svgPainter.paintElement(b,svgPainter.colorscheme.icons.base),c.hover(function(){svgPainter.paintElement(b,svgPainter.colorscheme.icons.focus)},function(){svgPainter.paintElement(b,svgPainter.colorscheme.icons.base)}))})},paintElement:function(c,d){if(d.match(/^(#[0-9a-f]{3}|#[0-9a-f]{6})$/i)){var e,f=c.data("mp6-svg-"+d);if(!f){if(e=c.css("background-image").match(/.+data:image\/svg\+xml;base64,(.+)\)/),!e)return;try{f=b.atob(e[1])}catch(g){f=a.base64.atob(e[1])}f=f.replace(/fill="(.+?)"/g,'fill="'+d+'"'),f=f.replace(/style="(.+?)"/g,'style="fill:'+d+'"'),f=f.replace(/fill:.*?;/g,"fill: "+d+";");try{f=b.btoa(f)}catch(g){f=a.base64.btoa(f)}c.data("mp6-svg-"+d,f)}c.attr("style",'background-image: url("data:image/svg+xml;base64,'+f+'") !important;')}}}}(jQuery,window,document);!function(a){function b(a,b,d,e,f,g){a=String(a);for(var h,i=0,j=0,k=a.length,l="",m=0;k>j;){for(c=a.charCodeAt(j),c=256>c?d[c]:-1,i=(i<=g;)m-=g,h=i>>m,l+=e.charAt(h),i^=h<0&&(l+=e.charAt(i<i;)c=String.fromCharCode(i),f+=c,h[i]=i,g[i]=e.indexOf(c),++i;d=a.base64=function(a,b,c){return b?d[a](b,c):a?null:this},a.base64.btoa=function(a){return a=b(a,!1,h,e,8,6),a+"====".slice(a.length%4||4)},a.base64.atob=function(a){a=a.replace(/[^A-Za-z0-9\+\/\=]/g,""),a=String(a).split("=");var c=a.length;do--c,a[c]=b(a[c],!0,g,f,6,8);while(c>0);return a=a.join("")}}(jQuery); \ No newline at end of file