r63635 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63634‎ | r63635 | r63636 >
Date:18:10, 12 March 2010
Author:nimishg
Status:ok
Tags:
Comment:
removed debugging, removed 20 char limit on templates being collapsed, removed some overhead code in highlight that is no longer needed for when the user hits 'enter'
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.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -73,19 +73,19 @@
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
7676 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 164 ),
77 - array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 40 ),
 77+ array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 41 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 52 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 21 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 97 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
82 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 52 ),
 82+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 53 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 327 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 328 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 327 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 328 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -204,8 +204,7 @@
205205 var $template = $wrapper.parent( '.wikiEditor-template' );
206206 $template.find( '.wikiEditor-template-name' )
207207 .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } )
208 - .mousedown( function() { return false; } )
209 - .data("keydownHandler", function(){console.log("CARLOS!");});
 208+ .mousedown( function() { return false; } );
210209 $template.find( '.wikiEditor-template-expand' )
211210 .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } )
212211 .mousedown( function() { return false; } );
@@ -581,10 +580,6 @@
582581 }
583582 };
584583
585 - //not collapsing "small" templates
586 - if ( wikitext.length < 20 ) {
587 - collapsible = false;
588 - }
589584 // Whitespace* {{ whitespace* nonwhitespace:
590585 if ( wikitext.match( /\s*{{\s*\S*:/ ) ) {
591586 collapsible = false; // is a parser function
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -176,30 +176,9 @@
177177 // Traverse the iframe DOM, inserting markers where they're needed.
178178 // Store visited markers here so we know which markers should be removed
179179 var visited = [], v = 0;
180 - var purgeStarts = false;
181 - var cBreak = false;
182180 for ( var i = 0; i < markers.length; i++ ) {
183181 // We want to isolate each marker, so we may need to split textNodes
184182 // if a marker starts or ends halfway one.
185 - if(!purgeStarts && ( (markers[i].start + "," + markers[i].type) in context.modules.highlight.markersOldStarts) ){
186 - //start same
187 - oldStarts[markers[i].start+","+markers[i].type] = true;
188 - if(division == 'realchange'){
189 - cBreak = true; //already existed, offsets fine
190 - }
191 - }
192 - else{
193 - //only do this once
194 - if(!purgeStarts){
195 - context.modules.highlight.markersOldStarts = oldStarts;
196 - purgeStarts = true;
197 - if(division == 'realchange'){
198 - cBreak = true; //user is currently typing in something whose begin exists
199 - }
200 - }
201 - context.modules.highlight.markersOldStarts[markers[i].start+","+markers[i].type] = true;
202 - }
203 -
204183 var start = markers[i].start;
205184 var s = context.fn.getOffset( start );
206185 if ( !s ) {
@@ -369,7 +348,7 @@
370349 var ca1 = startNode, ca2 = endNode;
371350 if ( ca1 && ca2 && ca1.parentNode ) {
372351 var anchor = markers[i].getAnchor( ca1, ca2 );
373 - if ( !anchor && !cBreak ) { //cBreak prevents a new span from being created which stops cursor jumps
 352+ if ( !anchor ) {
374353 var commonAncestor = ca1.parentNode;
375354 if ( markers[i].anchor == 'wrap') {
376355 // We have to store things like .parentNode and .nextSibling because
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -8708,30 +8708,9 @@
87098709 // Traverse the iframe DOM, inserting markers where they're needed.
87108710 // Store visited markers here so we know which markers should be removed
87118711 var visited = [], v = 0;
8712 - var purgeStarts = false;
8713 - var cBreak = false;
87148712 for ( var i = 0; i < markers.length; i++ ) {
87158713 // We want to isolate each marker, so we may need to split textNodes
87168714 // if a marker starts or ends halfway one.
8717 - if(!purgeStarts && ( (markers[i].start + "," + markers[i].type) in context.modules.highlight.markersOldStarts) ){
8718 - //start same
8719 - oldStarts[markers[i].start+","+markers[i].type] = true;
8720 - if(division == 'realchange'){
8721 - cBreak = true; //already existed, offsets fine
8722 - }
8723 - }
8724 - else{
8725 - //only do this once
8726 - if(!purgeStarts){
8727 - context.modules.highlight.markersOldStarts = oldStarts;
8728 - purgeStarts = true;
8729 - if(division == 'realchange'){
8730 - cBreak = true; //user is currently typing in something whose begin exists
8731 - }
8732 - }
8733 - context.modules.highlight.markersOldStarts[markers[i].start+","+markers[i].type] = true;
8734 - }
8735 -
87368715 var start = markers[i].start;
87378716 var s = context.fn.getOffset( start );
87388717 if ( !s ) {
@@ -8901,7 +8880,7 @@
89028881 var ca1 = startNode, ca2 = endNode;
89038882 if ( ca1 && ca2 && ca1.parentNode ) {
89048883 var anchor = markers[i].getAnchor( ca1, ca2 );
8905 - if ( !anchor && !cBreak ) { //cBreak prevents a new span from being created which stops cursor jumps
 8884+ if ( !anchor ) {
89068885 var commonAncestor = ca1.parentNode;
89078886 if ( markers[i].anchor == 'wrap') {
89088887 // We have to store things like .parentNode and .nextSibling because
@@ -9478,8 +9457,7 @@
94799458 var $template = $wrapper.parent( '.wikiEditor-template' );
94809459 $template.find( '.wikiEditor-template-name' )
94819460 .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } )
9482 - .mousedown( function() { return false; } )
9483 - .data("keydownHandler", function(){console.log("CARLOS!");});
 9461+ .mousedown( function() { return false; } );
94849462 $template.find( '.wikiEditor-template-expand' )
94859463 .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } )
94869464 .mousedown( function() { return false; } );
@@ -9855,10 +9833,6 @@
98569834 }
98579835 };
98589836
9859 - //not collapsing "small" templates
9860 - if ( wikitext.length < 20 ) {
9861 - collapsible = false;
9862 - }
98639837 // Whitespace* {{ whitespace* nonwhitespace:
98649838 if ( wikitext.match( /\s*{{\s*\S*:/ ) ) {
98659839 collapsible = false; // is a parser function
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -592,10 +592,7 @@
593593 tokenArray.sort(function(a,b){return a.offset-b.offset||a.tokenStart-b.tokenStart;});context.fn.trigger('scan');},mark:function(context,division,tokens){var markers=context.modules.highlight.markers=[];context.fn.trigger('mark');markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});var markersStr='';for(var i=0;i<markers.length;i++){markersStr+=markers[i].start+','+markers[i].end+','+markers[i].type+',';}
594594 if(context.modules.highlight.markersStr==markersStr){return;}
595595 context.modules.highlight.markersStr=markersStr;var oldStarts=[];if(!context.modules.highlight.markersOldStarts){context.modules.highlight.markersOldStarts=[];}
596 -var visited=[],v=0;var purgeStarts=false;var cBreak=false;for(var i=0;i<markers.length;i++){if(!purgeStarts&&((markers[i].start+","+markers[i].type)in context.modules.highlight.markersOldStarts)){oldStarts[markers[i].start+","+markers[i].type]=true;if(division=='realchange'){cBreak=true;}}
597 -else{if(!purgeStarts){context.modules.highlight.markersOldStarts=oldStarts;purgeStarts=true;if(division=='realchange'){cBreak=true;}}
598 -context.modules.highlight.markersOldStarts[markers[i].start+","+markers[i].type]=true;}
599 -var start=markers[i].start;var s=context.fn.getOffset(start);if(!s){continue;}
 596+var visited=[],v=0;for(var i=0;i<markers.length;i++){var start=markers[i].start;var s=context.fn.getOffset(start);if(!s){continue;}
600597 var startNode=s.node;var startDepth=s.depth;while(startNode.nodeName=='BR'||s.offset==startNode.nodeValue.length){start++;s=context.fn.getOffset(start);startNode=s.node;startDepth=s.depth;}
601598 if(s.offset>0&&s.node.nodeName=='#text'){var newStartNode=startNode.splitText(s.offset<s.node.nodeValue.length?s.offset:s.node.nodeValue.length-1);var oldStartNode=startNode;startNode=newStartNode;var subtracted=s.offset;var oldLength=s.length;var oldDepth=s.depth;var j,o;for(j=start-subtracted;j<start;j++){if(j in context.offsets){o=context.offsets[j];o.node=oldStartNode;o.length=subtracted;}}
602599 for(j=start;j<start-subtracted+oldLength;j++){if(j in context.offsets){o=context.offsets[j];o.node=newStartNode;o.offset-=subtracted;o.length-=subtracted;o.lastTextNode=oldStartNode;o.lastTextNodeDepth=oldDepth;}}}
@@ -609,7 +606,7 @@
610607 oldParent.parentNode.removeChild(oldParent);}
611608 lastP=t.inP;}
612609 context.fn.purgeOffsets();}
613 -var ca1=startNode,ca2=endNode;if(ca1&&ca2&&ca1.parentNode){var anchor=markers[i].getAnchor(ca1,ca2);if(!anchor&&!cBreak){var commonAncestor=ca1.parentNode;if(markers[i].anchor=='wrap'){var newNode=ca1.ownerDocument.createElement('span');var nextNode=ca2.nextSibling;var n=ca1;while(n!=nextNode){var ns=n.nextSibling;newNode.appendChild(n);n=ns;}
 610+var ca1=startNode,ca2=endNode;if(ca1&&ca2&&ca1.parentNode){var anchor=markers[i].getAnchor(ca1,ca2);if(!anchor){var commonAncestor=ca1.parentNode;if(markers[i].anchor=='wrap'){var newNode=ca1.ownerDocument.createElement('span');var nextNode=ca2.nextSibling;var n=ca1;while(n!=nextNode){var ns=n.nextSibling;newNode.appendChild(n);n=ns;}
614611 if(nextNode){commonAncestor.insertBefore(newNode,nextNode);}else{commonAncestor.appendChild(newNode);}
615612 anchor=newNode;}else if(markers[i].anchor=='tag'){anchor=commonAncestor;}
616613 $(anchor).data('marker',markers[i]).addClass('wikiEditor-highlight');markers[i].afterWrap(anchor,markers[i]);}else{$(anchor).data('marker',markers[i]);markers[i].onSkip(anchor);}
@@ -650,7 +647,7 @@
651648 if(tokenIndex<tokenArray.length){var beginIndex=tokenIndex;var endIndex=-1;var openTemplates=1;var templatesMatched=false;while(tokenIndex<tokenArray.length-1&&endIndex==-1){tokenIndex++;if(tokenArray[tokenIndex].label=='TEMPLATE_BEGIN'){openTemplates++;}else if(tokenArray[tokenIndex].label=='TEMPLATE_END'){openTemplates--;if(openTemplates==0){endIndex=tokenIndex;}}}
652649 if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,type:'template',anchor:'wrap',afterWrap:function(node){var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if(model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));$.wikiEditor.modules.templateEditor.fn.bindTemplateEvents($(node));}else{$(node).addClass('wikiEditor-template-text');}},beforeUnwrap:function(node){if($(node).parent().hasClass('wikiEditor-template')){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}},onSkip:function(node){if($(node).html()==$(node).data('oldHTML')){return;}
653650 var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if($(node).parent().hasClass('wikiEditor-template')){var $name=$(node).parent().children('.wikiEditor-template-name');if($name.text()!=model.getName()){$name.text(model.getName());}}
654 -if($(node).parent().hasClass('wikiEditor-template')&&!model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}else if(!$(node).parent().hasClass('wikiEditor-template')&&model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));$.wikiEditor.modules.templateEditor.fn.bindTemplateEvents($(node));}},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('span.wikiEditor-template-text')?ca1.parentNode:null;},context:context});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}},keydown:function(context,event){var $evtElem=event.jQueryNode;if($evtElem){if($evtElem.hasClass('wikiEditor-template-name')){switch(event.which){case 37:case 38:case 39:case 40:return true;default:return false;}}else if($evtElem.hasClass('wikiEditor-template-text')){switch(event.which){case 13:context.fn.encapsulateSelection({'pre':'\n','peri':'','post':''});return false;default:return true;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],cfg:{},fn:{create:function(context,config){context.modules.templateEditor={};},wrapTemplate:function($wrapper){var model=$wrapper.data('model');var context=$wrapper.data('marker').context;var $template=$wrapper.wrap('<span class="wikiEditor-template"></span>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed');var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').appendTo($templateName);},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},bindTemplateEvents:function($wrapper){var $template=$wrapper.parent('.wikiEditor-template');$template.find('.wikiEditor-template-name').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;}).data("keydownHandler",function(){console.log("CARLOS!");});$template.find('.wikiEditor-template-expand').click(function(){$.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor($wrapper);return false;}).mousedown(function(){return false;});$template.find('.wikiEditor-template-dialog').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;});},toggleWikiTextEditor:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');context.fn.purgeOffsets();$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('.wikiEditor-template-text').toggleClass('wikiEditor-nodisplay');},createDialog:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\
 651+if($(node).parent().hasClass('wikiEditor-template')&&!model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}else if(!$(node).parent().hasClass('wikiEditor-template')&&model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));$.wikiEditor.modules.templateEditor.fn.bindTemplateEvents($(node));}},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('span.wikiEditor-template-text')?ca1.parentNode:null;},context:context});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}},keydown:function(context,event){var $evtElem=event.jQueryNode;if($evtElem){if($evtElem.hasClass('wikiEditor-template-name')){switch(event.which){case 37:case 38:case 39:case 40:return true;default:return false;}}else if($evtElem.hasClass('wikiEditor-template-text')){switch(event.which){case 13:context.fn.encapsulateSelection({'pre':'\n','peri':'','post':''});return false;default:return true;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],cfg:{},fn:{create:function(context,config){context.modules.templateEditor={};},wrapTemplate:function($wrapper){var model=$wrapper.data('model');var context=$wrapper.data('marker').context;var $template=$wrapper.wrap('<span class="wikiEditor-template"></span>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed');var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').appendTo($templateName);},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},bindTemplateEvents:function($wrapper){var $template=$wrapper.parent('.wikiEditor-template');$template.find('.wikiEditor-template-name').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;});$template.find('.wikiEditor-template-expand').click(function(){$.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor($wrapper);return false;}).mousedown(function(){return false;});$template.find('.wikiEditor-template-dialog').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;});},toggleWikiTextEditor:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');context.fn.purgeOffsets();$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('.wikiEditor-template-text').toggleClass('wikiEditor-nodisplay');},createDialog:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\
655652 <fieldset>\
656653 <div class="wikiEditor-template-dialog-title" />\
657654 <div class="wikiEditor-template-dialog-fields" />\
@@ -671,8 +668,7 @@
672669 this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){if(typeof ranges[i].newVal=='undefined'){newText+=wikitext.substring(ranges[i].begin,ranges[i].end);}else{newText+=ranges[i].newVal;}}
673670 return newText;};this.isCollapsible=function(){return collapsible;}
674671 this.updateRanges=function(){var adjustment=0;for(var i=0;i<ranges.length;i++){ranges[i].begin+=adjustment;if(typeof ranges[i].adjust!='undefined'){adjustment+=ranges[i].adjust();delete ranges[i].adjust;}
675 -ranges[i].end+=adjustment;}};if(wikitext.length<20){collapsible=false;}
676 -if(wikitext.match(/\s*{{\s*\S*:/)){collapsible=false;}
 672+ranges[i].end+=adjustment;}};if(wikitext.match(/\s*{{\s*\S*:/)){collapsible=false;}
677673 var sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);if(endBraces){sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+
678674 sanatizedStr.substring(endBraces.index+2);}
679675 while(sanatizedStr.indexOf('<!')!=-1){startIndex=sanatizedStr.indexOf('<!');endIndex=sanatizedStr.indexOf('-->')+3;if(endIndex<3){break;}

Status & tagging log