Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -79,14 +79,14 @@ |
80 | 80 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 19 ), |
81 | 81 | array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 95 ), |
82 | 82 | 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 ), |
84 | 84 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ), |
85 | 85 | ), |
86 | 86 | 'combined' => array( |
87 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 294 ), |
| 87 | + array( 'src' => 'js/plugins.combined.js', 'version' => 295 ), |
88 | 88 | ), |
89 | 89 | 'minified' => array( |
90 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 294 ), |
| 90 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 295 ), |
91 | 91 | ), |
92 | 92 | ), |
93 | 93 | ); |
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php |
— | — | @@ -61,6 +61,10 @@ |
62 | 62 | ), |
63 | 63 | ), |
64 | 64 | ), |
| 65 | + 'messages' => array( |
| 66 | + 'wikieditor-template-editor-dialog-title', |
| 67 | + 'wikieditor-template-editor-dialog-submit', |
| 68 | + ), |
65 | 69 | ), |
66 | 70 | 'preview' => array( |
67 | 71 | 'i18n' => 'WikiEditorPreview', |
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/TemplateEditor/TemplateEditor.i18n.php |
— | — | @@ -13,6 +13,8 @@ |
14 | 14 | */ |
15 | 15 | $messages['en'] = array( |
16 | 16 | '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', |
17 | 19 | ); |
18 | 20 | |
19 | 21 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | afterWrap: function( node ) { |
76 | 76 | // Store model so we can compare it later |
77 | 77 | $( node ).data( 'model', $( node ).data( 'marker' ).model ); |
78 | | - if ( model.isCollapsible() ) { |
| 78 | + if ( $( node ).data( 'model' ).isCollapsible() ) { |
79 | 79 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
80 | 80 | } else { |
81 | 81 | $( node ).addClass( 'wikiEditor-template-text' ); |
— | — | @@ -150,6 +150,7 @@ |
151 | 151 | var context = $wrapper.data( 'marker' ).context; |
152 | 152 | |
153 | 153 | var $template = $wrapper |
| 154 | + .addClass( 'wikiEditor-template-text' ) |
154 | 155 | .wrap( '<span class="wikiEditor-template"></span>' ) |
155 | 156 | .addClass( 'wikiEditor-nodisplay' ) |
156 | 157 | .parent() |
— | — | @@ -164,20 +165,20 @@ |
165 | 166 | |
166 | 167 | var $templateExpand = $( '<span />' ) |
167 | 168 | .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;" />' ) |
170 | 171 | .mousedown( toggleWikiTextEditor ) |
171 | 172 | .prependTo( $template ); |
172 | 173 | |
173 | 174 | var $templateDialog = $( '<span />' ) |
174 | 175 | .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;" />' ) |
177 | 178 | .mousedown( function() { createDialog( $template ); return false; } ) |
178 | 179 | .insertAfter( $templateName ); |
179 | 180 | |
180 | 181 | function toggleWikiTextEditor() { |
181 | | - context.fn.refreshOffsets(); |
| 182 | + context.fn.purgeOffsets(); |
182 | 183 | var $template = $( this ).closest( '.wikiEditor-template' ); |
183 | 184 | $template |
184 | 185 | .toggleClass( 'wikiEditor-template-expanded' ) |
— | — | @@ -194,16 +195,17 @@ |
195 | 196 | var model = new $.wikiEditor.modules.templateEditor.fn.model( |
196 | 197 | $template.children( '.wikiEditor-template-text' ).text() |
197 | 198 | ); |
198 | | - $template.data( 'model' , model ); |
| 199 | + $template.children( '.wikiEditor-template-text' ).data( 'model', model ); |
199 | 200 | $template.children( '.wikiEditor-template-name' ).text( model.getName() ); |
200 | 201 | } else { //we just expanded this |
201 | | - $wikitext.text( $template.data( 'model' ).getText() ); |
| 202 | + $wikitext.text( $template.children( '.wikiEditor-template-text' ).data( 'model' ).getText() ); |
202 | 203 | } |
203 | 204 | |
204 | 205 | return false; |
205 | 206 | }; |
206 | 207 | |
207 | 208 | // Expand |
| 209 | + // FIXME: This function is unused |
208 | 210 | function expandTemplate( $displayDiv ) { |
209 | 211 | // Housekeeping |
210 | 212 | $displayDiv |
— | — | @@ -233,6 +235,7 @@ |
234 | 236 | } |
235 | 237 | }; |
236 | 238 | // Collapse |
| 239 | + // FIXME: This function is unused |
237 | 240 | function collapseTemplate( $displayDiv ) { |
238 | 241 | // Housekeeping |
239 | 242 | $displayDiv |
— | — | @@ -241,89 +244,84 @@ |
242 | 245 | .text( model.getName() ); |
243 | 246 | }; |
244 | 247 | |
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 | + } |
266 | 316 | } |
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 ); |
284 | 317 | } |
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; |
301 | 318 | }; |
302 | 319 | |
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' ); |
328 | 326 | } |
329 | 327 | |
330 | 328 | function noEdit() { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -9075,7 +9075,7 @@ |
9076 | 9076 | afterWrap: function( node ) { |
9077 | 9077 | // Store model so we can compare it later |
9078 | 9078 | $( node ).data( 'model', $( node ).data( 'marker' ).model ); |
9079 | | - if ( model.isCollapsible() ) { |
| 9079 | + if ( $( node ).data( 'model' ).isCollapsible() ) { |
9080 | 9080 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
9081 | 9081 | } else { |
9082 | 9082 | $( node ).addClass( 'wikiEditor-template-text' ); |
— | — | @@ -9151,6 +9151,7 @@ |
9152 | 9152 | var context = $wrapper.data( 'marker' ).context; |
9153 | 9153 | |
9154 | 9154 | var $template = $wrapper |
| 9155 | + .addClass( 'wikiEditor-template-text' ) |
9155 | 9156 | .wrap( '<span class="wikiEditor-template"></span>' ) |
9156 | 9157 | .addClass( 'wikiEditor-nodisplay' ) |
9157 | 9158 | .parent() |
— | — | @@ -9165,20 +9166,20 @@ |
9166 | 9167 | |
9167 | 9168 | var $templateExpand = $( '<span />' ) |
9168 | 9169 | .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;" />' ) |
9171 | 9172 | .mousedown( toggleWikiTextEditor ) |
9172 | 9173 | .prependTo( $template ); |
9173 | 9174 | |
9174 | 9175 | var $templateDialog = $( '<span />' ) |
9175 | 9176 | .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;" />' ) |
9178 | 9179 | .mousedown( function() { createDialog( $template ); return false; } ) |
9179 | 9180 | .insertAfter( $templateName ); |
9180 | 9181 | |
9181 | 9182 | function toggleWikiTextEditor() { |
9182 | | - context.fn.refreshOffsets(); |
| 9183 | + context.fn.purgeOffsets(); |
9183 | 9184 | var $template = $( this ).closest( '.wikiEditor-template' ); |
9184 | 9185 | $template |
9185 | 9186 | .toggleClass( 'wikiEditor-template-expanded' ) |
— | — | @@ -9195,16 +9196,17 @@ |
9196 | 9197 | var model = new $.wikiEditor.modules.templateEditor.fn.model( |
9197 | 9198 | $template.children( '.wikiEditor-template-text' ).text() |
9198 | 9199 | ); |
9199 | | - $template.data( 'model' , model ); |
| 9200 | + $template.children( '.wikiEditor-template-text' ).data( 'model', model ); |
9200 | 9201 | $template.children( '.wikiEditor-template-name' ).text( model.getName() ); |
9201 | 9202 | } else { //we just expanded this |
9202 | | - $wikitext.text( $template.data( 'model' ).getText() ); |
| 9203 | + $wikitext.text( $template.children( '.wikiEditor-template-text' ).data( 'model' ).getText() ); |
9203 | 9204 | } |
9204 | 9205 | |
9205 | 9206 | return false; |
9206 | 9207 | }; |
9207 | 9208 | |
9208 | 9209 | // Expand |
| 9210 | + // FIXME: This function is unused |
9209 | 9211 | function expandTemplate( $displayDiv ) { |
9210 | 9212 | // Housekeeping |
9211 | 9213 | $displayDiv |
— | — | @@ -9234,6 +9236,7 @@ |
9235 | 9237 | } |
9236 | 9238 | }; |
9237 | 9239 | // Collapse |
| 9240 | + // FIXME: This function is unused |
9238 | 9241 | function collapseTemplate( $displayDiv ) { |
9239 | 9242 | // Housekeeping |
9240 | 9243 | $displayDiv |
— | — | @@ -9242,89 +9245,84 @@ |
9243 | 9246 | .text( model.getName() ); |
9244 | 9247 | }; |
9245 | 9248 | |
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 | + } |
9267 | 9317 | } |
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 ); |
9285 | 9318 | } |
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; |
9302 | 9319 | }; |
9303 | 9320 | |
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' ); |
9329 | 9327 | } |
9330 | 9328 | |
9331 | 9329 | function noEdit() { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -633,12 +633,15 @@ |
634 | 634 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
635 | 635 | $('#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++;} |
636 | 636 | 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');} |
643 | 646 | 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;} |
644 | 647 | function Range(begin,end){this.begin=begin;this.end=end;} |
645 | 648 | function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";} |