r68298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68297‎ | r68298 | r68299 >
Date:01:46, 20 June 2010
Author:adam
Status:ok
Tags:
Comment:
SimpleSearch - ensuring that whatever is currently in the text input is the string that is sent when enter is presed, wheter the mouse is selecting something or not
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.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.suggestions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -64,7 +64,7 @@
6565 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ),
6666 array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ),
6767 array( 'src' => 'js/plugins/jquery.expandableField.js', 'version' => 17 ),
68 - array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 28 ),
 68+ array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 29 ),
6969 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 36 ),
7070 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 195 ),
7171 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ),
@@ -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' => 436 ),
 84+ array( 'src' => 'js/plugins.combined.js', 'version' => 437 ),
8585 ),
8686 'minified' => array(
87 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 440 ),
 87+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 441 ),
8888 ),
8989 ),
9090 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.suggestions.js
@@ -155,6 +155,7 @@
156156 .attr( 'rel', i )
157157 .data( 'text', context.config.suggestions[i] )
158158 .mousemove( function( e ) {
 159+ context.data.selectedWithMouse = true;
159160 $.suggestions.highlight(
160161 context, $(this).closest( '.suggestions-results div' ), false
161162 );
@@ -278,6 +279,7 @@
279280 case 40:
280281 if ( wasVisible ) {
281282 $.suggestions.highlight( context, 'next', true );
 283+ context.data.selectedWithMouse = false;
282284 } else {
283285 $.suggestions.update( context, false );
284286 }
@@ -287,6 +289,7 @@
288290 case 38:
289291 if ( wasVisible ) {
290292 $.suggestions.highlight( context, 'prev', true );
 293+ context.data.selectedWithMouse = false;
291294 }
292295 preventDefault = wasVisible;
293296 break;
@@ -303,8 +306,9 @@
304307 context.data.$container.hide();
305308 preventDefault = wasVisible;
306309 selected = context.data.$container.find( '.suggestions-result-current' );
307 - if ( selected.size() == 0 ) {
308 - // if nothing is selected, cancel any current requests and submit the form
 310+ if ( selected.size() == 0 || context.data.selectedWithMouse ) {
 311+ // if nothing is selected OR if something was selected with the mouse,
 312+ // cancel any current requests and submit the form
309313 $.suggestions.cancel( context );
310314 context.config.$region.closest( 'form' ).submit();
311315 } else if ( selected.is( '.suggestions-special' ) ) {
@@ -392,7 +396,8 @@
393397 'visibleResults': 0,
394398 // Suggestion the last mousedown event occured on
395399 'mouseDownOn': $( [] ),
396 - '$textbox': $(this)
 400+ '$textbox': $(this),
 401+ 'selectedWithMouse': false
397402 };
398403 // Setup the css for positioning the results box
399404 var newCSS = {
@@ -454,6 +459,7 @@
455460 context.data.$textbox.focus();
456461 } )
457462 .mousemove( function( e ) {
 463+ context.data.selectedWithMouse = true;
458464 $.suggestions.highlight(
459465 context, $( e.target ).closest( '.suggestions-special' ), false
460466 );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1124,6 +1124,7 @@
11251125 .attr( 'rel', i )
11261126 .data( 'text', context.config.suggestions[i] )
11271127 .mousemove( function( e ) {
 1128+ context.data.selectedWithMouse = true;
11281129 $.suggestions.highlight(
11291130 context, $(this).closest( '.suggestions-results div' ), false
11301131 );
@@ -1247,6 +1248,7 @@
12481249 case 40:
12491250 if ( wasVisible ) {
12501251 $.suggestions.highlight( context, 'next', true );
 1252+ context.data.selectedWithMouse = false;
12511253 } else {
12521254 $.suggestions.update( context, false );
12531255 }
@@ -1256,6 +1258,7 @@
12571259 case 38:
12581260 if ( wasVisible ) {
12591261 $.suggestions.highlight( context, 'prev', true );
 1262+ context.data.selectedWithMouse = false;
12601263 }
12611264 preventDefault = wasVisible;
12621265 break;
@@ -1272,8 +1275,9 @@
12731276 context.data.$container.hide();
12741277 preventDefault = wasVisible;
12751278 selected = context.data.$container.find( '.suggestions-result-current' );
1276 - if ( selected.size() == 0 ) {
1277 - // if nothing is selected, cancel any current requests and submit the form
 1279+ if ( selected.size() == 0 || context.data.selectedWithMouse ) {
 1280+ // if nothing is selected OR if something was selected with the mouse,
 1281+ // cancel any current requests and submit the form
12781282 $.suggestions.cancel( context );
12791283 context.config.$region.closest( 'form' ).submit();
12801284 } else if ( selected.is( '.suggestions-special' ) ) {
@@ -1361,7 +1365,8 @@
13621366 'visibleResults': 0,
13631367 // Suggestion the last mousedown event occured on
13641368 'mouseDownOn': $( [] ),
1365 - '$textbox': $(this)
 1369+ '$textbox': $(this),
 1370+ 'selectedWithMouse': false
13661371 };
13671372 // Setup the css for positioning the results box
13681373 var newCSS = {
@@ -1423,6 +1428,7 @@
14241429 context.data.$textbox.focus();
14251430 } )
14261431 .mousemove( function( e ) {
 1432+ context.data.selectedWithMouse = true;
14271433 $.suggestions.highlight(
14281434 context, $( e.target ).closest( '.suggestions-special' ), false
14291435 );
@@ -7349,3 +7355,5 @@
73507356
73517357 return cc;
73527358 }
 7359+
 7360+
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -62,7 +62,7 @@
6363 if(delayed){context.data.timerID=setTimeout(maybeFetch,context.config.delay);}else{maybeFetch();}
6464 $.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.data.$textbox.val().length==0){context.data.$container.hide();}else{context.data.$container.show();var newCSS={'top':context.config.$region.offset().top+context.config.$region.outerHeight(),'bottom':'auto','width':context.config.$region.outerWidth(),'height':'auto'}
6565 if(context.config.positionFromLeft){newCSS['left']=context.config.$region.offset().left;newCSS['right']='auto';}else{newCSS['left']='auto';newCSS['right']=$('body').width()-(context.config.$region.offset().left+context.config.$region.outerWidth());}
66 -context.data.$container.css(newCSS);var $results=context.data.$container.children('.suggestions-results');$results.empty();var expWidth=-1;var $autoEllipseMe=$([]);var matchedText=null;for(var i=0;i<context.config.suggestions.length;i++){var text=context.config.suggestions[i];var $result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]).mousemove(function(e){$.suggestions.highlight(context,$(this).closest('.suggestions-results div'),false);}).appendTo($results);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{if(context.config.highlightInput){matchedText=text.substr(0,context.data.prevText.length);}
 66+context.data.$container.css(newCSS);var $results=context.data.$container.children('.suggestions-results');$results.empty();var expWidth=-1;var $autoEllipseMe=$([]);var matchedText=null;for(var i=0;i<context.config.suggestions.length;i++){var text=context.config.suggestions[i];var $result=$('<div />').addClass('suggestions-result').attr('rel',i).data('text',context.config.suggestions[i]).mousemove(function(e){context.data.selectedWithMouse=true;$.suggestions.highlight(context,$(this).closest('.suggestions-results div'),false);}).appendTo($results);if(typeof context.config.result.render=='function'){context.config.result.render.call($result,context.config.suggestions[i]);}else{if(context.config.highlightInput){matchedText=text.substr(0,context.data.prevText.length);}
6767 $result.append($('<span />').css('whiteSpace','nowrap').text(text));var $span=$result.children('span');if($span.outerWidth()>$result.width()&&$span.outerWidth()>expWidth){expWidth=$span.outerWidth();}
6868 $autoEllipseMe=$autoEllipseMe.add($result);}}
6969 if(expWidth>context.data.$container.width()){var maxWidth=context.config.maxExpandFactor*context.data.$textbox.width();context.data.$container.width(Math.min(expWidth,maxWidth));}
@@ -70,19 +70,19 @@
7171 break;case'maxRows':context.config[property]=Math.max(1,Math.min(100,value));break;case'delay':context.config[property]=Math.max(0,Math.min(1200,value));break;case'maxExpandFactor':context.config[property]=Math.max(1,value);break;case'submitOnClick':case'positionFromLeft':case'highlightInput':context.config[property]=value?true:false;break;}},highlight:function(context,result,updateTextbox){var selected=context.data.$container.find('.suggestions-result-current');if(!result.get||selected.get(0)!=result.get(0)){if(result=='prev'){if(selected.is('.suggestions-special')){result=context.data.$container.find('.suggestions-result:last')}else{result=selected.prev();if(selected.length==0){if(context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}else{result=context.data.$container.find('.suggestions-results div:last');}}}}else if(result=='next'){if(selected.length==0){result=context.data.$container.find('.suggestions-results div:first');if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}else{result=selected.next();if(selected.is('.suggestions-special')){result=$([]);}else if(result.length==0&&context.data.$container.find('.suggestions-special').html()!=""){result=context.data.$container.find('.suggestions-special');}}}
7272 selected.removeClass('suggestions-result-current');result.addClass('suggestions-result-current');}
7373 if(updateTextbox){if(result.length==0||result.is('.suggestions-special')){$.suggestions.restore(context);}else{context.data.$textbox.val(result.data('text'));context.data.$textbox.change();}
74 -context.data.$textbox.trigger('change');}},keypress:function(e,context,key){var wasVisible=context.data.$container.is(':visible');var preventDefault=false;switch(key){case 40:if(wasVisible){$.suggestions.highlight(context,'next',true);}else{$.suggestions.update(context,false);}
75 -preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',true);}
76 -preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.size()==0){$.suggestions.cancel(context);context.config.$region.closest('form').submit();}else if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}}
 74+context.data.$textbox.trigger('change');}},keypress:function(e,context,key){var wasVisible=context.data.$container.is(':visible');var preventDefault=false;switch(key){case 40:if(wasVisible){$.suggestions.highlight(context,'next',true);context.data.selectedWithMouse=false;}else{$.suggestions.update(context,false);}
 75+preventDefault=true;break;case 38:if(wasVisible){$.suggestions.highlight(context,'prev',true);context.data.selectedWithMouse=false;}
 76+preventDefault=wasVisible;break;case 27:context.data.$container.hide();$.suggestions.restore(context);$.suggestions.cancel(context);context.data.$textbox.trigger('change');preventDefault=wasVisible;break;case 13:context.data.$container.hide();preventDefault=wasVisible;selected=context.data.$container.find('.suggestions-result-current');if(selected.size()==0||context.data.selectedWithMouse){$.suggestions.cancel(context);context.config.$region.closest('form').submit();}else if(selected.is('.suggestions-special')){if(typeof context.config.special.select=='function'){context.config.special.select.call(selected,context.data.$textbox);}}else{if(typeof context.config.result.select=='function'){$.suggestions.highlight(context,selected,true);context.config.result.select.call(selected,context.data.$textbox);}else{$.suggestions.highlight(context,selected,true);}}
7777 break;default:$.suggestions.update(context,true);break;}
7878 if(preventDefault){e.preventDefault();e.stopImmediatePropagation();}}};$.fn.suggestions=function(){var returnValue=null;var args=arguments;$(this).each(function(){var context=$(this).data('suggestions-context');if(typeof context=='undefined'||context==null){context={config:{'fetch':function(){},'cancel':function(){},'special':{},'result':{},'$region':$(this),'suggestions':[],'maxRows':7,'delay':120,'submitOnClick':false,'maxExpandFactor':3,'positionFromLeft':true,'highlightInput':false}};}
7979 if(args.length>0){if(typeof args[0]=='object'){for(var key in args[0]){$.suggestions.configure(context,key,args[0][key]);}}else if(typeof args[0]=='string'){if(args.length>1){$.suggestions.configure(context,args[0],args[1]);}else if(returnValue==null){returnValue=(args[0]in context.config?undefined:context.config[args[0]]);}}}
80 -if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this)};var newCSS={'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'width':context.data.$textbox.outerWidth(),'display':'none'}
 80+if(typeof context.data=='undefined'){context.data={'timerID':null,'prevText':null,'visibleResults':0,'mouseDownOn':$([]),'$textbox':$(this),'selectedWithMouse':false};var newCSS={'top':Math.round(context.data.$textbox.offset().top+context.data.$textbox.outerHeight()),'width':context.data.$textbox.outerWidth(),'display':'none'}
8181 if(context.config.positionFromLeft){newCSS['left']=context.config.$region.offset().left;newCSS['right']='auto';}else{newCSS['left']='auto';newCSS['right']=$('body').width()-(context.config.$region.offset().left+context.config.$region.outerWidth());}
8282 context.data.$container=$('<div />').css(newCSS).addClass('suggestions').append($('<div />').addClass('suggestions-results').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-results div');}).mouseup(function(e){var $result=$(e.target).closest('.suggestions-results div');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($result.get(0)!=$other.get(0)){return;}
8383 $.suggestions.highlight(context,$result,true);context.data.$container.hide();if(typeof context.config.result.select=='function'){context.config.result.select.call($result,context.data.$textbox);}
8484 context.data.$textbox.focus();})).append($('<div />').addClass('suggestions-special').mousedown(function(e){context.data.mouseDownOn=$(e.target).closest('.suggestions-special');}).mouseup(function(e){var $special=$(e.target).closest('.suggestions-special');var $other=context.data.mouseDownOn;context.data.mouseDownOn=$([]);if($special.get(0)!=$other.get(0)){return;}
8585 context.data.$container.hide();if(typeof context.config.special.select=='function'){context.config.special.select.call($special,context.data.$textbox);}
86 -context.data.$textbox.focus();}).mousemove(function(e){$.suggestions.highlight(context,$(e.target).closest('.suggestions-special'),false);})).appendTo($('body'));$(this).attr('autocomplete','off').keydown(function(e){context.data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;context.data.keypressedCount=0;switch(context.data.keypressed){case 40:e.preventDefault();e.stopImmediatePropagation();break;case 38:case 27:case 13:if(context.data.$container.is(':visible')){e.preventDefault();e.stopImmediatePropagation();}}}).keypress(function(e){context.data.keypressedCount++;$.suggestions.keypress(e,context,context.data.keypressed);}).keyup(function(e){if(context.data.keypressedCount==0){$.suggestions.keypress(e,context,context.data.keypressed);}}).blur(function(){if(context.data.mouseDownOn.length>0){return;}
 86+context.data.$textbox.focus();}).mousemove(function(e){context.data.selectedWithMouse=true;$.suggestions.highlight(context,$(e.target).closest('.suggestions-special'),false);})).appendTo($('body'));$(this).attr('autocomplete','off').keydown(function(e){context.data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;context.data.keypressedCount=0;switch(context.data.keypressed){case 40:e.preventDefault();e.stopImmediatePropagation();break;case 38:case 27:case 13:if(context.data.$container.is(':visible')){e.preventDefault();e.stopImmediatePropagation();}}}).keypress(function(e){context.data.keypressedCount++;$.suggestions.keypress(e,context,context.data.keypressed);}).keyup(function(e){if(context.data.keypressedCount==0){$.suggestions.keypress(e,context,context.data.keypressed);}}).blur(function(){if(context.data.mouseDownOn.length>0){return;}
8787 context.data.$container.hide();$.suggestions.cancel(context);});}
8888 $(this).data('suggestions-context',context);});return returnValue!==null?returnValue:$(this);};})(jQuery);(function($){$.fn.textSelection=function(command,options){var fn={getContents:function(){return this.val();},getSelection:function(){var e=this.get(0);var retval='';if($(e).is(':hidden')){}else if(document.selection&&document.selection.createRange){e.focus();var range=document.selection.createRange();retval=range.text;}else if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);}
8989 return retval;},encapsulateSelection:function(options){return this.each(function(){function checkSelectedText(){if(!selText){selText=options.peri;isSample=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);options.post+=' ';}}

Status & tagging log