r61614 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61613‎ | r61614 | r61615 >
Date:23:18, 27 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Optimized the TOC by building and comparing hashes of the outline to prevent any further processing or DOM manipulation when no changes have been made.
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.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -76,16 +76,16 @@
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 25 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ),
80 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 74 ),
 80+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 75 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 10 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 16 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 189 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 190 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 189 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 190 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -73,6 +73,7 @@
7474 context.modules.toc.$toc.data( 'previousWidth', context.$wikitext.width() );
7575 },
7676 mark: function( context, event ) {
 77+ var hash = '';
7778 var markers = context.modules.highlight.markers;
7879 var tokenArray = context.modules.highlight.tokenArray;
7980 var outline = context.data.outline = [];
@@ -105,14 +106,20 @@
106107 ca1.previousSibling : null;
107108 }
108109 } );
 110+ hash += tokenArray[i].match[2] + '\n';
109111 outline.push ( {
110112 'text': tokenArray[i].match[2],
111113 'level': tokenArray[i].match[1].length,
112114 'index': h
113115 } );
114116 }
115 - $.wikiEditor.modules.toc.fn.build( context );
116 - $.wikiEditor.modules.toc.fn.update( context );
 117+ // Only update the TOC if it's been changed - we do this by comparing a hash of the headings this time to last
 118+ if ( typeof context.modules.toc.lastHash == 'undefined' || context.modules.toc.lastHash !== hash ) {
 119+ $.wikiEditor.modules.toc.fn.build( context );
 120+ $.wikiEditor.modules.toc.fn.update( context );
 121+ // Remember the changed version
 122+ context.modules.toc.lastHash = hash;
 123+ }
117124 }
118125 },
119126 exp: [
@@ -488,7 +495,9 @@
489496 if( ui.size.width <= parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) {
490497 context.modules.toc.$toc.trigger( 'collapse.wikiEditor-toc' );
491498 } else {
492 - context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true, 'restoreText': true } );
 499+ context.modules.toc.$toc.find( 'div' ).autoEllipsis(
 500+ { 'position': 'right', 'tooltip': true, 'restoreText': true }
 501+ );
493502 context.modules.toc.$toc.data( 'openWidth', ui.size.width );
494503 $.cookie( 'wikiEditor-' + context.instance + '-toc-width', ui.size.width );
495504 }
@@ -552,7 +561,9 @@
553562 buildResizeControls();
554563 buildCollapseControls();
555564 }
556 - context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true, 'restoreText': true } );
 565+ context.modules.toc.$toc.find( 'div' ).autoEllipsis(
 566+ { 'position': 'right', 'tooltip': true, 'restoreText': true }
 567+ );
557568 }
558569 }
559570 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6793,7 +6793,7 @@
67946794 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
67956795 .replace( /\<p[^\>]*\>/gi, "\n" ) // IE uses </p><p> for user-inserted line breaks
67966796 .replace( /\<\/p[^\>]*\>/gi, "" )
6797 - .replace( /\<div[^\>]*\>/gi, "\n" ) // Webkit uses </p><p> for user-inserted line breaks
 6797+ .replace( /\<div[^\>]*\>/gi, "\n" ) // Webkit uses </div><div> for user-inserted line breaks
67986798 .replace( /\<\/div[^\>]*\>/gi, "" )
67996799 + '</pre>' );
68006800 // Get rid of the noincludes when getting text
@@ -8822,6 +8822,7 @@
88238823 context.modules.toc.$toc.data( 'previousWidth', context.$wikitext.width() );
88248824 },
88258825 mark: function( context, event ) {
 8826+ var hash = '';
88268827 var markers = context.modules.highlight.markers;
88278828 var tokenArray = context.modules.highlight.tokenArray;
88288829 var outline = context.data.outline = [];
@@ -8854,14 +8855,20 @@
88558856 ca1.previousSibling : null;
88568857 }
88578858 } );
 8859+ hash += tokenArray[i].match[2] + '\n';
88588860 outline.push ( {
88598861 'text': tokenArray[i].match[2],
88608862 'level': tokenArray[i].match[1].length,
88618863 'index': h
88628864 } );
88638865 }
8864 - $.wikiEditor.modules.toc.fn.build( context );
8865 - $.wikiEditor.modules.toc.fn.update( context );
 8866+ // Only update the TOC if it's been changed - we do this by comparing a hash of the headings this time to last
 8867+ if ( typeof context.modules.toc.lastHash == 'undefined' || context.modules.toc.lastHash !== hash ) {
 8868+ $.wikiEditor.modules.toc.fn.build( context );
 8869+ $.wikiEditor.modules.toc.fn.update( context );
 8870+ // Remember the changed version
 8871+ context.modules.toc.lastHash = hash;
 8872+ }
88668873 }
88678874 },
88688875 exp: [
@@ -9237,7 +9244,9 @@
92389245 if( ui.size.width <= parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) {
92399246 context.modules.toc.$toc.trigger( 'collapse.wikiEditor-toc' );
92409247 } else {
9241 - context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true, 'restoreText': true } );
 9248+ context.modules.toc.$toc.find( 'div' ).autoEllipsis(
 9249+ { 'position': 'right', 'tooltip': true, 'restoreText': true }
 9250+ );
92429251 context.modules.toc.$toc.data( 'openWidth', ui.size.width );
92439252 $.cookie( 'wikiEditor-' + context.instance + '-toc-width', ui.size.width );
92449253 }
@@ -9301,7 +9310,9 @@
93029311 buildResizeControls();
93039312 buildCollapseControls();
93049313 }
9305 - context.modules.toc.$toc.find( 'div' ).autoEllipsis( { 'position': 'right', 'tooltip': true, 'restoreText': true } );
 9314+ context.modules.toc.$toc.find( 'div' ).autoEllipsis(
 9315+ { 'position': 'right', 'tooltip': true, 'restoreText': true }
 9316+ );
93069317 }
93079318 }
93089319 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -594,9 +594,9 @@
595595 if(context.modules.toc.$toc.data('positionMode')=='goofy'){context.modules.toc.$toc.find('div').autoEllipsis({'position':'right','tooltip':true,'restoreText':true});}
596596 if(!context.modules.toc.$toc.data('collapsed')){context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height()-
597597 context.$ui.find('.tab-toc').outerHeight());}
598 -context.modules.toc.$toc.data('previousWidth',context.$wikitext.width());},mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var outline=context.data.outline=[];var h=0;for(var i=0;i<tokenArray.length;i++){if(tokenArray[i].label!='TOC_HEADER'){continue;}
599 -h++;markers.push({index:h,start:tokenArray[i].tokenStart,end:tokenArray[i].offset,anchor:'before',afterWrap:function(node){var marker=$(node).data('marker');$(node).addClass('wikiEditor-toc-header').addClass('wikiEditor-toc-section-'+marker.index).data('section',marker.index);},onSkip:function(node){var marker=$(node).data('marker');$(node).removeClass('wikiEditor-toc-section-'+$(node).data('section')).addClass('wikiEditor-toc-section-'+marker.index).data('section',marker.index);},getAnchor:function(ca1,ca2){return $(ca1.previousSibling).is('div.wikiEditor-toc-header')?ca1.previousSibling:null;}});outline.push({'text':tokenArray[i].match[2],'level':tokenArray[i].match[1].length,'index':h});}
600 -$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}},exp:[{'regex':/^(={1,6})([^\r\n]+?)\1\s*$/m,'label':'TOC_HEADER','markAfter':true}],fn:{create:function(context,config){if('$toc'in context.modules.toc){return;}
 598+context.modules.toc.$toc.data('previousWidth',context.$wikitext.width());},mark:function(context,event){var hash='';var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var outline=context.data.outline=[];var h=0;for(var i=0;i<tokenArray.length;i++){if(tokenArray[i].label!='TOC_HEADER'){continue;}
 599+h++;markers.push({index:h,start:tokenArray[i].tokenStart,end:tokenArray[i].offset,anchor:'before',afterWrap:function(node){var marker=$(node).data('marker');$(node).addClass('wikiEditor-toc-header').addClass('wikiEditor-toc-section-'+marker.index).data('section',marker.index);},onSkip:function(node){var marker=$(node).data('marker');$(node).removeClass('wikiEditor-toc-section-'+$(node).data('section')).addClass('wikiEditor-toc-section-'+marker.index).data('section',marker.index);},getAnchor:function(ca1,ca2){return $(ca1.previousSibling).is('div.wikiEditor-toc-header')?ca1.previousSibling:null;}});hash+=tokenArray[i].match[2]+'\n';outline.push({'text':tokenArray[i].match[2],'level':tokenArray[i].match[1].length,'index':h});}
 600+if(typeof context.modules.toc.lastHash=='undefined'||context.modules.toc.lastHash!==hash){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);context.modules.toc.lastHash=hash;}}},exp:[{'regex':/^(={1,6})([^\r\n]+?)\1\s*$/m,'label':'TOC_HEADER','markAfter':true}],fn:{create:function(context,config){if('$toc'in context.modules.toc){return;}
601601 $.wikiEditor.modules.toc.cfg.rtl=config.rtl;var height=context.$ui.find('.wikiEditor-ui-left').height();context.modules.toc.$toc=$('<div />').addClass('wikiEditor-ui-toc').data('context',context).data('positionMode','regular').data('collapsed',false);context.$ui.find('.wikiEditor-ui-right').append(context.modules.toc.$toc);context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height());$.wikiEditor.modules.toc.fn.redraw(context,$.wikiEditor.modules.toc.cfg.defaultWidth);},redraw:function(context,fixedWidth){var fixedWidth=parseFloat(fixedWidth);if(context.modules.toc.$toc.data('positionMode')=='regular'){context.$ui.find('.wikiEditor-ui-right').css('width',fixedWidth+'px');context.$ui.find('.wikiEditor-ui-left').css('marginRight',(-1*fixedWidth)+'px').children().css('marginRight',fixedWidth+'px');}else if(context.modules.toc.$toc.data('positionMode')=='goofy'){context.$ui.find('.wikiEditor-ui-left').css('width',fixedWidth);context.$ui.find('.wikiEditor-ui-right').css($.wikiEditor.modules.toc.cfg.rtl?'right':'left',fixedWidth);context.$wikitext.css('height',context.$ui.find('.wikiEditor-ui-right').height());}},switchLayout:function(context){var width,height=context.$ui.find('.wikiEditor-ui-right').height();if(context.modules.toc.$toc.data('positionMode')=='regular'&&!context.modules.toc.$toc.data('collapsed')){context.modules.toc.$toc.data('positionMode','goofy');context.modules.toc.$toc.data('positionModeChangeAt',context.$ui.find('.wikiEditor-ui-right').width());width=$.wikiEditor.modules.toc.cfg.textMinimumWidth;context.$ui.find('.wikiEditor-ui-left').css({'marginRight':'','position':'absolute','float':'none','left':$.wikiEditor.modules.toc.cfg.rtl?'auto':0,'right':$.wikiEditor.modules.toc.cfg.rtl?0:'auto'}).children().css('marginRight','');context.$ui.find('.wikiEditor-ui-right').css({'width':'auto','position':'absolute','float':'none','right':$.wikiEditor.modules.toc.cfg.rtl?'auto':0,'left':$.wikiEditor.modules.toc.cfg.rtl?0:'auto'});context.$wikitext.css('position','relative');}else if(context.modules.toc.$toc.data('positionMode')=='goofy'){context.modules.toc.$toc.data('positionMode','regular');width=context.$wikitext.width()-context.$ui.find('.wikiEditor-ui-left').width();if(width>context.modules.toc.$toc.data('positionModeChangeAt')){width=context.modules.toc.$toc.data('positionModeChangeAt');}
602602 context.$wikitext.css({'position':'','height':''});context.$ui.find('.wikiEditor-ui-right').css({'marginRight':'','position':'','left':'','right':'','float':'','top':'','height':''});context.$ui.find('.wikiEditor-ui-left').css({'width':'','position':'','left':'','float':'','right':''});}
603603 $.wikiEditor.modules.toc.fn.redraw(context,width);},disable:function(context){if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').hide();}else{if(context.modules.toc.$toc.data('positionMode')=='goofy'){$.wikiEditor.modules.toc.fn.switchLayout(context);}

Status & tagging log