http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88115

Revision: 88115
Author:   catrope
Date:     2011-05-14 17:56:01 +0000 (Sat, 14 May 2011)
Log Message:
-----------
(bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads 
to cache pollution

Modified Paths:
--------------
    trunk/phase3/resources/jquery/jquery.autoEllipsis.js

Modified: trunk/phase3/resources/jquery/jquery.autoEllipsis.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.autoEllipsis.js        2011-05-14 
17:16:07 UTC (rev 88114)
+++ trunk/phase3/resources/jquery/jquery.autoEllipsis.js        2011-05-14 
17:56:01 UTC (rev 88115)
@@ -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 @@
                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] = {};
                        }
-                       return;
+                       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;
+                       }
                }
+               
                if ( $trimmableText.width() + pw > w ) {
                        switch ( options.position ) {
                                case 'right':
@@ -122,9 +133,9 @@
                }
                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();
                }
                
        } );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to