Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -78,14 +78,14 @@ |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 21 ), |
80 | 80 | array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 97 ), |
81 | 81 | array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ), |
82 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 47 ), |
| 82 | + array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 48 ), |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 322 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 323 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 322 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 323 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -67,6 +67,7 @@ |
68 | 68 | var model = $.wikiEditor.modules.templateEditor.fn.updateModel( $( node ) ); |
69 | 69 | if ( model.isCollapsible() ) { |
70 | 70 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
| 71 | + $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); |
71 | 72 | } else { |
72 | 73 | $( node ).addClass( 'wikiEditor-template-text' ); |
73 | 74 | } |
— | — | @@ -100,6 +101,7 @@ |
101 | 102 | } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) && |
102 | 103 | model.isCollapsible() ) { |
103 | 104 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
| 105 | + $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); |
104 | 106 | } |
105 | 107 | }, |
106 | 108 | getAnchor: function( ca1, ca2 ) { |
— | — | @@ -148,43 +150,66 @@ |
149 | 151 | wrapTemplate: function( $wrapper ) { |
150 | 152 | var model = $wrapper.data( 'model' ); |
151 | 153 | var context = $wrapper.data( 'marker' ).context; |
152 | | - |
153 | 154 | var $template = $wrapper |
154 | 155 | .wrap( '<span class="wikiEditor-template"></span>' ) |
155 | 156 | .addClass( 'wikiEditor-template-text wikiEditor-nodisplay' ) |
156 | 157 | .parent() |
157 | 158 | .addClass( 'wikiEditor-template-collapsed' ); |
158 | | - |
159 | 159 | var $templateName = $( '<span />' ) |
160 | 160 | .addClass( 'wikiEditor-template-name wikiEditor-noinclude' ) |
161 | 161 | .text( model.getName() ) |
162 | | - .click( function() { createDialog( $template ); return false; } ) |
163 | | - .mousedown( function() { return false; } ) |
164 | 162 | .prependTo( $template ); |
165 | | - |
166 | 163 | var $templateExpand = $( '<span />' ) |
167 | 164 | .addClass( 'wikiEditor-template-expand wikiEditor-noinclude' ) |
168 | | - .click( toggleWikiTextEditor ) |
169 | | - .mousedown( function() { return false; } ) |
170 | 165 | .prependTo( $template ); |
171 | | - |
172 | 166 | var $templateDialog = $( '<span />' ) |
173 | 167 | .addClass( 'wikiEditor-template-dialog wikiEditor-noinclude' ) |
174 | | - .click( function() { createDialog( $template ); return false; } ) |
175 | | - .mousedown( function() { return false; } ) |
176 | 168 | .appendTo( $templateName ); |
177 | | - |
178 | | - function toggleWikiTextEditor() { |
179 | | - context.fn.purgeOffsets(); |
180 | | - $(this) |
181 | | - .closest( '.wikiEditor-template' ) |
182 | | - .toggleClass( 'wikiEditor-template-expanded' ) |
183 | | - .toggleClass( 'wikiEditor-template-collapsed' ) |
184 | | - .find( '.wikiEditor-template-text' ) |
185 | | - .toggleClass( 'wikiEditor-nodisplay' ); |
186 | | - return false; |
187 | | - }; |
188 | | - |
| 169 | + }, |
| 170 | + /** |
| 171 | + * Turn a complex template wrapper back into a simple one |
| 172 | + * @param $wrapper Wrapping <span> |
| 173 | + */ |
| 174 | + unwrapTemplate: function( $wrapper ) { |
| 175 | + $wrapper.parent().replaceWith( $wrapper ); |
| 176 | + }, |
| 177 | + /** |
| 178 | + * Bind events to a template |
| 179 | + * @param $wrapper Original wrapper for the template to bind events to |
| 180 | + */ |
| 181 | + bindTemplateEvents: function( $wrapper ) { |
| 182 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
| 183 | + $template.find( '.wikiEditor-template-name' ) |
| 184 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } ) |
| 185 | + .mousedown( function() { return false; } ); |
| 186 | + $template.find( '.wikiEditor-template-expand' ) |
| 187 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } ) |
| 188 | + .mousedown( function() { return false; } ); |
| 189 | + $template.find( '.wikiEditor-template-dialog' ) |
| 190 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } ) |
| 191 | + .mousedown( function() { return false; } ); |
| 192 | + }, |
| 193 | + /** |
| 194 | + * Toggle the visisbilty of the wikitext for a given template |
| 195 | + * @param $wrapper The origianl wrapper we want expand/collapse |
| 196 | + */ |
| 197 | + toggleWikiTextEditor: function( $wrapper ) { |
| 198 | + var context = $wrapper.data( 'marker' ).context; |
| 199 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
| 200 | + context.fn.purgeOffsets(); |
| 201 | + $template |
| 202 | + .toggleClass( 'wikiEditor-template-expanded' ) |
| 203 | + .toggleClass( 'wikiEditor-template-collapsed' ) |
| 204 | + .find( '.wikiEditor-template-text' ) |
| 205 | + .toggleClass( 'wikiEditor-nodisplay' ); |
| 206 | + }, |
| 207 | + /** |
| 208 | + * Create a dialog for editing a given template and open it |
| 209 | + * @param $wrapper The origianl wrapper for which to create the dialog |
| 210 | + */ |
| 211 | + createDialog: function( $wrapper ) { |
| 212 | + var context = $wrapper.data( 'marker' ).context; |
| 213 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
189 | 214 | var dialog = { |
190 | 215 | 'titleMsg': 'wikieditor-template-editor-dialog-title', |
191 | 216 | 'id': 'wikiEditor-template-dialog', |
— | — | @@ -207,7 +232,7 @@ |
208 | 233 | // More user feedback |
209 | 234 | var $templateDiv = $( this ).data( 'templateDiv' ); |
210 | 235 | context.fn.highlightLine( $templateDiv ); |
211 | | - |
| 236 | + |
212 | 237 | var $templateText = $templateDiv.children( '.wikiEditor-template-text' ); |
213 | 238 | var templateModel = $templateText.data( 'model' ); |
214 | 239 | $( this ).find( '.wikiEditor-template-dialog-field-wrapper textarea' ).each( function() { |
— | — | @@ -216,7 +241,7 @@ |
217 | 242 | }); |
218 | 243 | //keep text consistent |
219 | 244 | $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText, templateModel ); |
220 | | - |
| 245 | + |
221 | 246 | $( this ).dialog( 'close' ); |
222 | 247 | }, |
223 | 248 | 'wikieditor-template-editor-dialog-cancel': function() { |
— | — | @@ -231,7 +256,7 @@ |
232 | 257 | if ( $templateText.html() != $templateText.data( 'oldHTML' ) ) { |
233 | 258 | templateModel = $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText ); |
234 | 259 | } |
235 | | - |
| 260 | + |
236 | 261 | // Build the table |
237 | 262 | // TODO: Be smart and recycle existing table |
238 | 263 | var params = templateModel.getAllInitialParams(); |
— | — | @@ -294,7 +319,7 @@ |
295 | 320 | .appendTo( $fields ); |
296 | 321 | } |
297 | 322 | } |
298 | | - |
| 323 | + |
299 | 324 | // Remove any leftover rows |
300 | 325 | $rows.remove(); |
301 | 326 | $fields.find( 'label' ).autoEllipsis(); |
— | — | @@ -304,24 +329,13 @@ |
305 | 330 | } |
306 | 331 | } |
307 | 332 | }; |
308 | | - |
309 | | - function createDialog( $templateDiv ) { |
310 | | - // Lazy-create the dialog at this time |
311 | | - context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } ); |
312 | | - $( '#' + dialog.id ) |
313 | | - .data( 'templateDiv', $templateDiv ) |
314 | | - .dialog( 'open' ); |
315 | | - } |
| 333 | + // Lazy-create the dialog at this time |
| 334 | + context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } ); |
| 335 | + $( '#' + dialog.id ) |
| 336 | + .data( 'templateDiv', $template ) |
| 337 | + .dialog( 'open' ); |
316 | 338 | }, |
317 | 339 | /** |
318 | | - * Turn a complex template wrapper back into a simple one |
319 | | - * @param $wrapper Wrapping <span> |
320 | | - */ |
321 | | - unwrapTemplate: function( $wrapper ) { |
322 | | - $wrapper.parent().replaceWith( $wrapper ); |
323 | | - }, |
324 | | - |
325 | | - /** |
326 | 340 | * Update a template's model and HTML |
327 | 341 | * @param $templateText Wrapper <span> containing the template text |
328 | 342 | * @param model Template model to use, will be generated if not set |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -9310,6 +9310,7 @@ |
9311 | 9311 | var model = $.wikiEditor.modules.templateEditor.fn.updateModel( $( node ) ); |
9312 | 9312 | if ( model.isCollapsible() ) { |
9313 | 9313 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
| 9314 | + $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); |
9314 | 9315 | } else { |
9315 | 9316 | $( node ).addClass( 'wikiEditor-template-text' ); |
9316 | 9317 | } |
— | — | @@ -9343,6 +9344,7 @@ |
9344 | 9345 | } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) && |
9345 | 9346 | model.isCollapsible() ) { |
9346 | 9347 | $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); |
| 9348 | + $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); |
9347 | 9349 | } |
9348 | 9350 | }, |
9349 | 9351 | getAnchor: function( ca1, ca2 ) { |
— | — | @@ -9391,43 +9393,66 @@ |
9392 | 9394 | wrapTemplate: function( $wrapper ) { |
9393 | 9395 | var model = $wrapper.data( 'model' ); |
9394 | 9396 | var context = $wrapper.data( 'marker' ).context; |
9395 | | - |
9396 | 9397 | var $template = $wrapper |
9397 | 9398 | .wrap( '<span class="wikiEditor-template"></span>' ) |
9398 | 9399 | .addClass( 'wikiEditor-template-text wikiEditor-nodisplay' ) |
9399 | 9400 | .parent() |
9400 | 9401 | .addClass( 'wikiEditor-template-collapsed' ); |
9401 | | - |
9402 | 9402 | var $templateName = $( '<span />' ) |
9403 | 9403 | .addClass( 'wikiEditor-template-name wikiEditor-noinclude' ) |
9404 | 9404 | .text( model.getName() ) |
9405 | | - .click( function() { createDialog( $template ); return false; } ) |
9406 | | - .mousedown( function() { return false; } ) |
9407 | 9405 | .prependTo( $template ); |
9408 | | - |
9409 | 9406 | var $templateExpand = $( '<span />' ) |
9410 | 9407 | .addClass( 'wikiEditor-template-expand wikiEditor-noinclude' ) |
9411 | | - .click( toggleWikiTextEditor ) |
9412 | | - .mousedown( function() { return false; } ) |
9413 | 9408 | .prependTo( $template ); |
9414 | | - |
9415 | 9409 | var $templateDialog = $( '<span />' ) |
9416 | 9410 | .addClass( 'wikiEditor-template-dialog wikiEditor-noinclude' ) |
9417 | | - .click( function() { createDialog( $template ); return false; } ) |
9418 | | - .mousedown( function() { return false; } ) |
9419 | 9411 | .appendTo( $templateName ); |
9420 | | - |
9421 | | - function toggleWikiTextEditor() { |
9422 | | - context.fn.purgeOffsets(); |
9423 | | - $(this) |
9424 | | - .closest( '.wikiEditor-template' ) |
9425 | | - .toggleClass( 'wikiEditor-template-expanded' ) |
9426 | | - .toggleClass( 'wikiEditor-template-collapsed' ) |
9427 | | - .find( '.wikiEditor-template-text' ) |
9428 | | - .toggleClass( 'wikiEditor-nodisplay' ); |
9429 | | - return false; |
9430 | | - }; |
9431 | | - |
| 9412 | + }, |
| 9413 | + /** |
| 9414 | + * Turn a complex template wrapper back into a simple one |
| 9415 | + * @param $wrapper Wrapping <span> |
| 9416 | + */ |
| 9417 | + unwrapTemplate: function( $wrapper ) { |
| 9418 | + $wrapper.parent().replaceWith( $wrapper ); |
| 9419 | + }, |
| 9420 | + /** |
| 9421 | + * Bind events to a template |
| 9422 | + * @param $wrapper Original wrapper for the template to bind events to |
| 9423 | + */ |
| 9424 | + bindTemplateEvents: function( $wrapper ) { |
| 9425 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
| 9426 | + $template.find( '.wikiEditor-template-name' ) |
| 9427 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } ) |
| 9428 | + .mousedown( function() { return false; } ); |
| 9429 | + $template.find( '.wikiEditor-template-expand' ) |
| 9430 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } ) |
| 9431 | + .mousedown( function() { return false; } ); |
| 9432 | + $template.find( '.wikiEditor-template-dialog' ) |
| 9433 | + .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } ) |
| 9434 | + .mousedown( function() { return false; } ); |
| 9435 | + }, |
| 9436 | + /** |
| 9437 | + * Toggle the visisbilty of the wikitext for a given template |
| 9438 | + * @param $wrapper The origianl wrapper we want expand/collapse |
| 9439 | + */ |
| 9440 | + toggleWikiTextEditor: function( $wrapper ) { |
| 9441 | + var context = $wrapper.data( 'marker' ).context; |
| 9442 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
| 9443 | + context.fn.purgeOffsets(); |
| 9444 | + $template |
| 9445 | + .toggleClass( 'wikiEditor-template-expanded' ) |
| 9446 | + .toggleClass( 'wikiEditor-template-collapsed' ) |
| 9447 | + .find( '.wikiEditor-template-text' ) |
| 9448 | + .toggleClass( 'wikiEditor-nodisplay' ); |
| 9449 | + }, |
| 9450 | + /** |
| 9451 | + * Create a dialog for editing a given template and open it |
| 9452 | + * @param $wrapper The origianl wrapper for which to create the dialog |
| 9453 | + */ |
| 9454 | + createDialog: function( $wrapper ) { |
| 9455 | + var context = $wrapper.data( 'marker' ).context; |
| 9456 | + var $template = $wrapper.parent( '.wikiEditor-template' ); |
9432 | 9457 | var dialog = { |
9433 | 9458 | 'titleMsg': 'wikieditor-template-editor-dialog-title', |
9434 | 9459 | 'id': 'wikiEditor-template-dialog', |
— | — | @@ -9450,7 +9475,7 @@ |
9451 | 9476 | // More user feedback |
9452 | 9477 | var $templateDiv = $( this ).data( 'templateDiv' ); |
9453 | 9478 | context.fn.highlightLine( $templateDiv ); |
9454 | | - |
| 9479 | + |
9455 | 9480 | var $templateText = $templateDiv.children( '.wikiEditor-template-text' ); |
9456 | 9481 | var templateModel = $templateText.data( 'model' ); |
9457 | 9482 | $( this ).find( '.wikiEditor-template-dialog-field-wrapper textarea' ).each( function() { |
— | — | @@ -9459,7 +9484,7 @@ |
9460 | 9485 | }); |
9461 | 9486 | //keep text consistent |
9462 | 9487 | $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText, templateModel ); |
9463 | | - |
| 9488 | + |
9464 | 9489 | $( this ).dialog( 'close' ); |
9465 | 9490 | }, |
9466 | 9491 | 'wikieditor-template-editor-dialog-cancel': function() { |
— | — | @@ -9474,7 +9499,7 @@ |
9475 | 9500 | if ( $templateText.html() != $templateText.data( 'oldHTML' ) ) { |
9476 | 9501 | templateModel = $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText ); |
9477 | 9502 | } |
9478 | | - |
| 9503 | + |
9479 | 9504 | // Build the table |
9480 | 9505 | // TODO: Be smart and recycle existing table |
9481 | 9506 | var params = templateModel.getAllInitialParams(); |
— | — | @@ -9537,7 +9562,7 @@ |
9538 | 9563 | .appendTo( $fields ); |
9539 | 9564 | } |
9540 | 9565 | } |
9541 | | - |
| 9566 | + |
9542 | 9567 | // Remove any leftover rows |
9543 | 9568 | $rows.remove(); |
9544 | 9569 | $fields.find( 'label' ).autoEllipsis(); |
— | — | @@ -9547,24 +9572,13 @@ |
9548 | 9573 | } |
9549 | 9574 | } |
9550 | 9575 | }; |
9551 | | - |
9552 | | - function createDialog( $templateDiv ) { |
9553 | | - // Lazy-create the dialog at this time |
9554 | | - context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } ); |
9555 | | - $( '#' + dialog.id ) |
9556 | | - .data( 'templateDiv', $templateDiv ) |
9557 | | - .dialog( 'open' ); |
9558 | | - } |
| 9576 | + // Lazy-create the dialog at this time |
| 9577 | + context.$textarea.wikiEditor( 'addDialog', { 'templateEditor': dialog } ); |
| 9578 | + $( '#' + dialog.id ) |
| 9579 | + .data( 'templateDiv', $template ) |
| 9580 | + .dialog( 'open' ); |
9559 | 9581 | }, |
9560 | 9582 | /** |
9561 | | - * Turn a complex template wrapper back into a simple one |
9562 | | - * @param $wrapper Wrapping <span> |
9563 | | - */ |
9564 | | - unwrapTemplate: function( $wrapper ) { |
9565 | | - $wrapper.parent().replaceWith( $wrapper ); |
9566 | | - }, |
9567 | | - |
9568 | | - /** |
9569 | 9583 | * Update a template's model and HTML |
9570 | 9584 | * @param $templateText Wrapper <span> containing the template text |
9571 | 9585 | * @param model Template model to use, will be generated if not set |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -645,16 +645,16 @@ |
646 | 646 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
647 | 647 | $('#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++;} |
648 | 648 | 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;}}} |
649 | | -if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,type:'template',anchor:'wrap',afterWrap:function(node){var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if(model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));}else{$(node).addClass('wikiEditor-template-text');}},beforeUnwrap:function(node){if($(node).parent().hasClass('wikiEditor-template')){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}},onSkip:function(node){if($(node).html()==$(node).data('oldHTML')){return;} |
| 649 | +if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,type:'template',anchor:'wrap',afterWrap:function(node){var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if(model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));$.wikiEditor.modules.templateEditor.fn.bindTemplateEvents($(node));}else{$(node).addClass('wikiEditor-template-text');}},beforeUnwrap:function(node){if($(node).parent().hasClass('wikiEditor-template')){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}},onSkip:function(node){if($(node).html()==$(node).data('oldHTML')){return;} |
650 | 650 | var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if($(node).parent().hasClass('wikiEditor-template')){var $name=$(node).parent().children('.wikiEditor-template-name');if($name.text()!=model.getName()){$name.text(model.getName());}} |
651 | | -if($(node).parent().hasClass('wikiEditor-template')&&!model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}else if(!$(node).parent().hasClass('wikiEditor-template')&&model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));}},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');var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).click(function(){createDialog($template);return false;}).mousedown(function(){return false;}).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').click(toggleWikiTextEditor).mousedown(function(){return false;}).prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').click(function(){createDialog($template);return false;}).mousedown(function(){return false;}).appendTo($templateName);function toggleWikiTextEditor(){context.fn.purgeOffsets();$(this).closest('.wikiEditor-template').toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('.wikiEditor-template-text').toggleClass('wikiEditor-nodisplay');return false;};var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\ |
| 651 | +if($(node).parent().hasClass('wikiEditor-template')&&!model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.unwrapTemplate($(node));}else if(!$(node).parent().hasClass('wikiEditor-template')&&model.isCollapsible()){$.wikiEditor.modules.templateEditor.fn.wrapTemplate($(node));$.wikiEditor.modules.templateEditor.fn.bindTemplateEvents($(node));}},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('span.wikiEditor-template-text')?ca1.parentNode:null;},context:context});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],cfg:{},fn:{create:function(context,config){context.modules.templateEditor={};},wrapTemplate:function($wrapper){var model=$wrapper.data('model');var context=$wrapper.data('marker').context;var $template=$wrapper.wrap('<span class="wikiEditor-template"></span>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed');var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').prependTo($template);var $templateDialog=$('<span />').addClass('wikiEditor-template-dialog wikiEditor-noinclude').appendTo($templateName);},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},bindTemplateEvents:function($wrapper){var $template=$wrapper.parent('.wikiEditor-template');$template.find('.wikiEditor-template-name').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;});$template.find('.wikiEditor-template-expand').click(function(){$.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor($wrapper);return false;}).mousedown(function(){return false;});$template.find('.wikiEditor-template-dialog').click(function(){$.wikiEditor.modules.templateEditor.fn.createDialog($wrapper);return false;}).mousedown(function(){return false;});},toggleWikiTextEditor:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');context.fn.purgeOffsets();$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed').find('.wikiEditor-template-text').toggleClass('wikiEditor-nodisplay');},createDialog:function($wrapper){var context=$wrapper.data('marker').context;var $template=$wrapper.parent('.wikiEditor-template');var dialog={'titleMsg':'wikieditor-template-editor-dialog-title','id':'wikiEditor-template-dialog','html':'\ |
652 | 652 | <fieldset>\ |
653 | 653 | <div class="wikiEditor-template-dialog-title" />\ |
654 | 654 | <div class="wikiEditor-template-dialog-fields" />\ |
655 | 655 | </fieldset>',init:function(){$(this).find('[rel]').each(function(){$(this).text(mw.usability.getMsg($(this).attr('rel')));});},dialog:{width:600,height:400,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-field-wrapper textarea').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$.wikiEditor.modules.templateEditor.fn.updateModel($templateText,templateModel);$(this).dialog('close');},'wikieditor-template-editor-dialog-cancel':function(){$j(this).dialog('close');}},open:function(){var $templateDiv=$(this).data('templateDiv');var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');if($templateText.html()!=$templateText.data('oldHTML')){templateModel=$.wikiEditor.modules.templateEditor.fn.updateModel($templateText);} |
656 | 656 | var params=templateModel.getAllInitialParams();var $fields=$(this).find('.wikiEditor-template-dialog-fields');var $rows=$fields.find('.wikiEditor-template-dialog-field-wrapper');for(var paramIndex in params){var param=params[paramIndex];if(typeof param.name=='undefined'){continue;} |
657 | 657 | 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('label').text(paramText);$row.children('textarea').data('name',param.name).val(paramVal).change();$rows=$rows.not($row);}else{var $paramRow=$('<div />').addClass('wikiEditor-template-dialog-field-wrapper');$('<label />').text(paramText).appendTo($paramRow);$('<textarea />').data('name',param.name).val(paramVal).css('height',$(this).val().length>24?'4.5em':'1.5em').data('expanded',false).bind('cut paste keypress click change',function(e){if(e.keyCode=='9')return true;var $this=$(this);setTimeout(function(){var expanded=$this.data('expanded');if($this.val().indexOf('\n')!=-1||$this.val().length>24){if(!expanded){$this.animate({'height':'4.5em'},'fast');$this.data('expanded',true);}}else{if(expanded){$this.animate({'height':'1.5em'},'fast');$this.data('expanded',false);}}},0);}).appendTo($paramRow);$paramRow.append('<div style="clear:both"></div>').appendTo($fields);}} |
658 | | -$rows.remove();$fields.find('label').autoEllipsis();$(this).parent('.ui-dialog').find('.ui-dialog-titlebar-close').removeClass('ui-state-focus');}}};function createDialog($templateDiv){context.$textarea.wikiEditor('addDialog',{'templateEditor':dialog});$('#'+dialog.id).data('templateDiv',$templateDiv).dialog('open');}},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},updateModel:function($templateText,model){var context=$templateText.data('marker').context;var text;if(typeof model=='undefined'){text=context.fn.htmlToText($templateText.html());}else{text=model.getText();} |
| 658 | +$rows.remove();$fields.find('label').autoEllipsis();$(this).parent('.ui-dialog').find('.ui-dialog-titlebar-close').removeClass('ui-state-focus');}}};context.$textarea.wikiEditor('addDialog',{'templateEditor':dialog});$('#'+dialog.id).data('templateDiv',$template).dialog('open');},updateModel:function($templateText,model){var context=$templateText.data('marker').context;var text;if(typeof model=='undefined'){text=context.fn.htmlToText($templateText.html());}else{text=model.getText();} |
659 | 659 | $templateText.text(text);$templateText.html($templateText.html().replace(/\n/g,'<br />'));$templateText.data('oldHTML',$templateText.html());if(typeof model=='undefined'){model=new $.wikiEditor.modules.templateEditor.fn.model(text);$templateText.data('model',model);} |
660 | 660 | return model;},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;} |
661 | 661 | function Range(begin,end){this.begin=begin;this.end=end;} |