r63141 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63140‎ | r63141 | r63142 >
Date:22:34, 1 March 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Some performance improvements
* Don't collapse templates in the template namespace. Probably gonna be ridiculously slow and not useful anyway
* Only regenerate model when the text has changed rather than on every delayedChange event
* Recycle rows in template dialog rather than destroying everything and building it anew
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.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -78,14 +78,14 @@
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 19 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 96 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
82 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 30 ),
 82+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 31 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 297 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 298 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 297 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 298 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -28,6 +28,10 @@
2929 */
3030 evt: {
3131 mark: function( context, event ) {
 32+ if ( $( 'body' ).hasClass( 'ns-10' ) ) {
 33+ // We're in the template namespace, don't collapse any templates
 34+ return;
 35+ }
3236 // Get references to the markers and tokens from the current context
3337 var markers = context.modules.highlight.markers;
3438 var tokenArray = context.modules.highlight.tokenArray;
@@ -57,13 +61,6 @@
5862 }
5963 }//while finding template ending
6064 if ( endIndex != -1 ) {
61 - // Create a model for the template
62 - // FIXME: This is a performance hit
63 - var model = new $.wikiEditor.modules.templateEditor.fn.model(
64 - context.fn.getContents().substring( tokenArray[beginIndex].offset,
65 - tokenArray[endIndex].offset
66 - )
67 - );
6865 markers.push( {
6966 start: tokenArray[beginIndex].offset,
7067 end: tokenArray[endIndex].offset,
@@ -72,9 +69,12 @@
7370 //splitPs: model.isCollapsible(),
7471 splitPs: false,
7572 afterWrap: function( node ) {
76 - // Store model so we can compare it later
77 - $( node ).data( 'model', $( node ).data( 'marker' ).model );
78 - if ( $( node ).data( 'model' ).isCollapsible() ) {
 73+ // Generate model
 74+ var model = new $.wikiEditor.modules.templateEditor.fn.model(
 75+ $( node ).text()
 76+ );
 77+ $( node ).data( 'model', model );
 78+ if ( model.isCollapsible() ) {
7979 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
8080 } else {
8181 $( node ).addClass( 'wikiEditor-template-text' );
@@ -86,26 +86,28 @@
8787 }
8888 },
8989 onSkip: function( node ) {
90 - var oldModel = $( node ).data( 'model' );
91 - var newModel = $( node ).data( 'marker' ).model;
92 - if ( oldModel.getText() == newModel.getText() ) {
 90+ if ( $( node ).data( 'model' ).getText() == $( node ).text() ) {
9391 // No change
9492 return;
9593 }
 94+ // Text changed, regenerate model
 95+ var model = new $.wikiEditor.modules.templateEditor.fn.model(
 96+ $( node ).text()
 97+ );
 98+ $( node ).data( 'model', model );
9699
97 - if ( $( node ).parent().hasClass( 'wikiEditor-template' ) && !newModel.isCollapsible() ) {
 100+ if ( $( node ).parent().hasClass( 'wikiEditor-template' ) &&
 101+ !model.isCollapsible() ) {
98102 $.wikiEditor.modules.templateEditor.fn.unwrapTemplate( $( node ) );
99 - } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) && newModel.isCollapsible() ) {
 103+ } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) &&
 104+ model.isCollapsible() ) {
100105 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
101106 }
102 - // TODO: Update table; not doing this yet because the table will probably die
103107 },
104108 getAnchor: function( ca1, ca2 ) {
105 - // FIXME: Relies on the current <span> structure that is likely to die
106109 return $( ca1.parentNode ).is( 'span.wikiEditor-template-text' ) ?
107110 ca1.parentNode : null;
108111 },
109 - model: model,
110112 context: context
111113 } );
112114 } else { //else this was an unmatched opening
@@ -146,7 +148,7 @@
147149 * @param $wrapper Wrapping <span>
148150 */
149151 wrapTemplate: function( $wrapper ) {
150 - var model = $wrapper.data( 'marker' ).model;
 152+ var model = $wrapper.data( 'model' );
151153 var context = $wrapper.data( 'marker' ).context;
152154
153155 var $template = $wrapper
@@ -202,46 +204,6 @@
203205
204206 return false;
205207 };
206 -
207 - // Expand
208 - // FIXME: This function is unused
209 - function expandTemplate( $displayDiv ) {
210 - // Housekeeping
211 - $displayDiv
212 - .removeClass( 'wikiEditor-template-collapsed' )
213 - .addClass( 'wikiEditor-template-expanded' )
214 - // remove mousedown hander from the entire thing
215 - .unbind( 'mousedown' );
216 - //$displayDiv.text( model.getText() );
217 - $keyValueTable = $( '<table />' )
218 - .appendTo( $displayDiv );
219 - $header_row = $( '<tr />' )
220 - .appendTo( $keyValueTable );
221 - $( '<th />' )
222 - .attr( 'colspan', '2' )
223 - .text( model.getName() )
224 - .appendTo( $header_row );
225 - for( param in model.getAllParamNames() ){
226 - $keyVal_row = $( '<tr />' )
227 - .appendTo( $keyValueTable );
228 -
229 - $( '<td />' )
230 - .text( param )
231 - .appendTo( $keyVal_row );
232 - $( '<td />' )
233 - .text( model.getValue( param ) )
234 - .appendTo( $keyVal_row );
235 - }
236 - };
237 - // Collapse
238 - // FIXME: This function is unused
239 - function collapseTemplate( $displayDiv ) {
240 - // Housekeeping
241 - $displayDiv
242 - .addClass( 'wikiEditor-template-collapsed' )
243 - .removeClass( 'wikiEditor-template-expanded' )
244 - .text( model.getName() );
245 - };
246208
247209 var dialog = {
248210 'titleMsg': 'wikieditor-template-editor-dialog-title',
@@ -290,24 +252,39 @@
291253 // TODO: Be smart and recycle existing table
292254 var params = templateModel.getAllInitialParams();
293255 var $table = $(this).find( '.wikiEditor-template-dialog-table' ).empty();
 256+ // Do some bookkeeping so we can recycle existing rows
 257+ var $rows = $table.find( 'tr' );
294258 for ( var paramIndex in params ) {
295259 var param = params[paramIndex];
296260 if ( typeof param.name == 'undefined' ) {
297261 // param is the template name, skip it
298262 continue;
299263 }
300 - var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
301 - $( '<td />' ).addClass( 'wikiEditor-template-dialog-label' ).text(
302 - typeof param == 'string' ?
 264+
 265+ var paramText = typeof param == 'string' ?
303266 param.name.replace( /[\_\-]/g, ' ' ) :
304 - param.name
305 - ).appendTo( $paramRow );
306 - $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
307 - $( '<input />' )
308 - .data( 'name', param.name )
309 - .val( templateModel.getValue( param.name ) )
310 - ).appendTo( $paramRow );
311 - $table.append( $paramRow );
 267+ param.name;
 268+ var paramVal = templateModel.getValue( param.name );
 269+ if ( $rows.length > 0 ) {
 270+ // We have another row to recycle
 271+ var $row = $rows.eq( 0 );
 272+ $row.children( '.wikiEditor-template-dialog-label' ).text( paramText );
 273+ $row.children( '.wikiEditor-template-dialog-value input' ).val( paramVal );
 274+ $rows = $rows.not( $row );
 275+ } else {
 276+ // Create a new row
 277+ var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
 278+ $( '<td />' )
 279+ .addClass( 'wikiEditor-template-dialog-label' )
 280+ .text( paramText )
 281+ .appendTo( $paramRow );
 282+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
 283+ $( '<input />' ).data( 'name', param.name ).val( paramVal )
 284+ ).appendTo( $paramRow );
 285+ $table.append( $paramRow );
 286+ }
 287+ // Remove any leftover rows
 288+ $rows.remove();
312289 }
313290 }
314291 }
@@ -320,10 +297,6 @@
321298 .data( 'templateDiv', $templateDiv )
322299 .dialog( 'open' );
323300 }
324 -
325 - function noEdit() {
326 - return false;
327 - }
328301 },
329302 /**
330303 * Turn a complex template wrapper back into a simple one
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -9135,6 +9135,10 @@
91369136 */
91379137 evt: {
91389138 mark: function( context, event ) {
 9139+ if ( $( 'body' ).hasClass( 'ns-10' ) ) {
 9140+ // We're in the template namespace, don't collapse any templates
 9141+ return;
 9142+ }
91399143 // Get references to the markers and tokens from the current context
91409144 var markers = context.modules.highlight.markers;
91419145 var tokenArray = context.modules.highlight.tokenArray;
@@ -9164,13 +9168,6 @@
91659169 }
91669170 }//while finding template ending
91679171 if ( endIndex != -1 ) {
9168 - // Create a model for the template
9169 - // FIXME: This is a performance hit
9170 - var model = new $.wikiEditor.modules.templateEditor.fn.model(
9171 - context.fn.getContents().substring( tokenArray[beginIndex].offset,
9172 - tokenArray[endIndex].offset
9173 - )
9174 - );
91759172 markers.push( {
91769173 start: tokenArray[beginIndex].offset,
91779174 end: tokenArray[endIndex].offset,
@@ -9179,9 +9176,12 @@
91809177 //splitPs: model.isCollapsible(),
91819178 splitPs: false,
91829179 afterWrap: function( node ) {
9183 - // Store model so we can compare it later
9184 - $( node ).data( 'model', $( node ).data( 'marker' ).model );
9185 - if ( $( node ).data( 'model' ).isCollapsible() ) {
 9180+ // Generate model
 9181+ var model = new $.wikiEditor.modules.templateEditor.fn.model(
 9182+ $( node ).text()
 9183+ );
 9184+ $( node ).data( 'model', model );
 9185+ if ( model.isCollapsible() ) {
91869186 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
91879187 } else {
91889188 $( node ).addClass( 'wikiEditor-template-text' );
@@ -9193,26 +9193,28 @@
91949194 }
91959195 },
91969196 onSkip: function( node ) {
9197 - var oldModel = $( node ).data( 'model' );
9198 - var newModel = $( node ).data( 'marker' ).model;
9199 - if ( oldModel.getText() == newModel.getText() ) {
 9197+ if ( $( node ).data( 'model' ).getText() == $( node ).text() ) {
92009198 // No change
92019199 return;
92029200 }
 9201+ // Text changed, regenerate model
 9202+ var model = new $.wikiEditor.modules.templateEditor.fn.model(
 9203+ $( node ).text()
 9204+ );
 9205+ $( node ).data( 'model', model );
92039206
9204 - if ( $( node ).parent().hasClass( 'wikiEditor-template' ) && !newModel.isCollapsible() ) {
 9207+ if ( $( node ).parent().hasClass( 'wikiEditor-template' ) &&
 9208+ !model.isCollapsible() ) {
92059209 $.wikiEditor.modules.templateEditor.fn.unwrapTemplate( $( node ) );
9206 - } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) && newModel.isCollapsible() ) {
 9210+ } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) &&
 9211+ model.isCollapsible() ) {
92079212 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
92089213 }
9209 - // TODO: Update table; not doing this yet because the table will probably die
92109214 },
92119215 getAnchor: function( ca1, ca2 ) {
9212 - // FIXME: Relies on the current <span> structure that is likely to die
92139216 return $( ca1.parentNode ).is( 'span.wikiEditor-template-text' ) ?
92149217 ca1.parentNode : null;
92159218 },
9216 - model: model,
92179219 context: context
92189220 } );
92199221 } else { //else this was an unmatched opening
@@ -9253,7 +9255,7 @@
92549256 * @param $wrapper Wrapping <span>
92559257 */
92569258 wrapTemplate: function( $wrapper ) {
9257 - var model = $wrapper.data( 'marker' ).model;
 9259+ var model = $wrapper.data( 'model' );
92589260 var context = $wrapper.data( 'marker' ).context;
92599261
92609262 var $template = $wrapper
@@ -9309,46 +9311,6 @@
93109312
93119313 return false;
93129314 };
9313 -
9314 - // Expand
9315 - // FIXME: This function is unused
9316 - function expandTemplate( $displayDiv ) {
9317 - // Housekeeping
9318 - $displayDiv
9319 - .removeClass( 'wikiEditor-template-collapsed' )
9320 - .addClass( 'wikiEditor-template-expanded' )
9321 - // remove mousedown hander from the entire thing
9322 - .unbind( 'mousedown' );
9323 - //$displayDiv.text( model.getText() );
9324 - $keyValueTable = $( '<table />' )
9325 - .appendTo( $displayDiv );
9326 - $header_row = $( '<tr />' )
9327 - .appendTo( $keyValueTable );
9328 - $( '<th />' )
9329 - .attr( 'colspan', '2' )
9330 - .text( model.getName() )
9331 - .appendTo( $header_row );
9332 - for( param in model.getAllParamNames() ){
9333 - $keyVal_row = $( '<tr />' )
9334 - .appendTo( $keyValueTable );
9335 -
9336 - $( '<td />' )
9337 - .text( param )
9338 - .appendTo( $keyVal_row );
9339 - $( '<td />' )
9340 - .text( model.getValue( param ) )
9341 - .appendTo( $keyVal_row );
9342 - }
9343 - };
9344 - // Collapse
9345 - // FIXME: This function is unused
9346 - function collapseTemplate( $displayDiv ) {
9347 - // Housekeeping
9348 - $displayDiv
9349 - .addClass( 'wikiEditor-template-collapsed' )
9350 - .removeClass( 'wikiEditor-template-expanded' )
9351 - .text( model.getName() );
9352 - };
93539315
93549316 var dialog = {
93559317 'titleMsg': 'wikieditor-template-editor-dialog-title',
@@ -9397,24 +9359,39 @@
93989360 // TODO: Be smart and recycle existing table
93999361 var params = templateModel.getAllInitialParams();
94009362 var $table = $(this).find( '.wikiEditor-template-dialog-table' ).empty();
 9363+ // Do some bookkeeping so we can recycle existing rows
 9364+ var $rows = $table.find( 'tr' );
94019365 for ( var paramIndex in params ) {
94029366 var param = params[paramIndex];
94039367 if ( typeof param.name == 'undefined' ) {
94049368 // param is the template name, skip it
94059369 continue;
94069370 }
9407 - var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
9408 - $( '<td />' ).addClass( 'wikiEditor-template-dialog-label' ).text(
9409 - typeof param == 'string' ?
 9371+
 9372+ var paramText = typeof param == 'string' ?
94109373 param.name.replace( /[\_\-]/g, ' ' ) :
9411 - param.name
9412 - ).appendTo( $paramRow );
9413 - $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
9414 - $( '<input />' )
9415 - .data( 'name', param.name )
9416 - .val( templateModel.getValue( param.name ) )
9417 - ).appendTo( $paramRow );
9418 - $table.append( $paramRow );
 9374+ param.name;
 9375+ var paramVal = templateModel.getValue( param.name );
 9376+ if ( $rows.length > 0 ) {
 9377+ // We have another row to recycle
 9378+ var $row = $rows.eq( 0 );
 9379+ $row.children( '.wikiEditor-template-dialog-label' ).text( paramText );
 9380+ $row.children( '.wikiEditor-template-dialog-value input' ).val( paramVal );
 9381+ $rows = $rows.not( $row );
 9382+ } else {
 9383+ // Create a new row
 9384+ var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
 9385+ $( '<td />' )
 9386+ .addClass( 'wikiEditor-template-dialog-label' )
 9387+ .text( paramText )
 9388+ .appendTo( $paramRow );
 9389+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
 9390+ $( '<input />' ).data( 'name', param.name ).val( paramVal )
 9391+ ).appendTo( $paramRow );
 9392+ $table.append( $paramRow );
 9393+ }
 9394+ // Remove any leftover rows
 9395+ $rows.remove();
94199396 }
94209397 }
94219398 }
@@ -9427,10 +9404,6 @@
94289405 .data( 'templateDiv', $templateDiv )
94299406 .dialog( 'open' );
94309407 }
9431 -
9432 - function noEdit() {
9433 - return false;
9434 - }
94359408 },
94369409 /**
94379410 * Turn a complex template wrapper back into a simple one
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -637,18 +637,19 @@
638638 $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked'))
639639 $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0)
640640 $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked'))
641 -$('#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={'browsers':{'ltr':{'msie':[['>=',8]],'firefox':[['>=',3]],'opera':[['>=',10]],'safari':[['>=',4]]},'rtl':{'msie':[['>=',8]],'firefox':[['>=',3]],'opera':[['>=',10]],'safari':[['>=',4]]}},'req':['iframe'],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++;}
 641+$('#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={'browsers':{'ltr':{'msie':[['>=',8]],'firefox':[['>=',3]],'opera':[['>=',10]],'safari':[['>=',4]]},'rtl':{'msie':[['>=',8]],'firefox':[['>=',3]],'opera':[['>=',10]],'safari':[['>=',4]]}},'req':['iframe'],evt:{mark:function(context,event){if($('body').hasClass('ns-10')){return;}
 642+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++;}
642643 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;}}}
643 -if(endIndex!=-1){var model=new $.wikiEditor.modules.templateEditor.fn.model(context.fn.getContents().substring(tokenArray[beginIndex].offset,tokenArray[endIndex].offset));markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,type:'template',anchor:'wrap',splitPs:false,afterWrap:function(node){$(node).data('model',$(node).data('marker').model);if($(node).data('model').isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(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){var oldModel=$(node).data('model');var newModel=$(node).data('marker').model;if(oldModel.getText()==newModel.getText()){return;}
644 -if($(node).parent().hasClass('wikiEditor-template')&&!newModel.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}else if(!$(node).parent().hasClass('wikiEditor-template')&&newModel.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));}},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('span.wikiEditor-template-text')?ca1.parentNode:null;},model:model,context:context});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}}},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('marker').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').data('model',model);var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(toggleWikiTextEditor).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/expand.png')+'" width="12" height="16" />').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/collapse.png')+'" width="12" height="16" style="display:none;" />').mousedown(toggleWikiTextEditor).prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/dialog-collapsed.png')+'" width="22" height="16" />').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/dialog-expanded.png')+'" width="22" height="16" style="display:none;" />').mousedown(function(){createDialog($template);return false;}).insertAfter($templateName);function toggleWikiTextEditor(){context.fn.purgeOffsets();var $template=$(this).closest('.wikiEditor-template');$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('img').each(function(){$(this).toggle();});var $wikitext=$template.children('.wikiEditor-template-text');$wikitext.toggleClass('wikiEditor-nodisplay');if($template.hasClass('wikiEditor-template-collapsed')){var model=new $.wikiEditor.modules.templateEditor.fn.model($template.children('.wikiEditor-template-text').text());$template.children('.wikiEditor-template-text').data('model',model);$template.children('.wikiEditor-template-name').text(model.getName());}else{$wikitext.text($template.children('.wikiEditor-template-text').data('model').getText());}
645 -return false;};function expandTemplate($displayDiv){$displayDiv.removeClass('wikiEditor-template-collapsed').addClass('wikiEditor-template-expanded').unbind('mousedown');$keyValueTable=$('<table />').appendTo($displayDiv);$header_row=$('<tr />').appendTo($keyValueTable);$('<th />').attr('colspan','2').text(model.getName()).appendTo($header_row);for(param in model.getAllParamNames()){$keyVal_row=$('<tr />').appendTo($keyValueTable);$('<td />').text(param).appendTo($keyVal_row);$('<td />').text(model.getValue(param)).appendTo($keyVal_row);}};function collapseTemplate($displayDiv){$displayDiv.addClass('wikiEditor-template-collapsed').removeClass('wikiEditor-template-expanded').text(model.getName());};var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\
 644+if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,type:'template',anchor:'wrap',splitPs:false,afterWrap:function(node){var model=new $.wikiEditor.modules.templateEditor.fn.model($(node).text());$(node).data('model',model);if(model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(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).data('model').getText()==$(node).text()){return;}
 645+var model=new $.wikiEditor.modules.templateEditor.fn.model($(node).text());$(node).data('model',model);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));}},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;}}}}},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').data('model',model);var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(toggleWikiTextEditor).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/expand.png')+'" width="12" height="16" />').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/collapse.png')+'" width="12" height="16" style="display:none;" />').mousedown(toggleWikiTextEditor).prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/dialog-collapsed.png')+'" width="22" height="16" />').append('<img src="'+$.wikiEditor.autoIcon('templateEditor/dialog-expanded.png')+'" width="22" height="16" style="display:none;" />').mousedown(function(){createDialog($template);return false;}).insertAfter($templateName);function toggleWikiTextEditor(){context.fn.purgeOffsets();var $template=$(this).closest('.wikiEditor-template');$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('img').each(function(){$(this).toggle();});var $wikitext=$template.children('.wikiEditor-template-text');$wikitext.toggleClass('wikiEditor-nodisplay');if($template.hasClass('wikiEditor-template-collapsed')){var model=new $.wikiEditor.modules.templateEditor.fn.model($template.children('.wikiEditor-template-text').text());$template.children('.wikiEditor-template-text').data('model',model);$template.children('.wikiEditor-template-name').text(model.getName());}else{$wikitext.text($template.children('.wikiEditor-template-text').data('model').getText());}
 646+return false;};var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\
646647 <fieldset>\
647648 <div class="wikiEditor-template-dialog-title" />\
648649 <table class="wikiEditor-template-dialog-table" />\
649650 </fieldset>',init:function(){$(this).find('[rel]').each(function(){$(this).text(mw.usability.getMsg($(this).attr('rel')));});},dialog:{width:500,dialogClass:'wikiEditor-toolbar-dialog',buttons:{'wikieditor-template-editor-dialog-submit':function(){var $templateDiv=$(this).data('templateDiv');context.fn.highlightLine($templateDiv);var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');$(this).find('.wikiEditor-template-dialog-value input').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$templateText.text(templateModel.getText());$(this).dialog('close');}},open:function(){var $templateDiv=$(this).data('templateDiv');var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');if(templateModel.getText()!=$templateText.text()){templateModel=new $.wikiEditor.modules.templateEditor.fn.model($templateText.text());$templateText.data('model',templateModel);}
650 -var params=templateModel.getAllInitialParams();var $table=$(this).find('.wikiEditor-template-dialog-table').empty();for(var paramIndex in params){var param=params[paramIndex];if(typeof param.name=='undefined'){continue;}
651 -var $paramRow=$('<tr />').addClass('wikiEditor-template-dialog-row');$('<td />').addClass('wikiEditor-template-dialog-label').text(typeof param=='string'?param.name.replace(/[\_\-]/g,' '):param.name).appendTo($paramRow);$('<td />').addClass('wikiEditor-template-dialog-value').append($('<input />').data('name',param.name).val(templateModel.getValue(param.name))).appendTo($paramRow);$table.append($paramRow);}}}};function createDialog($templateDiv){context.$textarea.wikiEditor('addDialog',{'templateEditor':dialog});$('#'+dialog.id).data('templateDiv',$templateDiv).dialog('open');}
652 -function noEdit(){return false;}},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},getTemplateInfo:function(templateName){var templateInfo='';return $(templateInfo);},model:function(wikitext){var collapsible=true;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;}
 651+var params=templateModel.getAllInitialParams();var $table=$(this).find('.wikiEditor-template-dialog-table').empty();var $rows=$table.find('tr');for(var paramIndex in params){var param=params[paramIndex];if(typeof param.name=='undefined'){continue;}
 652+var paramText=typeof param=='string'?param.name.replace(/[\_\-]/g,' '):param.name;var paramVal=templateModel.getValue(param.name);if($rows.length>0){var $row=$rows.eq(0);$row.children('.wikiEditor-template-dialog-label').text(paramText);$row.children('.wikiEditor-template-dialog-value input').val(paramVal);$rows=$rows.not($row);}else{var $paramRow=$('<tr />').addClass('wikiEditor-template-dialog-row');$('<td />').addClass('wikiEditor-template-dialog-label').text(paramText).appendTo($paramRow);$('<td />').addClass('wikiEditor-template-dialog-value').append($('<input />').data('name',param.name).val(paramVal)).appendTo($paramRow);$table.append($paramRow);}
 653+$rows.remove();}}}};function createDialog($templateDiv){context.$textarea.wikiEditor('addDialog',{'templateEditor':dialog});$('#'+dialog.id).data('templateDiv',$templateDiv).dialog('open');}},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},getTemplateInfo:function(templateName){var templateInfo='';return $(templateInfo);},model:function(wikitext){var collapsible=true;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;}
653654 function Range(begin,end){this.begin=begin;this.end=end;}
654655 function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";}
655656 rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);}

Follow-up revisions

RevisionCommit summaryAuthorDate
r63165UsabilityInitiative: Remove template namespace check added in r63141 in favor...catrope10:29, 2 March 2010

Status & tagging log