r61221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61220‎ | r61221 | r61222 >
Date:22:59, 18 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Turned the real-time highlighting back on, cleaned up some of the code in that particular calling chain, and removed some old commented out junk.
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.wikiEditor.highlight.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -153,12 +153,12 @@
154154 array(
155155 'src' => 'js/plugins/jquery.wikiEditor.js',
156156 'class' => 'j.wikiEditor',
157 - 'version' => 48
 157+ 'version' => 49
158158 ),
159159 array(
160160 'src' => 'js/plugins/jquery.wikiEditor.highlight.js',
161161 'class' => 'j.wikiEditor.modules.highlight',
162 - 'version' => 12
 162+ 'version' => 13
163163 ),
164164 array(
165165 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js',
@@ -191,10 +191,10 @@
192192 'version' => 1 ),
193193 ),
194194 'combined' => array(
195 - array( 'src' => 'js/plugins.combined.js', 'version' => 148 ),
 195+ array( 'src' => 'js/plugins.combined.js', 'version' => 149 ),
196196 ),
197197 'minified' => array(
198 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 148 ),
 198+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 149 ),
199199 ),
200200 ),
201201 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html
@@ -94,7 +94,7 @@
9595 }
9696 var context = window.parent.jQuery.wikiEditor.instances[get( 'instance' )].data( 'wikiEditor-context' );
9797 $j( document )
98 - .bind( "keydown keypress keyup mousedown mouseup cut paste", function( event ) {
 98+ .bind( "keyup mouseup paste cut", function( event ) {
9999 context.fn.trigger( "change", event );
100100 } )
101101 .delayedBind( 250, "keydown keypress keyup mousedown mouseup cut paste", function( event ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -269,23 +269,22 @@
270270 'change': function( event ) {
271271 // Event filtering
272272 switch ( event.type ) {
273 - case 'keypress':
274 - if ( /* TODO: test if something interesting was deleted */ true ) {
275 - event.data.scope = 'keydown';
276 - } else {
277 - event.data.scope = 'character';
278 - }
 273+ // We are looking for characters being inserted and deleted one at a time here, and keyp happens after a
 274+ // key has already been pressed and proceesed - it also works the same on all browsers
 275+ case 'keyup':
 276+ // TODO: Test if something was deleted, because if nothing was deleted, we can go with a less
 277+ // resource intensive character level event scope - like: "event.data.scope = 'character'"
 278+ event.data.scope = 'division';
279279 break;
280 - case 'mousedown': // FIXME: mouseup?
281 - if ( /* TODO: test if text was dragged and dropped */ true ) {
282 - event.data.scope = 'division';
283 - } else {
284 - return false;
285 - }
286 - break;
287 - default:
 280+ // Here we are looking for the user dragging and dropping content around or cutting and pasting
 281+ case 'mouseup':
 282+ case 'paste':
 283+ case 'cut':
 284+ // TODO: Verify our suspicion that something really did change
288285 event.data.scope = 'division';
289286 break;
 287+ // When nothing of interest happened, we can go ahead and move on - nothing to see here
 288+ default: break;
290289 }
291290 return true;
292291 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -34,26 +34,13 @@
3535 * ; Definition
3636 * : Definition
3737 */
38 - if ( event.data.scope == 'none' ) {
 38+ if ( event.data.scope == 'division' ) {
3939 $.wikiEditor.modules.highlight.fn.scan( context, "" );
4040 $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
4141 }
4242 },
4343 ready: function( context, event ) {
44 - /*
45 - // Add our CSS to the iframe
46 - // Style version for wikiEditor.highlight.css is here
47 - // FIXME: That's not ideal
48 - context.$content.parent().find( 'head' ).append( $j( '<link />' ).attr( {
49 - 'rel': 'stylesheet',
50 - 'type': 'text/css',
51 - 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css?' +
52 - $.wikiEditor.modules.highlight.cfg.styleVersion,
53 - } ) );
54 - */
5544 // Highlight stuff for the first time
56 -
57 -
5845 $.wikiEditor.modules.highlight.fn.scan( context, "" );
5946 $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
6047 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6631,23 +6631,22 @@
66326632 'change': function( event ) {
66336633 // Event filtering
66346634 switch ( event.type ) {
6635 - case 'keypress':
6636 - if ( /* TODO: test if something interesting was deleted */ true ) {
6637 - event.data.scope = 'keydown';
6638 - } else {
6639 - event.data.scope = 'character';
6640 - }
 6635+ // We are looking for characters being inserted and deleted one at a time here, and keyp happens after a
 6636+ // key has already been pressed and proceesed - it also works the same on all browsers
 6637+ case 'keyup':
 6638+ // TODO: Test if something was deleted, because if nothing was deleted, we can go with a less
 6639+ // resource intensive character level event scope - like: "event.data.scope = 'character'"
 6640+ event.data.scope = 'division';
66416641 break;
6642 - case 'mousedown': // FIXME: mouseup?
6643 - if ( /* TODO: test if text was dragged and dropped */ true ) {
6644 - event.data.scope = 'division';
6645 - } else {
6646 - return false;
6647 - }
6648 - break;
6649 - default:
 6642+ // Here we are looking for the user dragging and dropping content around or cutting and pasting
 6643+ case 'mouseup':
 6644+ case 'paste':
 6645+ case 'cut':
 6646+ // TODO: Verify our suspicion that something really did change
66506647 event.data.scope = 'division';
66516648 break;
 6649+ // When nothing of interest happened, we can go ahead and move on - nothing to see here
 6650+ default: break;
66526651 }
66536652 return true;
66546653 }
@@ -7294,26 +7293,13 @@
72957294 * ; Definition
72967295 * : Definition
72977296 */
7298 - if ( event.data.scope == 'none' ) {
 7297+ if ( event.data.scope == 'division' ) {
72997298 $.wikiEditor.modules.highlight.fn.scan( context, "" );
73007299 $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
73017300 }
73027301 },
73037302 ready: function( context, event ) {
7304 - /*
7305 - // Add our CSS to the iframe
7306 - // Style version for wikiEditor.highlight.css is here
7307 - // FIXME: That's not ideal
7308 - context.$content.parent().find( 'head' ).append( $j( '<link />' ).attr( {
7309 - 'rel': 'stylesheet',
7310 - 'type': 'text/css',
7311 - 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css?' +
7312 - $.wikiEditor.modules.highlight.cfg.styleVersion,
7313 - } ) );
7314 - */
73157303 // Highlight stuff for the first time
7316 -
7317 -
73187304 $.wikiEditor.modules.highlight.fn.scan( context, "" );
73197305 $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
73207306 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -434,9 +434,7 @@
435435 return src+'?'+wgWikiEditorIconVersion;}};$.fn.wikiEditor=function(){if(!$j.wikiEditor.isSupported()){return $(this);}
436436 var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':$.wikiEditor.instances.push($(this))-1};context.api={'addModule':function(context,data){var modules={};if(typeof data=='string'){modules[data]={};}else if(typeof data=='object'){modules=data;}
437437 for(module in modules){if(typeof module=='string'&&module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}
438 -if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'change':function(event){switch(event.type){case'keypress':if(true){event.data.scope='keydown';}else{event.data.scope='character';}
439 -break;case'mousedown':if(true){event.data.scope='division';}else{return false;}
440 -break;default:event.data.scope='division';break;}
 438+if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'change':function(event){switch(event.type){case'keyup':event.data.scope='division';break;case'mouseup':case'paste':case'cut':event.data.scope='division';break;default:break;}
441439 return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
442440 if(typeof event.data=='undefined'){event.data={};}
443441 if(name in context.evt){if(!context.evt[name](event)){return false;}}
@@ -475,7 +473,7 @@
476474 configuration.newButtons[gM(msg)]=configuration.buttons[msg];configuration.buttons=configuration.newButtons;var dialogDiv=$('<div /> ').attr('id',module.id).html(module.html).data('context',context).appendTo($('body')).each(module.init).dialog(configuration);if(!('resizeme'in module)||module.resizeme){dialogDiv.bind('dialogopen',$.wikiEditor.modules.dialogs.fn.resize).find('.ui-tabs').bind('tabsshow',function(){$(this).closest('.ui-dialog-content').each($.wikiEditor.modules.dialogs.fn.resize);});}
477475 var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
478476 maxTI=ti;});var tabIndex=maxTI+1;$j('.ui-dialog input, .ui-dialog button').not('[tabindex]').each(function(){$j(this).attr('tabindex',tabIndex++);});}}});},resize:function(){var wrapper=$(this).closest('.ui-dialog');var oldWidth=wrapper.width();var oldHidden=$(this).find('*').not(':visible');oldHidden.each(function(){$(this).data('oldstyle',$(this).attr('style'));});oldHidden.show();var oldWS=$(this).css('white-space');$(this).css('white-space','nowrap');if(wrapper.width()<=$(this).get(0).scrollWidth){var thisWidth=$(this).data('thisWidth')?$(this).data('thisWidth'):0;thisWidth=Math.max($(this).get(0).scrollWidth,thisWidth);$(this).width(thisWidth);$(this).data('thisWidth',thisWidth);var wrapperWidth=$(this).data('wrapperWidth')?$(this).data('wrapperWidth'):0;wrapperWidth=Math.max(wrapper.get(0).scrollWidth,wrapperWidth);wrapper.width(wrapperWidth);$(this).data('wrapperWidth',wrapperWidth);$(this).dialog({'width':wrapper.width()});wrapper.css('left',parseInt(wrapper.css('left'))-(wrapper.width()-oldWidth)/2);}
479 -$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={cfg:{'styleVersion':3},evt:{delayedChange:function(context,event){if(event.data.scope=='none'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},ready:function(context,event){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},scan:function(context,division){function Token(offset,label,tokenStart,match){this.offset=offset;this.label=label;this.tokenStart=tokenStart;this.match=match;}
 477+$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={cfg:{'styleVersion':3},evt:{delayedChange:function(context,event){if(event.data.scope=='division'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},ready:function(context,event){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},scan:function(context,division){function Token(offset,label,tokenStart,match){this.offset=offset;this.label=label;this.tokenStart=tokenStart;this.match=match;}
480478 var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;}
481479 match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;var tokenStart=match.index+oldOffset+markOffset;if(markAfter){markOffset+=match[0].length;}
482480 tokenArray.push(new Token(match.index+oldOffset+markOffset,label,tokenStart,match));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}}

Status & tagging log