r60122 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60121‎ | r60122 | r60123 >
Date:13:03, 16 December 2009
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Whitespace changes in templateEditor
Modified paths:
  • /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.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -2662,28 +2662,28 @@
26632663 var level = 0;
26642664
26652665 var tokenIndex = 0;
2666 - while( tokenIndex < tokenArray.length ){
2667 - while( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN'){
 2666+ while ( tokenIndex < tokenArray.length ){
 2667+ while ( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN' ) {
26682668 tokenIndex++;
26692669 }
26702670 //open template
2671 - if(tokenIndex < tokenArray.length){
 2671+ if ( tokenIndex < tokenArray.length ) {
26722672 var beginIndex = tokenIndex;
26732673 var endIndex = -1; //no match found
26742674 var openTemplates = 1;
26752675 var templatesMatched = false;
2676 - while(tokenIndex < tokenArray.length && (endIndex == -1) ){
 2676+ while ( tokenIndex < tokenArray.length && endIndex == -1 ) {
26772677 tokenIndex++;
2678 - if(tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN'){
 2678+ if ( tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN' ) {
26792679 openTemplates++;
2680 - } else if(tokenArray[tokenIndex].label == 'TEMPLATE_END') {
 2680+ } else if ( tokenArray[tokenIndex].label == 'TEMPLATE_END' ) {
26812681 openTemplates--;
2682 - if(openTemplates == 0){
 2682+ if ( openTemplates == 0 ) {
26832683 endIndex = tokenIndex;
26842684 } //we can stop looping
26852685 }
26862686 }//while finding template ending
2687 - if(endIndex != -1){
 2687+ if ( endIndex != -1 ) {
26882688 markers.push( {
26892689 start: tokenArray[beginIndex].offset,
26902690 end: tokenArray[endIndex].offset,
@@ -2721,18 +2721,18 @@
27222722 },
27232723 stylize: function( context ) {
27242724 var $templates = context.$content.find( '.wiki-template' );
2725 - $templates.each( function(){
2726 - if ( typeof $( this ).data( 'model' ) != 'undefined' ) {
 2725+ $templates.each( function() {
 2726+ if ( typeof $(this).data( 'model' ) != 'undefined' ) {
27272727 // We have a model, so all this init stuff has already happened
27282728 return;
27292729 }
27302730 // Hide this
2731 - $(this).addClass('wikieditor-nodisplay');
 2731+ $(this).addClass( 'wikieditor-nodisplay' );
27322732 // Build a model for this
2733 - $( this ).data( 'model' , new model( $( this ).text() ) );
2734 - var model = $( this ).data( 'model' );
 2733+ $(this).data( 'model' , new model( $( this ).text() ) );
 2734+ var model = $(this).data( 'model' );
27352735 // Expand
2736 - function expandTemplate($displayDiv){
 2736+ function expandTemplate( $displayDiv ) {
27372737 // Housekeeping
27382738 $displayDiv.removeClass( 'wiki-collapsed-template' );
27392739 $displayDiv.addClass( 'wiki-expanded-template' );
@@ -2740,7 +2740,7 @@
27412741 $displayDiv.text( model.getText() );
27422742 };
27432743 // Collapse
2744 - function collapseTemplate($displayDiv){
 2744+ function collapseTemplate( $displayDiv ) {
27452745 // Housekeeping
27462746 $displayDiv.addClass( 'wiki-collapsed-template' );
27472747 $displayDiv.removeClass( 'wiki-expanded-template' );
@@ -2752,11 +2752,11 @@
27532753 // Let these two know about eachother
27542754 $(this).data( 'display' , $visibleDiv );
27552755 $visibleDiv.data( 'wikitext-node', $(this) );
2756 - $(this).after( $visibleDiv );
 2756+ $(this).after( $visibleDiv );
27572757 // Add click handler
2758 - $visibleDiv.click( function(){
 2758+ $visibleDiv.click( function() {
27592759 // Is collapsed, switch to expand
2760 - if ( $(this).data('mode') == 'collapsed' ) {
 2760+ if ( $(this).data( 'mode' ) == 'collapsed' ) {
27612761 expandTemplate( $(this) );
27622762 } else {
27632763 collapseTemplate( $(this) );
@@ -2933,11 +2933,11 @@
29342934 var sanatizedStr = wikitext.replace( /{{/, " " );
29352935 // Replace end
29362936 endBraces = sanatizedStr.match( /}}\s*$/ );
2937 - sanatizedStr =
2938 - sanatizedStr.substring( 0, endBraces.index ) + " " + sanatizedStr.substring( endBraces.index + 2 );
 2937+ sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " +
 2938+ sanatizedStr.substring( endBraces.index + 2 );
29392939 // Match the open braces we just found with equivalent closing braces note, works for any level of braces
29402940 while ( sanatizedStr.indexOf( '{{' ) != -1 ) {
2941 - startIndex = sanatizedStr.indexOf('{{') + 1;
 2941+ startIndex = sanatizedStr.indexOf( '{{' ) + 1;
29422942 openBraces = 2;
29432943 endIndex = startIndex;
29442944 while ( openBraces > 0 ) {
@@ -2962,7 +2962,7 @@
29632963 doneParsing = true;
29642964 }
29652965 nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ );
2966 - if(nameMatch != undefined){
 2966+ if ( nameMatch != undefined ) {
29672967 ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name
29682968 templateNameIndex = ranges.push( new Range( nameMatch.index,
29692969 nameMatch.index + nameMatch[0].length ) );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -170,7 +170,7 @@
171171 $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0)
172172 $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked'))
173173 $('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var tokenIndex=0;while(tokenIndex<tokenArray.length){while(tokenIndex<tokenArray.length&&tokenArray[tokenIndex].label!='TEMPLATE_BEGIN'){tokenIndex++;}
174 -if(tokenIndex<tokenArray.length){var beginIndex=tokenIndex;var endIndex=-1;var openTemplates=1;var templatesMatched=false;while(tokenIndex<tokenArray.length&&(endIndex==-1)){tokenIndex++;if(tokenArray[tokenIndex].label=='TEMPLATE_BEGIN'){openTemplates++;}else if(tokenArray[tokenIndex].label=='TEMPLATE_END'){openTemplates--;if(openTemplates==0){endIndex=tokenIndex;}}}
 174+if(tokenIndex<tokenArray.length){var beginIndex=tokenIndex;var endIndex=-1;var openTemplates=1;var templatesMatched=false;while(tokenIndex<tokenArray.length&&endIndex==-1){tokenIndex++;if(tokenArray[tokenIndex].label=='TEMPLATE_BEGIN'){openTemplates++;}else if(tokenArray[tokenIndex].label=='TEMPLATE_END'){openTemplates--;if(openTemplates==0){endIndex=tokenIndex;}}}
175175 if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,wrapElement:function(){return $('<div />').addClass('wikiEditor-highlight-template');}});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){context.modules.templateEditor={};},stylize:function(context){var $templates=context.$content.find('.wiki-template');$templates.each(function(){if(typeof $(this).data('model')!='undefined'){return;}
176176 $(this).addClass('wikieditor-nodisplay');$(this).data('model',new model($(this).text()));var model=$(this).data('model');function expandTemplate($displayDiv){$displayDiv.removeClass('wiki-collapsed-template');$displayDiv.addClass('wiki-expanded-template');$displayDiv.data('mode')="expanded";$displayDiv.text(model.getText());};function collapseTemplate($displayDiv){$displayDiv.addClass('wiki-collapsed-template');$displayDiv.removeClass('wiki-expanded-template');$displayDiv.data('mode')="collapsed";$displayDiv.text(model.getName());};var $visibleDiv=$("<div></div>").addClass('wikieditor-noinclude');$(this).data('display',$visibleDiv);$visibleDiv.data('wikitext-node',$(this));$(this).after($visibleDiv);$visibleDiv.click(function(){if($(this).data('mode')=='collapsed'){expandTemplate($(this));}else{collapseTemplate($(this));}});collapseTemplate($visibleDiv);});},model:function(wikitext){function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;}
177177 function Range(begin,end){this.begin=begin;this.end=end;}
@@ -182,7 +182,8 @@
183183 return retVal;};this.getName=function(){if(typeof ranges[templateNameIndex].newVal=='undefined'){return wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}else{return ranges[templateNameIndex].newVal;}};this.setName=function(name){ranges[templateNameIndex].newVal=name;};this.setValue=function(name,value){return getSetValue(name,value,false);};this.getValue=function(name){return getSetValue(name,null,false);};this.getOriginalValue=function(name){return getSetValue(name,null,true);};this.getAllParamNames=function(){return paramsByName;};this.getAllInitialParams=function(){return params;}
184184 this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){if(typeof ranges[i].newVal=='undefined'){wikitext.substring(ranges[i].begin,ranges[i].end);}else{newText+=ranges[i].newVal;}}
185185 return newText;};if(wikitext.match(/\s*{{\s*\S*:/)){}
186 -var sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+sanatizedStr.substring(endBraces.index+2);while(sanatizedStr.indexOf('{{')!=-1){startIndex=sanatizedStr.indexOf('{{')+1;openBraces=2;endIndex=startIndex;while(openBraces>0){var brace=sanatizedStr[++endIndex];openBraces+=brace=='}'?-1:brace=='{'?1:0;}
 186+var sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+
 187+sanatizedStr.substring(endBraces.index+2);while(sanatizedStr.indexOf('{{')!=-1){startIndex=sanatizedStr.indexOf('{{')+1;openBraces=2;endIndex=startIndex;while(openBraces>0){var brace=sanatizedStr[++endIndex];openBraces+=brace=='}'?-1:brace=='{'?1:0;}
187188 sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[{}|=]/g,'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+sanatizedSegment+sanatizedStr.substring(endIndex);}
188189 var ranges=[];var params=[];var templateNameIndex=0;var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;}
189190 nameMatch=wikitext.substring(oldDivider,divider).match(/[^{\s]+/);if(nameMatch!=undefined){ranges.push(new Range(oldDivider,nameMatch.index));templateNameIndex=ranges.push(new Range(nameMatch.index,nameMatch.index+nameMatch[0].length));templateNameIndex--;ranges[templateNameIndex].old=wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -13,28 +13,28 @@
1414 var level = 0;
1515
1616 var tokenIndex = 0;
17 - while( tokenIndex < tokenArray.length ){
18 - while( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN'){
 17+ while ( tokenIndex < tokenArray.length ){
 18+ while ( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN' ) {
1919 tokenIndex++;
2020 }
2121 //open template
22 - if(tokenIndex < tokenArray.length){
 22+ if ( tokenIndex < tokenArray.length ) {
2323 var beginIndex = tokenIndex;
2424 var endIndex = -1; //no match found
2525 var openTemplates = 1;
2626 var templatesMatched = false;
27 - while(tokenIndex < tokenArray.length && (endIndex == -1) ){
 27+ while ( tokenIndex < tokenArray.length && endIndex == -1 ) {
2828 tokenIndex++;
29 - if(tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN'){
 29+ if ( tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN' ) {
3030 openTemplates++;
31 - } else if(tokenArray[tokenIndex].label == 'TEMPLATE_END') {
 31+ } else if ( tokenArray[tokenIndex].label == 'TEMPLATE_END' ) {
3232 openTemplates--;
33 - if(openTemplates == 0){
 33+ if ( openTemplates == 0 ) {
3434 endIndex = tokenIndex;
3535 } //we can stop looping
3636 }
3737 }//while finding template ending
38 - if(endIndex != -1){
 38+ if ( endIndex != -1 ) {
3939 markers.push( {
4040 start: tokenArray[beginIndex].offset,
4141 end: tokenArray[endIndex].offset,
@@ -72,18 +72,18 @@
7373 },
7474 stylize: function( context ) {
7575 var $templates = context.$content.find( '.wiki-template' );
76 - $templates.each( function(){
77 - if ( typeof $( this ).data( 'model' ) != 'undefined' ) {
 76+ $templates.each( function() {
 77+ if ( typeof $(this).data( 'model' ) != 'undefined' ) {
7878 // We have a model, so all this init stuff has already happened
7979 return;
8080 }
8181 // Hide this
82 - $(this).addClass('wikieditor-nodisplay');
 82+ $(this).addClass( 'wikieditor-nodisplay' );
8383 // Build a model for this
84 - $( this ).data( 'model' , new model( $( this ).text() ) );
85 - var model = $( this ).data( 'model' );
 84+ $(this).data( 'model' , new model( $( this ).text() ) );
 85+ var model = $(this).data( 'model' );
8686 // Expand
87 - function expandTemplate($displayDiv){
 87+ function expandTemplate( $displayDiv ) {
8888 // Housekeeping
8989 $displayDiv.removeClass( 'wiki-collapsed-template' );
9090 $displayDiv.addClass( 'wiki-expanded-template' );
@@ -91,7 +91,7 @@
9292 $displayDiv.text( model.getText() );
9393 };
9494 // Collapse
95 - function collapseTemplate($displayDiv){
 95+ function collapseTemplate( $displayDiv ) {
9696 // Housekeeping
9797 $displayDiv.addClass( 'wiki-collapsed-template' );
9898 $displayDiv.removeClass( 'wiki-expanded-template' );
@@ -103,11 +103,11 @@
104104 // Let these two know about eachother
105105 $(this).data( 'display' , $visibleDiv );
106106 $visibleDiv.data( 'wikitext-node', $(this) );
107 - $(this).after( $visibleDiv );
 107+ $(this).after( $visibleDiv );
108108 // Add click handler
109 - $visibleDiv.click( function(){
 109+ $visibleDiv.click( function() {
110110 // Is collapsed, switch to expand
111 - if ( $(this).data('mode') == 'collapsed' ) {
 111+ if ( $(this).data( 'mode' ) == 'collapsed' ) {
112112 expandTemplate( $(this) );
113113 } else {
114114 collapseTemplate( $(this) );
@@ -284,11 +284,11 @@
285285 var sanatizedStr = wikitext.replace( /{{/, " " );
286286 // Replace end
287287 endBraces = sanatizedStr.match( /}}\s*$/ );
288 - sanatizedStr =
289 - sanatizedStr.substring( 0, endBraces.index ) + " " + sanatizedStr.substring( endBraces.index + 2 );
 288+ sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " +
 289+ sanatizedStr.substring( endBraces.index + 2 );
290290 // Match the open braces we just found with equivalent closing braces note, works for any level of braces
291291 while ( sanatizedStr.indexOf( '{{' ) != -1 ) {
292 - startIndex = sanatizedStr.indexOf('{{') + 1;
 292+ startIndex = sanatizedStr.indexOf( '{{' ) + 1;
293293 openBraces = 2;
294294 endIndex = startIndex;
295295 while ( openBraces > 0 ) {
@@ -313,7 +313,7 @@
314314 doneParsing = true;
315315 }
316316 nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ );
317 - if(nameMatch != undefined){
 317+ if ( nameMatch != undefined ) {
318318 ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name
319319 templateNameIndex = ranges.push( new Range( nameMatch.index,
320320 nameMatch.index + nameMatch[0].length ) );

Status & tagging log