r63121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63120‎ | r63121 | r63122 >
Date:16:47, 1 March 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Convert template dialogs to using the dialogs module, random fixes
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/TemplateEditor/TemplateEditor.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.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
@@ -79,14 +79,14 @@
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 19 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 95 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
83 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 27 ),
 83+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 28 ),
8484 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8585 ),
8686 'combined' => array(
87 - array( 'src' => 'js/plugins.combined.js', 'version' => 294 ),
 87+ array( 'src' => 'js/plugins.combined.js', 'version' => 295 ),
8888 ),
8989 'minified' => array(
90 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 294 ),
 90+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 295 ),
9191 ),
9292 ),
9393 );
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php
@@ -61,6 +61,10 @@
6262 ),
6363 ),
6464 ),
 65+ 'messages' => array(
 66+ 'wikieditor-template-editor-dialog-title',
 67+ 'wikieditor-template-editor-dialog-submit',
 68+ ),
6569 ),
6670 'preview' => array(
6771 'i18n' => 'WikiEditorPreview',
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/TemplateEditor/TemplateEditor.i18n.php
@@ -13,6 +13,8 @@
1414 */
1515 $messages['en'] = array(
1616 'wikieditor-template-editor-preference' => 'Enable form-based editing of wiki templates',
 17+ 'wikieditor-template-editor-dialog-title' => 'Edit template',
 18+ 'wikieditor-template-editor-dialog-submit' => 'OK',
1719 );
1820
1921 /** Afrikaans (Afrikaans)
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -74,7 +74,7 @@
7575 afterWrap: function( node ) {
7676 // Store model so we can compare it later
7777 $( node ).data( 'model', $( node ).data( 'marker' ).model );
78 - if ( model.isCollapsible() ) {
 78+ if ( $( node ).data( 'model' ).isCollapsible() ) {
7979 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
8080 } else {
8181 $( node ).addClass( 'wikiEditor-template-text' );
@@ -150,6 +150,7 @@
151151 var context = $wrapper.data( 'marker' ).context;
152152
153153 var $template = $wrapper
 154+ .addClass( 'wikiEditor-template-text' )
154155 .wrap( '<span class="wikiEditor-template"></span>' )
155156 .addClass( 'wikiEditor-nodisplay' )
156157 .parent()
@@ -164,20 +165,20 @@
165166
166167 var $templateExpand = $( '<span />' )
167168 .addClass( 'wikiEditor-template-expand wikiEditor-noinclude' )
168 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/expand.png" width="12" height="16" />' )
169 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/collapse.png" width="12" height="16" style="display:none;" />' )
 169+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/expand.png' ) + '" width="12" height="16" />' )
 170+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/collapse.png' ) + '" width="12" height="16" style="display:none;" />' )
170171 .mousedown( toggleWikiTextEditor )
171172 .prependTo( $template );
172173
173174 var $templateDialog = $( '<span />' )
174175 .addClass( 'wikiEditor-template-dialog wikiEditor-noinclude' )
175 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/dialog-collapsed.png" width="22" height="16" />' )
176 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/dialog-expanded.png" width="22" height="16" style="display:none;" />' )
 176+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/dialog-collapsed.png' ) + '" width="22" height="16" />' )
 177+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/dialog-expanded.png' ) + '" width="22" height="16" style="display:none;" />' )
177178 .mousedown( function() { createDialog( $template ); return false; } )
178179 .insertAfter( $templateName );
179180
180181 function toggleWikiTextEditor() {
181 - context.fn.refreshOffsets();
 182+ context.fn.purgeOffsets();
182183 var $template = $( this ).closest( '.wikiEditor-template' );
183184 $template
184185 .toggleClass( 'wikiEditor-template-expanded' )
@@ -194,16 +195,17 @@
195196 var model = new $.wikiEditor.modules.templateEditor.fn.model(
196197 $template.children( '.wikiEditor-template-text' ).text()
197198 );
198 - $template.data( 'model' , model );
 199+ $template.children( '.wikiEditor-template-text' ).data( 'model', model );
199200 $template.children( '.wikiEditor-template-name' ).text( model.getName() );
200201 } else { //we just expanded this
201 - $wikitext.text( $template.data( 'model' ).getText() );
 202+ $wikitext.text( $template.children( '.wikiEditor-template-text' ).data( 'model' ).getText() );
202203 }
203204
204205 return false;
205206 };
206207
207208 // Expand
 209+ // FIXME: This function is unused
208210 function expandTemplate( $displayDiv ) {
209211 // Housekeeping
210212 $displayDiv
@@ -233,6 +235,7 @@
234236 }
235237 };
236238 // Collapse
 239+ // FIXME: This function is unused
237240 function collapseTemplate( $displayDiv ) {
238241 // Housekeeping
239242 $displayDiv
@@ -241,89 +244,84 @@
242245 .text( model.getName() );
243246 };
244247
245 - function createDialog( $templateDiv ) {
246 - // Give the user some feedback on what they're doing
247 - context.fn.highlightLine( $templateDiv );
248 - //
249 - var $wikitext = $templateDiv.children( '.wikiEditor-template-text' );
250 - //TODO: check if template model has been changed
251 - var templateModel = new $.wikiEditor.modules.templateEditor.fn.model( $wikitext.text() );
252 - $templateDiv.data( 'model', templateModel );
253 - var $dialog = $( '<div />' );
254 - var $title = $(' <div />' )
255 - .text( templateModel.getName() )
256 - .addClass( 'wikiEditor-template-dialog-title' );
257 - var $table = $( '<table />' )
258 - .addClass( 'wikiEditor-template-dialog-table' )
259 - .appendTo( $dialog );
260 - var allInitialParams = templateModel.getAllInitialParams();
261 - for ( var paramIndex in allInitialParams ) {
262 - var param = allInitialParams[paramIndex];
263 - if ( typeof param.name == 'undefined' ) {
264 - //param 0 is the name
265 - continue;
 248+ var dialog = {
 249+ 'titleMsg': 'wikieditor-template-editor-dialog-title',
 250+ 'id': 'wikiEditor-template-dialog',
 251+ 'html': '\
 252+ <fieldset>\
 253+ <div class="wikiEditor-template-dialog-title" />\
 254+ <table class="wikiEditor-template-dialog-table" />\
 255+ </fieldset>',
 256+ init: function() {
 257+ $(this).find( '[rel]' ).each( function() {
 258+ $(this).text( mw.usability.getMsg( $(this).attr( 'rel' ) ) );
 259+ } );
 260+ },
 261+ dialog: {
 262+ width: 500,
 263+ buttons: {
 264+ 'wikieditor-template-editor-dialog-submit': function() {
 265+ // More user feedback
 266+ var $templateDiv = $(this).data( 'templateDiv' );
 267+ context.fn.highlightLine( $templateDiv );
 268+
 269+ var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
 270+ var templateModel = $templateText.data( 'model' );
 271+ $(this).find( '.wikiEditor-template-dialog-value input' ).each( function() {
 272+ templateModel.setValue( $(this).data( 'name' ), $(this).val() );
 273+ });
 274+ //keep text consistent
 275+ $templateText.text( templateModel.getText() );
 276+
 277+ $(this).dialog( 'close' );
 278+ }
 279+ },
 280+ open: function() {
 281+ var $templateDiv = $(this).data( 'templateDiv' );
 282+ var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
 283+ var templateModel = $templateText.data( 'model' );
 284+ // Update the model if we need to
 285+ if ( templateModel.getText() != $templateText.text() ) {
 286+ templateModel = new $.wikiEditor.modules.templateEditor.fn.model( $templateText.text() );
 287+ $templateText.data( 'model', templateModel );
 288+ }
 289+
 290+ // Build the table
 291+ // TODO: Be smart and recycle existing table
 292+ var params = templateModel.getAllInitialParams();
 293+ var $table = $(this).find( '.wikiEditor-template-dialog-table' ).empty();
 294+ for ( var paramIndex in params ) {
 295+ var param = params[paramIndex];
 296+ if ( typeof param.name == 'undefined' ) {
 297+ // param is the template name, skip it
 298+ continue;
 299+ }
 300+ var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
 301+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-name' ).text(
 302+ typeof param == 'string' ?
 303+ param.name.replace( /[\_\-]/g, ' ' )
 304+ .replace( /^(.)|\s(.)/g, function( first ) {
 305+ return first.toUpperCase();
 306+ } ) :
 307+ param.name
 308+ ).appendTo( $paramRow );
 309+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
 310+ $( '<input />' )
 311+ .data( 'name', param.name )
 312+ .val( templateModel.getValue( param.name ) )
 313+ ).appendTo( $paramRow );
 314+ $table.append( $paramRow );
 315+ }
266316 }
267 - var $paramRow = $( '<tr />' )
268 - .addClass( 'wikiEditor-template-dialog-row' );
269 - var $paramName = $( '<td />' )
270 - .addClass( 'wikiEditor-template-dialog-name' )
271 - .text(
272 - param.name.replace( /[\_\-]/g, ' ' ).replace( /^(.)|\s(.)/g, function ( first ) {
273 - return first.toUpperCase();
274 - } )
275 - );
276 - var $paramVal = $( '<td />' )
277 - .addClass( 'wikiEditor-template-dialog-value' );
278 - var $paramInput = $( '<input />' )
279 - .data( 'name', param.name )
280 - .val( templateModel.getValue( param.name ) );
281 - $paramVal.append( $paramInput );
282 - $paramRow.append( $paramName ).append( $paramVal );
283 - $table.append( $paramRow );
284317 }
285 - //click handler for values
286 - $( '<button />' ).click( function() {
287 - // More user feedback
288 - context.fn.highlightLine( $templateDiv );
289 - //
290 - $( '.wikiEditor-template-dialog-value input' ).each( function(){
291 - templateModel.setValue( $(this).data( 'name' ), $(this).val() );
292 - });
293 - //keep text consistent
294 - $wikitext.text( templateModel.getText() );
295 -
296 - $dialog.dialog( 'close' );
297 -
298 - }).text( 'OK' ).appendTo( $dialog ); // FIXME: Internationalize 'OK'
299 - $dialog.dialog(); //opens dialog
300 - return false;
301318 };
302319
303 - function toggleWikiText() {
304 - var $template = $( this ).closest( '.wikiEditor-template' );
305 - $template
306 - .toggleClass( 'wikiEditor-template-collapsed' )
307 - .toggleClass( 'wikiEditor-template-expanded' )
308 - .children( '.wikiEditor-template-text, .wikiEditor-template-name, .wikiEditor-template-modes' )
309 - .toggleClass( 'wikiEditor-nodisplay' );
310 -
311 - //if we just collapsed this
312 - if ( $template.hasClass( 'wikiEditor-template-collapsed' ) ) {
313 - var model = new $.wikiEditor.modules.templateEditor.fn.model(
314 - $template.children( '.wikiEditor-template-text' ).text()
315 - );
316 - $template.data( 'model' , model );
317 - $template.children( '.wikiEditor-template-name' ).text( model.getName() );
318 - } else{ //else we just expanded this
319 - $template.children( '.wikiEditor-template-text' ).children('.wikiEditor-template-inner-text').text(
320 - $template.data('model')
321 - .getText()
322 - .replace(/\{\{/, '')
323 - .replace(/\}\}$/, '')
324 - );
325 -
326 - }
327 - return false;
 320+ function createDialog( $templateDiv ) {
 321+ // Lazy-create the dialog at this time
 322+ context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } );
 323+ $( '#' + dialog.id )
 324+ .data( 'templateDiv', $templateDiv )
 325+ .dialog( 'open' );
328326 }
329327
330328 function noEdit() {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -9075,7 +9075,7 @@
90769076 afterWrap: function( node ) {
90779077 // Store model so we can compare it later
90789078 $( node ).data( 'model', $( node ).data( 'marker' ).model );
9079 - if ( model.isCollapsible() ) {
 9079+ if ( $( node ).data( 'model' ).isCollapsible() ) {
90809080 $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) );
90819081 } else {
90829082 $( node ).addClass( 'wikiEditor-template-text' );
@@ -9151,6 +9151,7 @@
91529152 var context = $wrapper.data( 'marker' ).context;
91539153
91549154 var $template = $wrapper
 9155+ .addClass( 'wikiEditor-template-text' )
91559156 .wrap( '<span class="wikiEditor-template"></span>' )
91569157 .addClass( 'wikiEditor-nodisplay' )
91579158 .parent()
@@ -9165,20 +9166,20 @@
91669167
91679168 var $templateExpand = $( '<span />' )
91689169 .addClass( 'wikiEditor-template-expand wikiEditor-noinclude' )
9169 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/expand.png" width="12" height="16" />' )
9170 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/collapse.png" width="12" height="16" style="display:none;" />' )
 9170+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/expand.png' ) + '" width="12" height="16" />' )
 9171+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/collapse.png' ) + '" width="12" height="16" style="display:none;" />' )
91719172 .mousedown( toggleWikiTextEditor )
91729173 .prependTo( $template );
91739174
91749175 var $templateDialog = $( '<span />' )
91759176 .addClass( 'wikiEditor-template-dialog wikiEditor-noinclude' )
9176 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/dialog-collapsed.png" width="22" height="16" />' )
9177 - .append( '<img src="' + $.wikiEditor.imgPath + '/templateEditor/dialog-expanded.png" width="22" height="16" style="display:none;" />' )
 9177+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/dialog-collapsed.png' ) + '" width="22" height="16" />' )
 9178+ .append( '<img src="' + $.wikiEditor.autoIcon( 'templateEditor/dialog-expanded.png' ) + '" width="22" height="16" style="display:none;" />' )
91789179 .mousedown( function() { createDialog( $template ); return false; } )
91799180 .insertAfter( $templateName );
91809181
91819182 function toggleWikiTextEditor() {
9182 - context.fn.refreshOffsets();
 9183+ context.fn.purgeOffsets();
91839184 var $template = $( this ).closest( '.wikiEditor-template' );
91849185 $template
91859186 .toggleClass( 'wikiEditor-template-expanded' )
@@ -9195,16 +9196,17 @@
91969197 var model = new $.wikiEditor.modules.templateEditor.fn.model(
91979198 $template.children( '.wikiEditor-template-text' ).text()
91989199 );
9199 - $template.data( 'model' , model );
 9200+ $template.children( '.wikiEditor-template-text' ).data( 'model', model );
92009201 $template.children( '.wikiEditor-template-name' ).text( model.getName() );
92019202 } else { //we just expanded this
9202 - $wikitext.text( $template.data( 'model' ).getText() );
 9203+ $wikitext.text( $template.children( '.wikiEditor-template-text' ).data( 'model' ).getText() );
92039204 }
92049205
92059206 return false;
92069207 };
92079208
92089209 // Expand
 9210+ // FIXME: This function is unused
92099211 function expandTemplate( $displayDiv ) {
92109212 // Housekeeping
92119213 $displayDiv
@@ -9234,6 +9236,7 @@
92359237 }
92369238 };
92379239 // Collapse
 9240+ // FIXME: This function is unused
92389241 function collapseTemplate( $displayDiv ) {
92399242 // Housekeeping
92409243 $displayDiv
@@ -9242,89 +9245,84 @@
92439246 .text( model.getName() );
92449247 };
92459248
9246 - function createDialog( $templateDiv ) {
9247 - // Give the user some feedback on what they're doing
9248 - context.fn.highlightLine( $templateDiv );
9249 - //
9250 - var $wikitext = $templateDiv.children( '.wikiEditor-template-text' );
9251 - //TODO: check if template model has been changed
9252 - var templateModel = new $.wikiEditor.modules.templateEditor.fn.model( $wikitext.text() );
9253 - $templateDiv.data( 'model', templateModel );
9254 - var $dialog = $( '<div />' );
9255 - var $title = $(' <div />' )
9256 - .text( templateModel.getName() )
9257 - .addClass( 'wikiEditor-template-dialog-title' );
9258 - var $table = $( '<table />' )
9259 - .addClass( 'wikiEditor-template-dialog-table' )
9260 - .appendTo( $dialog );
9261 - var allInitialParams = templateModel.getAllInitialParams();
9262 - for ( var paramIndex in allInitialParams ) {
9263 - var param = allInitialParams[paramIndex];
9264 - if ( typeof param.name == 'undefined' ) {
9265 - //param 0 is the name
9266 - continue;
 9249+ var dialog = {
 9250+ 'titleMsg': 'wikieditor-template-editor-dialog-title',
 9251+ 'id': 'wikiEditor-template-dialog',
 9252+ 'html': '\
 9253+ <fieldset>\
 9254+ <div class="wikiEditor-template-dialog-title" />\
 9255+ <table class="wikiEditor-template-dialog-table" />\
 9256+ </fieldset>',
 9257+ init: function() {
 9258+ $(this).find( '[rel]' ).each( function() {
 9259+ $(this).text( mw.usability.getMsg( $(this).attr( 'rel' ) ) );
 9260+ } );
 9261+ },
 9262+ dialog: {
 9263+ width: 500,
 9264+ buttons: {
 9265+ 'wikieditor-template-editor-dialog-submit': function() {
 9266+ // More user feedback
 9267+ var $templateDiv = $(this).data( 'templateDiv' );
 9268+ context.fn.highlightLine( $templateDiv );
 9269+
 9270+ var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
 9271+ var templateModel = $templateText.data( 'model' );
 9272+ $(this).find( '.wikiEditor-template-dialog-value input' ).each( function() {
 9273+ templateModel.setValue( $(this).data( 'name' ), $(this).val() );
 9274+ });
 9275+ //keep text consistent
 9276+ $templateText.text( templateModel.getText() );
 9277+
 9278+ $(this).dialog( 'close' );
 9279+ }
 9280+ },
 9281+ open: function() {
 9282+ var $templateDiv = $(this).data( 'templateDiv' );
 9283+ var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
 9284+ var templateModel = $templateText.data( 'model' );
 9285+ // Update the model if we need to
 9286+ if ( templateModel.getText() != $templateText.text() ) {
 9287+ templateModel = new $.wikiEditor.modules.templateEditor.fn.model( $templateText.text() );
 9288+ $templateText.data( 'model', templateModel );
 9289+ }
 9290+
 9291+ // Build the table
 9292+ // TODO: Be smart and recycle existing table
 9293+ var params = templateModel.getAllInitialParams();
 9294+ var $table = $(this).find( '.wikiEditor-template-dialog-table' ).empty();
 9295+ for ( var paramIndex in params ) {
 9296+ var param = params[paramIndex];
 9297+ if ( typeof param.name == 'undefined' ) {
 9298+ // param is the template name, skip it
 9299+ continue;
 9300+ }
 9301+ var $paramRow = $( '<tr />' ).addClass( 'wikiEditor-template-dialog-row' );
 9302+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-name' ).text(
 9303+ typeof param == 'string' ?
 9304+ param.name.replace( /[\_\-]/g, ' ' )
 9305+ .replace( /^(.)|\s(.)/g, function( first ) {
 9306+ return first.toUpperCase();
 9307+ } ) :
 9308+ param.name
 9309+ ).appendTo( $paramRow );
 9310+ $( '<td />' ).addClass( 'wikiEditor-template-dialog-value' ).append(
 9311+ $( '<input />' )
 9312+ .data( 'name', param.name )
 9313+ .val( templateModel.getValue( param.name ) )
 9314+ ).appendTo( $paramRow );
 9315+ $table.append( $paramRow );
 9316+ }
92679317 }
9268 - var $paramRow = $( '<tr />' )
9269 - .addClass( 'wikiEditor-template-dialog-row' );
9270 - var $paramName = $( '<td />' )
9271 - .addClass( 'wikiEditor-template-dialog-name' )
9272 - .text(
9273 - param.name.replace( /[\_\-]/g, ' ' ).replace( /^(.)|\s(.)/g, function ( first ) {
9274 - return first.toUpperCase();
9275 - } )
9276 - );
9277 - var $paramVal = $( '<td />' )
9278 - .addClass( 'wikiEditor-template-dialog-value' );
9279 - var $paramInput = $( '<input />' )
9280 - .data( 'name', param.name )
9281 - .val( templateModel.getValue( param.name ) );
9282 - $paramVal.append( $paramInput );
9283 - $paramRow.append( $paramName ).append( $paramVal );
9284 - $table.append( $paramRow );
92859318 }
9286 - //click handler for values
9287 - $( '<button />' ).click( function() {
9288 - // More user feedback
9289 - context.fn.highlightLine( $templateDiv );
9290 - //
9291 - $( '.wikiEditor-template-dialog-value input' ).each( function(){
9292 - templateModel.setValue( $(this).data( 'name' ), $(this).val() );
9293 - });
9294 - //keep text consistent
9295 - $wikitext.text( templateModel.getText() );
9296 -
9297 - $dialog.dialog( 'close' );
9298 -
9299 - }).text( 'OK' ).appendTo( $dialog ); // FIXME: Internationalize 'OK'
9300 - $dialog.dialog(); //opens dialog
9301 - return false;
93029319 };
93039320
9304 - function toggleWikiText() {
9305 - var $template = $( this ).closest( '.wikiEditor-template' );
9306 - $template
9307 - .toggleClass( 'wikiEditor-template-collapsed' )
9308 - .toggleClass( 'wikiEditor-template-expanded' )
9309 - .children( '.wikiEditor-template-text, .wikiEditor-template-name, .wikiEditor-template-modes' )
9310 - .toggleClass( 'wikiEditor-nodisplay' );
9311 -
9312 - //if we just collapsed this
9313 - if ( $template.hasClass( 'wikiEditor-template-collapsed' ) ) {
9314 - var model = new $.wikiEditor.modules.templateEditor.fn.model(
9315 - $template.children( '.wikiEditor-template-text' ).text()
9316 - );
9317 - $template.data( 'model' , model );
9318 - $template.children( '.wikiEditor-template-name' ).text( model.getName() );
9319 - } else{ //else we just expanded this
9320 - $template.children( '.wikiEditor-template-text' ).children('.wikiEditor-template-inner-text').text(
9321 - $template.data('model')
9322 - .getText()
9323 - .replace(/\{\{/, '')
9324 - .replace(/\}\}$/, '')
9325 - );
9326 -
9327 - }
9328 - return false;
 9321+ function createDialog( $templateDiv ) {
 9322+ // Lazy-create the dialog at this time
 9323+ context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } );
 9324+ $( '#' + dialog.id )
 9325+ .data( 'templateDiv', $templateDiv )
 9326+ .dialog( 'open' );
93299327 }
93309328
93319329 function noEdit() {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -633,12 +633,15 @@
634634 $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked'))
635635 $('#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++;}
636636 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;}}}
637 -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(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;}
638 -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-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.imgPath+'/templateEditor/expand.png" width="12" height="16" />').append('<img src="'+$.wikiEditor.imgPath+'/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.imgPath+'/templateEditor/dialog-collapsed.png" width="22" height="16" />').append('<img src="'+$.wikiEditor.imgPath+'/templateEditor/dialog-expanded.png" width="22" height="16" style="display:none;" />').mousedown(function(){createDialog($template);return false;}).insertAfter($templateName);function toggleWikiTextEditor(){context.fn.refreshOffsets();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.data('model',model);$template.children('.wikiEditor-template-name').text(model.getName());}else{$wikitext.text($template.data('model').getText());}
639 -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());};function createDialog($templateDiv){context.fn.highlightLine($templateDiv);var $wikitext=$templateDiv.children('.wikiEditor-template-text');var templateModel=new $.wikiEditor.modules.templateEditor.fn.model($wikitext.text());$templateDiv.data('model',templateModel);var $dialog=$('<div />');var $title=$(' <div />').text(templateModel.getName()).addClass('wikiEditor-template-dialog-title');var $table=$('<table />').addClass('wikiEditor-template-dialog-table').appendTo($dialog);var allInitialParams=templateModel.getAllInitialParams();for(var paramIndex in allInitialParams){var param=allInitialParams[paramIndex];if(typeof param.name=='undefined'){continue;}
640 -var $paramRow=$('<tr />').addClass('wikiEditor-template-dialog-row');var $paramName=$('<td />').addClass('wikiEditor-template-dialog-name').text(param.name.replace(/[\_\-]/g,' ').replace(/^(.)|\s(.)/g,function(first){return first.toUpperCase();}));var $paramVal=$('<td />').addClass('wikiEditor-template-dialog-value');var $paramInput=$('<input />').data('name',param.name).val(templateModel.getValue(param.name));$paramVal.append($paramInput);$paramRow.append($paramName).append($paramVal);$table.append($paramRow);}
641 -$('<button />').click(function(){context.fn.highlightLine($templateDiv);$('.wikiEditor-template-dialog-value input').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$wikitext.text(templateModel.getText());$dialog.dialog('close');}).text('OK').appendTo($dialog);$dialog.dialog();return false;};function toggleWikiText(){var $template=$(this).closest('.wikiEditor-template');$template.toggleClass('wikiEditor-template-collapsed').toggleClass('wikiEditor-template-expanded').children('.wikiEditor-template-text, .wikiEditor-template-name, .wikiEditor-template-modes').toggleClass('wikiEditor-nodisplay');if($template.hasClass('wikiEditor-template-collapsed')){var model=new $.wikiEditor.modules.templateEditor.fn.model($template.children('.wikiEditor-template-text').text());$template.data('model',model);$template.children('.wikiEditor-template-name').text(model.getName());}else{$template.children('.wikiEditor-template-text').children('.wikiEditor-template-inner-text').text($template.data('model').getText().replace(/\{\{/,'').replace(/\}\}$/,''));}
642 -return false;}
 637+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;}
 638+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.addClass('wikiEditor-template-text').wrap('<span class="wikiEditor-template"></span>').addClass('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());}
 639+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':'\
 640+ <fieldset>\
 641+ <div class="wikiEditor-template-dialog-title" />\
 642+ <table class="wikiEditor-template-dialog-table" />\
 643+ </fieldset>',init:function(){$(this).find('[rel]').each(function(){$(this).text(mw.usability.getMsg($(this).attr('rel')));});},dialog:{width:500,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);}
 644+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;}
 645+var $paramRow=$('<tr />').addClass('wikiEditor-template-dialog-row');$('<td />').addClass('wikiEditor-template-dialog-name').text(typeof param=='string'?param.name.replace(/[\_\-]/g,' ').replace(/^(.)|\s(.)/g,function(first){return first.toUpperCase();}):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');}
643646 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;}
644647 function Range(begin,end){this.begin=begin;this.end=end;}
645648 function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";}

Follow-up revisions

RevisionCommit summaryAuthorDate
r63122UsabilityInitiative: Fix r63094, r63121 per CRcatrope17:24, 1 March 2010

Status & tagging log