r61224 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61223‎ | r61224 | r61225 >
Date:23:40, 18 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Got realtime events working again. BTW - You can't depend on the event type of a delayed bind to be similar to that of a normal bind, especially on multiple events.
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
@@ -158,7 +158,7 @@
159159 array(
160160 'src' => 'js/plugins/jquery.wikiEditor.highlight.js',
161161 'class' => 'j.wikiEditor.modules.highlight',
162 - 'version' => 13
 162+ 'version' => 14
163163 ),
164164 array(
165165 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js',
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html
@@ -94,11 +94,11 @@
9595 }
9696 var context = window.parent.jQuery.wikiEditor.instances[get( 'instance' )].data( 'wikiEditor-context' );
9797 $j( document )
98 - .bind( "keyup mouseup paste cut", function( event ) {
99 - context.fn.trigger( "change", event );
 98+ .bind( 'keyup mouseup paste cut', function( event ) {
 99+ context.fn.trigger( 'change', event );
100100 } )
101 - .delayedBind( 250, "keydown keypress keyup mousedown mouseup cut paste", function( event ) {
102 - context.fn.trigger( "delayedChange", event );
 101+ .delayedBind( 250, 'keyup mouseup paste cut', function( event ) {
 102+ context.fn.trigger( 'delayedChange', event );
103103 } );
104104 } );
105105 </script>
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -267,26 +267,12 @@
268268 * processing of events which did not actually change the content of the iframe.
269269 */
270270 'change': function( event ) {
271 - // Event filtering
272 - switch ( event.type ) {
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';
279 - break;
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
285 - event.data.scope = 'division';
286 - break;
287 - // When nothing of interest happened, we can go ahead and move on - nothing to see here
288 - default: break;
289 - }
 271+ event.data.scope = 'division';
290272 return true;
 273+ },
 274+ 'delayedChange': function( event ) {
 275+ // Redirect - since we want the same functionality
 276+ return context.evt.change( event );
291277 }
292278 };
293279
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -12,6 +12,7 @@
1313 */
1414 evt: {
1515 delayedChange: function( context, event ) {
 16+ console.log( event.data.scope );
1617 /*
1718 * Triggered on any of the following events, with the intent on detecting if something was added, deleted or
1819 * replaced due to user action.
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6629,26 +6629,12 @@
66306630 * processing of events which did not actually change the content of the iframe.
66316631 */
66326632 'change': function( event ) {
6633 - // Event filtering
6634 - switch ( event.type ) {
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';
6641 - break;
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
6647 - event.data.scope = 'division';
6648 - break;
6649 - // When nothing of interest happened, we can go ahead and move on - nothing to see here
6650 - default: break;
6651 - }
 6633+ event.data.scope = 'division';
66526634 return true;
 6635+ },
 6636+ 'delayedChange': function( event ) {
 6637+ // Redirect - since we want the same functionality
 6638+ return context.evt.change( event );
66536639 }
66546640 };
66556641
@@ -7299,6 +7285,7 @@
73007286 */
73017287 evt: {
73027288 delayedChange: function( context, event ) {
 7289+ console.log( event.data.scope );
73037290 /*
73047291 * Triggered on any of the following events, with the intent on detecting if something was added, deleted or
73057292 * replaced due to user action.
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -434,8 +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'keyup':event.data.scope='division';break;case'mouseup':case'paste':case'cut':event.data.scope='division';break;default:break;}
439 -return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
 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){event.data.scope='division';return true;},'delayedChange':function(event){return context.evt.change(event);}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
440439 if(typeof event.data=='undefined'){event.data={};}
441440 if(name in context.evt){if(!context.evt[name](event)){return false;}}
442441 for(module in context.modules){if(module in $.wikiEditor.modules&&'evt'in $.wikiEditor.modules[module]&&name in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt[name](context,event);}}},'addButton':function(options){context.$controls.show();context.$buttons.show();return $('<button />').text($.wikiEditor.autoMsg(options,'caption')).click(options.action).appendTo(context.$buttons);},'addView':function(options){function addTab(options){context.$controls.show();context.$tabs.show();return $('<div></div>').attr('rel','wikiEditor-ui-view-'+options.name).addClass(context.view==options.name?'current':null).append($('<a></a>').attr('href','#').click(function(event){context.$ui.find('.wikiEditor-ui-view').hide();context.$ui.find('.'+$(this).parent().attr('rel')).show();context.$tabs.find('div').removeClass('current');$(this).parent().addClass('current');$(this).blur();if('init'in options&&typeof options.init=='function'){options.init(context);}
@@ -475,7 +474,7 @@
476475 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);});}
477476 var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI)
478477 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=='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;}
 478+$(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){console.log(event.data.scope);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;}
480479 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;}
481480 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;}
482481 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