r56785 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56784‎ | r56785 | r56786 >
Date:20:54, 22 September 2009
Author:catrope
Status:ok
Tags:
Comment:
UsabilityInitiative: Add delayedBind plugin which generalizes the delayed firing of events. Gonna port NavigableTOC and the suggestions plugin to use this
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/combine.sh (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.delayedBind.js (added) (history)

Diff [purge]

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.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
 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.delayedBind.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/UsabilityInitiative.hooks.php
@@ -60,6 +60,7 @@
6161 array( 'src' => 'js/plugins/jquery.autoEllipse.js', 'version' => 1 ),
6262 array( 'src' => 'js/plugins/jquery.browser.js', 'version' => 3 ),
6363 array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 3 ),
 64+ array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 0 ),
6465 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
6566 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 4 ),
6667 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 10 ),
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.delayedBind.js
@@ -0,0 +1,40 @@
 2+(function( $ ) {
 3+$.fn.extend( {
 4+ /**
 5+ * Bind a callback to an event in a delayed fashion.
 6+ * In detail, this means that the callback will be called a certain
 7+ * time after the event fires, but the timer is reset every time
 8+ * the event fires.
 9+ * @param event Name of the event (string)
 10+ * @param callback Function to call
 11+ * @param timeout Number of milliseconds to wait
 12+ */
 13+ delayedBind: function( event, callback, timeout ) {
 14+ return this.each( function() {
 15+ var that = this;
 16+ $(this).bind( event, function() {
 17+ var timerID = $(this).data( '_delayedBindTimerID-' + event );
 18+ var args = arguments;
 19+ // Cancel the running timer
 20+ if ( typeof timerID != 'undefined' )
 21+ clearTimeout( timerID );
 22+ timerID = setTimeout( function() {
 23+ callback.apply( that, args );
 24+ }, timeout );
 25+ $(this).data( '_delayedBindTimerID-' + event, timerID );
 26+ } );
 27+ } );
 28+ },
 29+
 30+ /**
 31+ * Cancel the timers for delayed events on the selected elements.
 32+ */
 33+ delayedBindCancel: function( event ) {
 34+ return this.each( function() {
 35+ var timerID = $(this).data( '_delayedBindTimerID-' + event );
 36+ if ( typeof timerID != 'undefined' )
 37+ clearTimeout( timerID );
 38+ } );
 39+ }
 40+} );
 41+} )( jQuery );
Property changes on: trunk/extensions/UsabilityInitiative/js/plugins/jquery.delayedBind.js
___________________________________________________________________
Name: svn:eol-style
142 + native
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -275,6 +275,46 @@
276276 }
277277 };
278278
 279+(function( $ ) {
 280+$.fn.extend( {
 281+ /**
 282+ * Bind a callback to an event in a delayed fashion.
 283+ * In detail, this means that the callback will be called a certain
 284+ * time after the event fires, but the timer is reset every time
 285+ * the event fires.
 286+ * @param event Name of the event (string)
 287+ * @param callback Function to call
 288+ * @param timeout Number of milliseconds to wait
 289+ */
 290+ delayedBind: function( event, callback, timeout ) {
 291+ return this.each( function() {
 292+ var that = this;
 293+ $(this).bind( event, function() {
 294+ var timerID = $(this).data( '_delayedBindTimerID-' + event );
 295+ var args = arguments;
 296+ // Cancel the running timer
 297+ if ( typeof timerID != 'undefined' )
 298+ clearTimeout( timerID );
 299+ timerID = setTimeout( function() {
 300+ callback.apply( that, args );
 301+ }, timeout );
 302+ $(this).data( '_delayedBindTimerID-' + event, timerID );
 303+ } );
 304+ } );
 305+ },
 306+
 307+ /**
 308+ * Cancel the timers for delayed events on the selected elements.
 309+ */
 310+ delayedBindCancel: function( event ) {
 311+ return this.each( function() {
 312+ var timerID = $(this).data( '_delayedBindTimerID-' + event );
 313+ if ( typeof timerID != 'undefined' )
 314+ clearTimeout( timerID );
 315+ } );
 316+ }
 317+} );
 318+} )( jQuery );
279319 /**
280320 * Plugin that fills a <select> with namespaces
281321 */
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -18,7 +18,9 @@
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($){$.fn.namespaceSelector=function(defaultNS){if(typeof defaultNS=='undefined')
 22+return cookieValue;}};(function($){$.fn.extend({delayedBind:function(event,callback,timeout){return this.each(function(){var that=this;$(this).bind(event,function(){var timerID=$(this).data('_delayedBindTimerID-'+event);var args=arguments;if(typeof timerID!='undefined')
 23+clearTimeout(timerID);timerID=setTimeout(function(){callback.apply(that,args);},timeout);$(this).data('_delayedBindTimerID-'+event,timerID);});});},delayedBindCancel:function(event){return this.each(function(){var timerID=$(this).data('_delayedBindTimerID-'+event);if(typeof timerID!='undefined')
 24+clearTimeout(timerID);});}});})(jQuery);(function($){$.fn.namespaceSelector=function(defaultNS){if(typeof defaultNS=='undefined')
2325 defaultNS=0;return this.each(function(){for(var id in wgFormattedNamespaces){var opt=$('<option />').attr('value',id).text(wgFormattedNamespaces[id]);if(id==defaultNS)
2426 opt.attr('selected','selected');opt.appendTo($(this));}});};})(jQuery);(function($){$.suggestions={cancel:function(context){if(context.data.timerID!=null){clearTimeout(context.data.timerID);}
2527 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());}}}

Status & tagging log