r68359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68358‎ | r68359 | r68360 >
Date:14:44, 21 June 2010
Author:adam
Status:ok
Tags:
Comment:
AutoEllipsis - Follow up to rr67755. Segregating caches as Roan suggested, to avoid edge case problems.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipsis.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -57,7 +57,7 @@
5858
5959 // Core functionality of extension scripts
6060 array( 'src' => 'js/plugins/jquery.async.js', 'version' => 3 ),
61 - array( 'src' => 'js/plugins/jquery.autoEllipsis.js', 'version' => 12 ),
 61+ array( 'src' => 'js/plugins/jquery.autoEllipsis.js', 'version' => 13 ),
6262 array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 8 ),
6363 array( 'src' => 'js/plugins/jquery.collapsibleTabs.js', 'version' => 6 ),
6464 array( 'src' => 'js/plugins/jquery.color.js', 'version' => 1 ),
@@ -80,10 +80,10 @@
8181 array( 'src' => 'js/thirdparty/contentCollector.js', 'version' => 2 ),
8282 ),
8383 'combined' => array(
84 - array( 'src' => 'js/plugins.combined.js', 'version' => 438 ),
 84+ array( 'src' => 'js/plugins.combined.js', 'version' => 439 ),
8585 ),
8686 'minified' => array(
87 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 442 ),
 87+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 443 ),
8888 ),
8989 ),
9090 );
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php
@@ -13,7 +13,7 @@
1414 static $scripts = array(
1515 'raw' => array(
1616 array( 'src' => 'Modules/Highlight/Highlight.js', 'version' => 5 ),
17 - array( 'src' => 'Modules/Preview/Preview.js', 'version' => 6 ),
 17+ array( 'src' => 'Modules/Preview/Preview.js', 'version' => 7 ),
1818 array( 'src' => 'Modules/Publish/Publish.js', 'version' => 6 ),
1919 array( 'src' => 'Modules/Toc/Toc.js', 'version' => 7 ),
2020 array( 'src' => 'Modules/Toolbar/Toolbar.js', 'version' => 96 ),
@@ -22,10 +22,10 @@
2323 array( 'src' => 'Modules/AddMediaWizard/AddMediaWizard.js', 'version' => 6 ),
2424 ),
2525 'combined' => array(
26 - array( 'src' => 'WikiEditor.combined.js', 'version' => 103 ),
 26+ array( 'src' => 'WikiEditor.combined.js', 'version' => 104 ),
2727 ),
2828 'minified' => array(
29 - array( 'src' => 'WikiEditor.combined.min.js', 'version' => 103 ),
 29+ array( 'src' => 'WikiEditor.combined.min.js', 'version' => 104 ),
3030 ),
3131 );
3232 static $messages = array(
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipsis.js
@@ -5,6 +5,8 @@
66
77 // Cache ellipsed substrings for every string-width combination
88 var cache = { };
 9+// Use a seperate cache when match highlighting is enabled
 10+var matchTextCache = { };
911
1012 $.fn.autoEllipsis = function( options ) {
1113 options = $.extend( {
@@ -67,8 +69,8 @@
6870 if ( !( text in cache ) ) {
6971 cache[text] = {};
7072 }
71 - if ( options.matchText && !( options.matchText in cache[text] ) ) {
72 - cache[text][options.matchText] = {};
 73+ if ( options.matchText && !( options.matchText in matchTextCache[text] ) ) {
 74+ matchTextCache[text][options.matchText] = {};
7375 }
7476 if ( !options.matchText && w in cache[text] ) {
7577 $container.html( cache[text][w] );
@@ -76,8 +78,8 @@
7779 $container.attr( 'title', text );
7880 return;
7981 }
80 - if( options.matchText && options.matchText in cache[text] && w in cache[text][options.matchText] ) {
81 - $container.html( cache[text][options.matchText][w] );
 82+ if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) {
 83+ $container.html( matchTextCache[text][options.matchText][w] );
8284 if ( options.tooltip )
8385 $container.attr( 'title', text );
8486 return;
@@ -131,7 +133,7 @@
132134 $container.attr( 'title', text );
133135 }
134136 if ( options.matchText ) {
135 - cache[text][options.matchText][w] = $container.html();
 137+ matchTextCache[text][options.matchText][w] = $container.html();
136138 } else {
137139 cache[text][w] = $container.html();
138140 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -213,6 +213,8 @@
214214
215215 // Cache ellipsed substrings for every string-width combination
216216 var cache = { };
 217+// Use a seperate cache when match highlighting is enabled
 218+var matchTextCache = { };
217219
218220 $.fn.autoEllipsis = function( options ) {
219221 options = $.extend( {
@@ -275,8 +277,8 @@
276278 if ( !( text in cache ) ) {
277279 cache[text] = {};
278280 }
279 - if ( options.matchText && !( options.matchText in cache[text] ) ) {
280 - cache[text][options.matchText] = {};
 281+ if ( options.matchText && !( options.matchText in matchTextCache[text] ) ) {
 282+ matchTextCache[text][options.matchText] = {};
281283 }
282284 if ( !options.matchText && w in cache[text] ) {
283285 $container.html( cache[text][w] );
@@ -284,8 +286,8 @@
285287 $container.attr( 'title', text );
286288 return;
287289 }
288 - if( options.matchText && options.matchText in cache[text] && w in cache[text][options.matchText] ) {
289 - $container.html( cache[text][options.matchText][w] );
 290+ if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) {
 291+ $container.html( matchTextCache[text][options.matchText][w] );
290292 if ( options.tooltip )
291293 $container.attr( 'title', text );
292294 return;
@@ -339,7 +341,7 @@
340342 $container.attr( 'title', text );
341343 }
342344 if ( options.matchText ) {
343 - cache[text][options.matchText][w] = $container.html();
 345+ matchTextCache[text][options.matchText][w] = $container.html();
344346 } else {
345347 cache[text][w] = $container.html();
346348 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -18,19 +18,19 @@
1919 {var i=0,l=array.length,loop=opts.loop||function(){};$.whileAsync($.extend(opts,{test:function(){return i<l;},loop:function()
2020 {var val=array[i];return loop.call(val,i++,val);}}));}
2121 $.fn.eachAsync=function(opts)
22 -{$.eachAsync(this,opts);return this;}})(jQuery);(function($){var cache={};$.fn.autoEllipsis=function(options){options=$.extend({'position':'center','tooltip':false,'restoreText':false,'hasSpan':false,'matchText':null},options);$(this).each(function(){var $this=$(this);if(options.restoreText){if(!$this.data('autoEllipsis.originalText')){$this.data('autoEllipsis.originalText',$this.text());}else{$this.text($this.data('autoEllipsis.originalText'));}}
 22+{$.eachAsync(this,opts);return this;}})(jQuery);(function($){var cache={};var matchTextCache={};$.fn.autoEllipsis=function(options){options=$.extend({'position':'center','tooltip':false,'restoreText':false,'hasSpan':false,'matchText':null},options);$(this).each(function(){var $this=$(this);if(options.restoreText){if(!$this.data('autoEllipsis.originalText')){$this.data('autoEllipsis.originalText',$this.text());}else{$this.text($this.data('autoEllipsis.originalText'));}}
2323 var $container=$this;var $trimmableText=null;var $protectedText=null;if(options.matchText){var text=$this.text();var matchedText=options.matchText;$trimmableText=$('<span />').css('whiteSpace','nowrap').addClass('autoellipsis-trimmed').text($this.text().substr(matchedText.length,$this.text().length));$protectedText=$('<span />').addClass('autoellipsis-matched').css('whiteSpace','nowrap').text(options.matchText);$container.empty().append($protectedText).append($trimmableText);}else{if(options.hasSpan){$trimmableText=$this.children(options.selector);}else{$trimmableText=$('<span />').css('whiteSpace','nowrap').text($this.text());$this.empty().append($trimmableText);}}
2424 var text=$container.text();var trimmableText=$trimmableText.text();var w=$container.width();var pw=$protectedText?$protectedText.width():0;if(!(text in cache)){cache[text]={};}
25 -if(options.matchText&&!(options.matchText in cache[text])){cache[text][options.matchText]={};}
 25+if(options.matchText&&!(options.matchText in matchTextCache[text])){matchTextCache[text][options.matchText]={};}
2626 if(!options.matchText&&w in cache[text]){$container.html(cache[text][w]);if(options.tooltip)
2727 $container.attr('title',text);return;}
28 -if(options.matchText&&options.matchText in cache[text]&&w in cache[text][options.matchText]){$container.html(cache[text][options.matchText][w]);if(options.tooltip)
 28+if(options.matchText&&options.matchText in matchTextCache[text]&&w in matchTextCache[text][options.matchText]){$container.html(matchTextCache[text][options.matchText][w]);if(options.tooltip)
2929 $container.attr('title',text);return;}
3030 if($trimmableText.width()+pw>w){switch(options.position){case'right':var l=0,r=trimmableText.length;do{var m=Math.ceil((l+r)/2);$trimmableText.text(trimmableText.substr(0,m)+'...');if($trimmableText.width()+pw>w){r=m-1;}else{l=m;}}while(l<r);$trimmableText.text(trimmableText.substr(0,l)+'...');break;case'center':var i=[Math.round(trimmableText.length/2),Math.round(trimmableText.length/2)];var side=1;while($trimmableText.outerWidth()+pw>w&&i[0]>0){$trimmableText.text(trimmableText.substr(0,i[0])+'...'+trimmableText.substr(i[1]));if(side==0){i[0]--;side=1;}else{i[1]++;side=0;}}
3131 break;case'left':var r=0;while($trimmableText.outerWidth()+pw>w&&r<trimmableText.length){$trimmableText.text('...'+trimmableText.substr(r));r++;}
3232 break;}}
3333 if(options.tooltip){$container.attr('title',text);}
34 -if(options.matchText){cache[text][options.matchText][w]=$container.html();}else{cache[text][w]=$container.html();}});};})(jQuery);(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}
 34+if(options.matchText){matchTextCache[text][options.matchText][w]=$container.html();}else{cache[text][w]=$container.html();}});};})(jQuery);(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}
3535 return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}
3636 if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}
3737 if(r.name==='opera'&&$.browser.version>=9.8){r.version=i.match(/version\/([0-9\.]*)/i)[1]||10;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r68360AutoEllipsis - Fixing a bug introduced in r68359adam14:56, 21 June 2010

Status & tagging log