r56220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56219‎ | r56220 | r56221 >
Date:04:46, 12 September 2009
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Resotred automatic ellipsis for suggestions, added autoEllipse plugin. Also noticed that namespaceSelect needed to be added to list of combined and minified scripts. Ellipis seems a little screwy still - working on getting it to be more stable.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/SimpleSearch/SimpleSearch.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/combine.sh (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.min.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/suggestions.css (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.autoEllipse.js (added) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/SimpleSearch/SimpleSearch.js
@@ -80,27 +80,28 @@
8181 render: function( query ) {
8282 var perfectMatch = false;
8383 $j(this).closest( '.suggestions' ).find( '.suggestions-results div' ).each( function() {
84 - if ( $j(this).text() == query ) {
 84+ if ( $j(this).data( 'text' ) == query ) {
8585 perfectMatch = true;
8686 }
8787 } );
8888 if ( perfectMatch ) {
8989 if ( $j(this).children().size() == 0 ) {
90 - $j(this).append(
91 - $j( '<div />' )
92 - .addClass( 'special-label' )
93 - .text( gM( 'simplesearch-containing' ) )
94 - );
95 - $j(this).append(
96 - $j( '<span />' ).addClass( 'special-query' ).text( query )
97 - );
9890 $j(this).show();
 91+ $label = $j( '<div />' )
 92+ .addClass( 'special-label' )
 93+ .text( gM( 'simplesearch-containing' ) )
 94+ .appendTo( $j(this) );
 95+ $query = $j( '<span />' )
 96+ .addClass( 'special-query' )
 97+ .text( query )
 98+ .appendTo( $j(this) );
 99+ $query.autoEllipse();
99100 } else {
100 - $j(this).find( '.special-query' ).text( query );
 101+ $j(this).find( '.special-query' ).empty().text( query ).autoEllipse();
101102 }
102103 } else {
 104+ $j(this).hide();
103105 $j(this).empty();
104 - $j(this).hide();
105106 }
106107 },
107108 select: function( $textbox ) {
Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -18,10 +18,10 @@
1919 private static $styleFiles = array(
2020 'base_sets' => array(
2121 'raw' => array(
22 - array( 'src' => 'css/suggestions.css', 'version' => 5 ),
 22+ array( 'src' => 'css/suggestions.css', 'version' => 6 ),
2323 array( 'src' => 'css/wikiEditor.css', 'version' => 4 ),
2424 array( 'src' => 'css/wikiEditor.toolbar.css', 'version' => 5 ),
25 - array( 'src' => 'css/wikiEditor.dialogs.css', 'version' => 2 ),
 25+ array( 'src' => 'css/wikiEditor.dialogs.css', 'version' => 1 ),
2626 array( 'src' => 'css/wikiEditor.toc.css', 'version' => 5 ),
2727 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2' ),
2828 ),
@@ -57,22 +57,23 @@
5858 'base_sets' => array(
5959 'raw' => array(
6060 array( 'src' => 'js/plugins/jquery.async.js', 'version' => 3 ),
 61+ array( 'src' => 'js/plugins/jquery.autoEllipse.js', 'version' => 1 ),
6162 array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 3 ),
6263 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 3 ),
63 - array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 0 ),
64 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 2 ),
65 - array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 10 ),
 64+ array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
 65+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 1 ),
 66+ array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 9 ),
6667 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 4 ),
6768 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ),
68 - array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 2 ),
69 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 8 ),
 69+ array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 1 ),
 70+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 5 ),
7071 array( 'src' => 'js/js2/jquery-ui-1.7.2.js', 'version' => '1.7.2x' ),
7172 ),
7273 'combined' => array(
73 - array( 'src' => 'js/plugins.combined.js', 'version' => 19 ),
 74+ array( 'src' => 'js/plugins.combined.js', 'version' => 18 ),
7475 ),
7576 'minified' => array(
76 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 19 ),
 77+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 18 ),
7778 ),
7879 ),
7980 );
Index: trunk/extensions/UsabilityInitiative/combine.sh
@@ -5,7 +5,7 @@
66 echo "Merging raw scripts and styles"
77 # Explicitly including scripts is important, because loading order is important
88 cat js/js2/jquery-1.3.2.js js/js2/jquery-ui-1.7.2.js js/js2/js2.js > js/js2.combined.js
9 -cat js/plugins/jquery.async.js js/plugins/jquery.browser.js js/plugins/jquery.cookie.js js/plugins/jquery.suggestions.js js/plugins/jquery.textSelection.js js/plugins/jquery.wikiEditor.js js/plugins/jquery.wikiEditor.dialogs.js js/plugins/jquery.wikiEditor.toolbar.js js/plugins/jquery.wikiEditor.toc.js > js/plugins.combined.js
 9+cat js/plugins/jquery.async.js js/plugins/jquery.autoEllipse.js js/plugins/jquery.browser.js js/plugins/jquery.cookie.js js/plugins/jquery.namespaceSelect.js js/plugins/jquery.suggestions.js js/plugins/jquery.textSelection.js js/plugins/jquery.wikiEditor.js js/plugins/jquery.wikiEditor.dialogs.js js/plugins/jquery.wikiEditor.toolbar.js js/plugins/jquery.wikiEditor.toc.js > js/plugins.combined.js
1010 # Styles can be loaded in any order
1111 cat css/*.css > css/combined.css
1212 # For more info on JSMin, see: http://www.crockford.com/javascript/jsmin.html
Index: trunk/extensions/UsabilityInitiative/css/suggestions.css
@@ -39,6 +39,7 @@
4040 padding: 0.25em 0.25em;
4141 line-height: 1.25em;
4242 margin: 0;
 43+ width: 100%;
4344 }
4445 .suggestions-result-current {
4546 background-color: #4C59A6;
Index: trunk/extensions/UsabilityInitiative/css/combined.css
@@ -39,6 +39,7 @@
4040 padding: 0.25em 0.25em;
4141 line-height: 1.25em;
4242 margin: 0;
 43+ width: 100%;
4344 }
4445 .suggestions-result-current {
4546 background-color: #4C59A6;
Index: trunk/extensions/UsabilityInitiative/css/combined.min.css
@@ -37,6 +37,7 @@
3838 padding:0.25em 0.25em;
3939 line-height:1.25em;
4040 margin:0;
 41+width:100%;
4142 }
4243 .suggestions-result-current{
4344 background-color:#4C59A6;
@@ -445,4 +446,4 @@
446447 background-color:white;
447448 text-decoration:none;
448449 border-color:#a8d7f9;
449 -}
\ No newline at end of file
 450+}
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.autoEllipse.js
@@ -0,0 +1,21 @@
 2+/**
 3+ * Plugin that automatically truncates the plain text contents of an element and adds an ellipsis
 4+ */
 5+( function( $ ) {
 6+
 7+$.fn.autoEllipse = function() {
 8+ $(this).each( function() {
 9+ var text = $(this).text();
 10+ var $text = $( '<span />' ).text( text ).css( 'whiteSpace', 'nowrap' );
 11+ $(this).empty().append( $text );
 12+ if ( $text.outerWidth() > $(this).outerWidth() ) {
 13+ var i = text.length;
 14+ while ( $text.outerWidth() > $(this).outerWidth() && i > 0 ) {
 15+ $text.text( text.substr( 0, i ) + '...' );
 16+ i--;
 17+ }
 18+ }
 19+ } );
 20+};
 21+
 22+} )( jQuery );
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -125,14 +125,15 @@
126126 $result = $( '<div />' )
127127 .addClass( 'suggestions-result' )
128128 .attr( 'rel', i )
129 - .data( 'text', context.config.suggestions[i] );
 129+ .data( 'text', context.config.suggestions[i] )
 130+ .appendTo( $results );
130131 // Allow custom rendering
131132 if ( typeof context.config.result.render == 'function' ) {
132133 context.config.result.render.call( $result, context.config.suggestions[i] );
133134 } else {
134135 $result.text( context.config.suggestions[i] );
 136+ $result.autoEllipse();
135137 }
136 - $results.append( $result );
137138 }
138139 // Update the size and position of the list
139140 context.data.$container.css( {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -76,8 +76,28 @@
7777
7878 })(jQuery);
7979
80 -/*
 80+/**
 81+ * Plugin that automatically truncates the plain text contents of an element and adds an ellipsis
 82+ */
 83+( function( $ ) {
8184
 85+$.fn.autoEllipse = function() {
 86+ $(this).each( function() {
 87+ var text = $(this).text();
 88+ var $text = $( '<span />' ).text( text ).css( 'whiteSpace', 'nowrap' );
 89+ $(this).empty().append( $text );
 90+ if ( $text.outerWidth() > $(this).outerWidth() ) {
 91+ var i = text.length;
 92+ while ( $text.outerWidth() > $(this).outerWidth() && i > 0 ) {
 93+ $text.text( text.substr( 0, i ) + '...' );
 94+ i--;
 95+ }
 96+ }
 97+ } );
 98+};
 99+
 100+} )( jQuery );/*
 101+
82102 jQuery Browser Plugin
83103 * Version 2.3
84104 * 2008-09-17 19:27:05
@@ -256,6 +276,26 @@
257277 };
258278
259279 /**
 280+ * Plugin that fills a <select> with namespaces
 281+ */
 282+
 283+(function ($) {
 284+$.fn.namespaceSelector = function( defaultNS ) {
 285+ if ( typeof defaultNS == 'undefined' )
 286+ defaultNS = 0;
 287+ return this.each( function() {
 288+ for ( var id in wgFormattedNamespaces ) {
 289+ var opt = $( '<option />' )
 290+ .attr( 'value', id )
 291+ .text( wgFormattedNamespaces[id] );
 292+ if ( id == defaultNS )
 293+ opt.attr( 'selected', 'selected' );
 294+ opt.appendTo( $(this) );
 295+ }
 296+ });
 297+};})(jQuery);
 298+
 299+/**
260300 * This plugin provides a generic way to add suggestions to a text box.
261301 *
262302 * Usage:
@@ -382,14 +422,15 @@
383423 $result = $( '<div />' )
384424 .addClass( 'suggestions-result' )
385425 .attr( 'rel', i )
386 - .data( 'text', context.config.suggestions[i] );
 426+ .data( 'text', context.config.suggestions[i] )
 427+ .appendTo( $results );
387428 // Allow custom rendering
388429 if ( typeof context.config.result.render == 'function' ) {
389430 context.config.result.render.call( $result, context.config.suggestions[i] );
390431 } else {
391432 $result.text( context.config.suggestions[i] );
 433+ $result.autoEllipse();
392434 }
393 - $results.append( $result );
394435 }
395436 // Update the size and position of the list
396437 context.data.$container.css( {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -11,19 +11,20 @@
1212 {var i=0,l=array.length,loop=opts.loop||function(){};$.whileAsync($.extend(opts,{test:function(){return i<l;},loop:function()
1313 {var val=array[i];return loop.call(val,i++,val);}}));}
1414 $.fn.eachAsync=function(opts)
15 -{$.eachAsync(this,opts);return this;}})(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]);}
 15+{$.eachAsync(this,opts);return this;}})(jQuery);(function($){$.fn.autoEllipse=function(){$(this).each(function(){var text=$(this).text();var $text=$('<span />').text(text).css('whiteSpace','nowrap');$(this).empty().append($text);if($text.outerWidth()>$(this).outerWidth()){var i=text.length;while($text.outerWidth()>$(this).outerWidth()&&i>0){$text.text(text.substr(0,i)+'...');i--;}}});};})(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]);}
1616 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';}
1717 if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}
1818 r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent);})(jQuery);jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
1919 var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
2020 expires='; expires='+date.toUTCString();}
2121 var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
22 -return cookieValue;}};(function($){$.suggestions={cancel:function(context){if(context.data.timerID!=null){clearTimeout(context.data.timerID);}
 22+return cookieValue;}};(function($){$.fn.namespaceSelector=function(defaultNS){if(typeof defaultNS=='undefined')
 23+defaultNS=0;return this.each(function(){for(var id in wgFormattedNamespaces){var opt=$('<option />').attr('value',id).text(wgFormattedNamespaces[id]);if(id==defaultNS)
 24+opt.attr('selected','selected');opt.appendTo($(this));}});};})(jQuery);(function($){$.suggestions={cancel:function(context){if(context.data.timerID!=null){clearTimeout(context.data.timerID);}
2325 if(typeof context.config.cancel=='function'){context.config.cancel.call(context.data.$textbox);}},restore:function(context){context.data.$textbox.val(context.data.prevText);},update:function(context,delayed){function maybeFetch(){if(context.data.$textbox.val()!==context.data.prevText){context.data.prevText=context.data.$textbox.val();if(typeof context.config.fetch=='function'){context.config.fetch.call(context.data.$textbox,context.data.$textbox.val());}}}
2426 if(context.data.timerID!=null){clearTimeout(context.data.timerID);}
2527 if(delayed){context.data.timerID=setTimeout(maybeFetch,context.config.delay);}else{maybeFetch();}
26 -$.suggestions.special(context);},special:function(context){if(typeof context.config.special.render=='function'){setTimeout(function(){$special=context.data.$container.find('.suggestions-special');context.config.special.render.call($special,context.data.$textbox.val());},1);}},configure:function(context,property,value){switch(property){case'fetch':case'cancel':case'special':case'result':case'$region':context.config[property]=value;break;case'suggestions':context.config[property]=value;if(typeof context.data!=='undefined'){if(context.config.suggestions.length==0){context.data.$container.hide();}else{context.data.$container.show();var $results=context.data.$container.children('.suggestions-results');$results.empty();for(var i=0;i<context.config.suggestions.length;i++){$result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{$result.text(context.config.suggestions[i]);}
27 -$results.append($result);}
 28+$.suggestions.special(context);},special:function(context){if(typeof context.config.special.render=='function'){setTimeout(function(){$special=context.data.$container.find('.suggestions-special');context.config.special.render.call($special,context.data.$textbox.val());},1);}},configure:function(context,property,value){switch(property){case'fetch':case'cancel':case'special':case'result':case'$region':context.config[property]=value;break;case'suggestions':context.config[property]=value;if(typeof context.data!=='undefined'){if(context.config.suggestions.length==0){context.data.$container.hide();}else{context.data.$container.show();var $results=context.data.$container.children('.suggestions-results');$results.empty();for(var i=0;i<context.config.suggestions.length;i++){$result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]).appendTo($results);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{$result.text(context.config.suggestions[i]);$result.autoEllipse();}}
2829 context.data.$container.css({'top':context.config.$region.offset().top+context.config.$region.outerHeight(),'bottom':'auto','width':context.config.$region.outerWidth(),'height':'auto','left':context.config.$region.offset().left,'right':'auto'});}}
2930 break;case'maxRows':context.config[property]=Math.max(1,Math.min(100,value));break;case'delay':context.config[property]=Math.max(0,Math.min(12000,value));break;case'submitOnClick':context.config[property]=value?true:false;break;}},highlight:function(context,result,updateTextbox){var selected=context.data.$container.find('.suggestions-result-current')
3031 if(!result.get||selected.get(0)!=result.get(0)){if(result=='prev'){result=selected.prev();}else if(result=='next'){if(selected.size()==0)

Follow-up revisions

RevisionCommit summaryAuthorDate
r60792Fixme on r56220: Fix spelling ellipse -> ellipsisdemon13:47, 7 January 2010

Comments

#Comment by Tim Starling (talk | contribs)   05:13, 1 December 2009

Needs spelling fix, ellipse -> ellipsis, especially in the public interface name.

Status & tagging log