From: Roan Kattouw Date: Sat, 14 May 2011 17:56:01 +0000 (+0000) Subject: (bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads to... X-Git-Tag: 1.31.0-rc.0~30186 X-Git-Url: http://git.cyclocoop.org/wiki/Target_page?a=commitdiff_plain;h=f3a55bdbeaa0506226c65615f754eb255b5bd330;p=lhc%2Fweb%2Fwiklou.git (bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads to cache pollution --- diff --git a/resources/jquery/jquery.autoEllipsis.js b/resources/jquery/jquery.autoEllipsis.js index 0ec1ad31cd..7bdc7f5242 100644 --- a/resources/jquery/jquery.autoEllipsis.js +++ b/resources/jquery/jquery.autoEllipsis.js @@ -3,7 +3,7 @@ */ ( function( $ ) { -// Cache ellipsed substrings for every string-width combination +// Cache ellipsed substrings for every string-width-position combination var cache = { }; // Use a seperate cache when match highlighting is enabled var matchTextCache = { }; @@ -49,29 +49,40 @@ $.fn.autoEllipsis = function( options ) { var w = $container.width(); var pw = $protectedText ? $protectedText.width() : 0; // Try cache - if ( !( text in cache ) ) { - cache[text] = {}; - } - if ( options.matchText && !( text in matchTextCache ) ) { - matchTextCache[text] = {}; - } - if ( options.matchText && !( options.matchText in matchTextCache[text] ) ) { - matchTextCache[text][options.matchText] = {}; - } - if ( !options.matchText && w in cache[text] ) { - $container.html( cache[text][w] ); - if ( options.tooltip ) { - $container.attr( 'title', text ); + if ( options.matchText ) { + if ( !( text in matchTextCache ) ) { + matchTextCache[text] = {}; } - return; - } - if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) { - $container.html( matchTextCache[text][options.matchText][w] ); - if ( options.tooltip ) { - $container.attr( 'title', text ); + if ( !( options.matchText in matchTextCache[text] ) ) { + matchTextCache[text][options.matchText] = {}; + } + if ( !( w in matchTextCache[text][options.matchText] ) ) { + matchTextCache[text][options.matchText][w] = {}; + } + if ( options.position in matchTextCache[text][options.matchText][w] ) { + $container.html( matchTextCache[text][options.matchText][w][options.position] ); + if ( options.tooltip ) { + $container.attr( 'title', text ); + } + return; + } + } else { + if ( !( text in cache ) ) { + cache[text] = {}; + } + if ( !( w in cache[text] ) ) { + cache[text][w] = {}; + } + if ( options.position in cache[text][w] ) { + $container.html( cache[text][w][options.position] ); + if ( options.tooltip ) { + $container.attr( 'title', text ); + } + console.log("YAY CACHE HIT"); + return; } - return; } + if ( $trimmableText.width() + pw > w ) { switch ( options.position ) { case 'right': @@ -122,9 +133,9 @@ $.fn.autoEllipsis = function( options ) { } if ( options.matchText ) { $container.highlightText( options.matchText ); - matchTextCache[text][options.matchText][w] = $container.html(); + matchTextCache[text][options.matchText][w][options.position] = $container.html(); } else { - cache[text][w] = $container.html(); + cache[text][w][options.position] = $container.html(); } } );