Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,20 +72,20 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 151 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 152 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 34 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 50 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 18 ), |
80 | 80 | array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 93 ), |
81 | 81 | array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ), |
82 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 24 ), |
| 82 | + array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 25 ), |
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' => 283 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 284 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 283 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 284 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -401,6 +401,10 @@ |
402 | 402 | return true; |
403 | 403 | }, |
404 | 404 | 'paste': function( event ) { |
| 405 | + // Save the cursor position to restore it after all this voodoo |
| 406 | + var cursorPos = context.fn.getCaretPosition(); |
| 407 | + var oldLength = context.fn.getContents().length; |
| 408 | + |
405 | 409 | context.$content.find( ':not(.wikiEditor)' ).addClass( 'wikiEditor' ); |
406 | 410 | if ( $.layout.name !== 'webkit' ) { |
407 | 411 | context.$content.addClass( 'pasting' ); |
— | — | @@ -478,6 +482,11 @@ |
479 | 483 | if ( $.layout.name !== 'webkit' ) { |
480 | 484 | context.$content.removeClass( 'pasting' ); |
481 | 485 | } |
| 486 | + |
| 487 | + // Restore cursor position |
| 488 | + context.fn.purgeOffsets(); |
| 489 | + var restoreTo = cursorPos[0] + context.fn.getContents().length - oldLength; |
| 490 | + context.fn.setSelection( { start: restoreTo, end: restoreTo } ); |
482 | 491 | }, 0 ); |
483 | 492 | return true; |
484 | 493 | }, |
— | — | @@ -1514,6 +1523,14 @@ |
1515 | 1524 | ec = e ? e.node : null; |
1516 | 1525 | start = s ? s.offset : null; |
1517 | 1526 | end = e ? e.offset : null; |
| 1527 | + // Don't try to set the selection past the end of a node, causes errors |
| 1528 | + // Just put the selection at the end of the node in this case |
| 1529 | + if ( sc.nodeName == '#text' && start >= sc.nodeValue.length ) { |
| 1530 | + start = sc.nodeValue.length - 1; |
| 1531 | + } |
| 1532 | + if ( ec.nodeName == '#text' && end >= ec.nodeValue.length ) { |
| 1533 | + end = ec.nodeValue.length - 1; |
| 1534 | + } |
1518 | 1535 | } |
1519 | 1536 | if ( !sc || !ec ) { |
1520 | 1537 | // The requested offset isn't in the offsets array |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6834,6 +6834,10 @@ |
6835 | 6835 | return true; |
6836 | 6836 | }, |
6837 | 6837 | 'paste': function( event ) { |
| 6838 | + // Save the cursor position to restore it after all this voodoo |
| 6839 | + var cursorPos = context.fn.getCaretPosition(); |
| 6840 | + var oldLength = context.fn.getContents().length; |
| 6841 | + |
6838 | 6842 | context.$content.find( ':not(.wikiEditor)' ).addClass( 'wikiEditor' ); |
6839 | 6843 | if ( $.layout.name !== 'webkit' ) { |
6840 | 6844 | context.$content.addClass( 'pasting' ); |
— | — | @@ -6911,6 +6915,11 @@ |
6912 | 6916 | if ( $.layout.name !== 'webkit' ) { |
6913 | 6917 | context.$content.removeClass( 'pasting' ); |
6914 | 6918 | } |
| 6919 | + |
| 6920 | + // Restore cursor position |
| 6921 | + context.fn.purgeOffsets(); |
| 6922 | + var restoreTo = cursorPos[0] + context.fn.getContents().length - oldLength; |
| 6923 | + context.fn.setSelection( { start: restoreTo, end: restoreTo } ); |
6915 | 6924 | }, 0 ); |
6916 | 6925 | return true; |
6917 | 6926 | }, |
— | — | @@ -7947,6 +7956,14 @@ |
7948 | 7957 | ec = e ? e.node : null; |
7949 | 7958 | start = s ? s.offset : null; |
7950 | 7959 | end = e ? e.offset : null; |
| 7960 | + // Don't try to set the selection past the end of a node, causes errors |
| 7961 | + // Just put the selection at the end of the node in this case |
| 7962 | + if ( sc.nodeName == '#text' && start >= sc.nodeValue.length ) { |
| 7963 | + start = sc.nodeValue.length - 1; |
| 7964 | + } |
| 7965 | + if ( ec.nodeName == '#text' && end >= ec.nodeValue.length ) { |
| 7966 | + end = ec.nodeValue.length - 1; |
| 7967 | + } |
7951 | 7968 | } |
7952 | 7969 | if ( !sc || !ec ) { |
7953 | 7970 | // The requested offset isn't in the offsets array |
— | — | @@ -9042,7 +9059,8 @@ |
9043 | 9060 | return $( ca1.parentNode ).is( 'span.wikiEditor-template-text' ) ? |
9044 | 9061 | ca1.parentNode : null; |
9045 | 9062 | }, |
9046 | | - model: model |
| 9063 | + model: model, |
| 9064 | + context: context |
9047 | 9065 | } ); |
9048 | 9066 | } else { //else this was an unmatched opening |
9049 | 9067 | tokenArray[beginIndex].label = 'TEMPLATE_FALSE_BEGIN'; |
— | — | @@ -9084,10 +9102,11 @@ |
9085 | 9103 | return; |
9086 | 9104 | } |
9087 | 9105 | var model = $(this).data( 'marker' ).model; |
| 9106 | + var context = $(this).data( 'marker' ).context; |
9088 | 9107 | |
9089 | 9108 | //check if model is collapsible |
9090 | 9109 | if ( !model.isCollapsible() ) { |
9091 | | - $(this).addClass( 'wikiEditor-template-text' ); |
| 9110 | + //just treat it as normal text for now |
9092 | 9111 | return; |
9093 | 9112 | } |
9094 | 9113 | |
— | — | @@ -9117,19 +9136,11 @@ |
9118 | 9137 | .append( '<img src="'+$.wikiEditor.imgPath+'/templateEditor/dialog-expanded.png" width="22" height="16" style="display:none;" />' ) |
9119 | 9138 | .mousedown( function() { createDialog( $template ); return false; } ) |
9120 | 9139 | .insertAfter( $templateName ); |
9121 | | - /* |
9122 | | - var $options = $( '<ul />' ) |
9123 | | - .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' ) |
9124 | | - .append( $( '<li />' ) |
9125 | | - .addClass( 'wikiEditor-template-action-wikiText' ) |
9126 | | - .append( $( '<img />' ).attr( 'src', |
9127 | | - $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) ) |
9128 | | - .mousedown( toggleWikiTextEditor ) ) |
9129 | | - .insertAfter( $template.find( '.wikiEditor-template-name' ) ); |
9130 | | - */ |
| 9140 | + |
9131 | 9141 | $(this).data( 'setupDone', true ); |
9132 | 9142 | |
9133 | 9143 | function toggleWikiTextEditor(){ |
| 9144 | + context.fn.refreshOffsets(); |
9134 | 9145 | var $template = $( this ).closest( '.wikiEditor-template' ); |
9135 | 9146 | $template |
9136 | 9147 | .toggleClass( 'wikiEditor-template-expanded' ) |
— | — | @@ -9469,7 +9480,10 @@ |
9470 | 9481 | } |
9471 | 9482 | }; |
9472 | 9483 | |
9473 | | - |
| 9484 | + //not collapsing "small" templates |
| 9485 | + if( wikitext.length < 20 ){ |
| 9486 | + collapsible = false; |
| 9487 | + } |
9474 | 9488 | // Whitespace* {{ whitespace* nonwhitespace: |
9475 | 9489 | if ( wikitext.match( /\s*{{\s*\S*:/ ) ) { |
9476 | 9490 | collapsible = false; // is a parser function |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -456,7 +456,7 @@ |
457 | 457 | return true;},'change':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldHTML!=newHTML){context.fn.purgeOffsets();context.oldHTML=newHTML;event.data.scope='realchange';} |
458 | 458 | switch(event.which){case 8:break;} |
459 | 459 | return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.oldDelayedHTML=newHTML;event.data.scope='realchange';} |
460 | | -context.fn.updateHistory(event.data.scope=='realchange');return true;},'paste':function(event){context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');} |
| 460 | +context.fn.updateHistory(event.data.scope=='realchange');return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();var oldLength=context.fn.getContents().length;context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');} |
461 | 461 | setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,br,button').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});var t=context.fn.traverser(context.$content);while(t){if(t.node.nodeName=='#text'){if(t.node.nodeValue==='\n'){$('<p><br></p>').insertAfter($(t.node));var oldNode=t.node;t=t.next();$(oldNode).remove();continue;} |
462 | 462 | else if((t.node.nodeValue.indexOf('\n')!=1||t.node.nodeValue.indexOf('\r')!=-1)){t.node.nodeValue=t.node.nodeValue.replace(/\r|\n/g,' ');}} |
463 | 463 | t=t.next();} |
— | — | @@ -464,7 +464,8 @@ |
465 | 465 | var html=$('<div></div>').text($currentElement.text().replace(/\r|\n/g,' ')).html();if($currentElement.is('br')){$currentElement.addClass('wikiEditor');}else if($currentElement.is('span')&&html.length==0){$currentElement.remove();}else if($currentElement.is('p')||$currentElement.is('div')){$newElement=$('<p></p>').addClass('wikiEditor').insertAfter($currentElement);if(html.length){$newElement.html(html);}else{$newElement.append($('<br>').addClass('wikiEditor'));} |
466 | 466 | $currentElement.remove();}else{$newElement=$('<span></span>').html(html).insertAfter($currentElement);$newElement.replaceWith($newElement[0].childNodes);$currentElement.remove();} |
467 | 467 | $selection=context.$content.find(':not(.wikiEditor)');} |
468 | | -context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');}},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};} |
| 468 | +context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');} |
| 469 | +context.fn.purgeOffsets();var restoreTo=cursorPos[0]+context.fn.getContents().length-oldLength;context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};} |
469 | 470 | if(typeof event.data=='undefined'){event.data={};} |
470 | 471 | if(name in context.evt){if(!context.evt[name](event)){return false;}} |
471 | 472 | for(var module in context.modules){if(module in $.wikiEditor.modules&&'evt'in $.wikiEditor.modules[module]&&name in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt[name](context,event);}} |
— | — | @@ -547,7 +548,8 @@ |
548 | 549 | if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}} |
549 | 550 | if(!postFinished){if(postRange.compareEndPoints("StartToEnd",postRange)==0){postFinished=true;}else{postRange.moveEnd("character",-1) |
550 | 551 | if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));startPos=rawPreText.replace(/\r\n/g,"\n").length;endPos=startPos+rawPeriText.replace(/\r\n/g,"\n").length;}catch(e){startPos=endPos=0;}} |
551 | | -return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;} |
| 552 | +return[startPos,endPos];},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc&&sc.jquery?sc[0]:sc;ec=ec&&ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var start=options.start,end=options.end;if(!sc||!ec){var s=context.fn.getOffset(start);var e=context.fn.getOffset(end);sc=s?s.node:null;ec=e?e.node:null;start=s?s.offset:null;end=e?e.offset:null;if(sc.nodeName=='#text'&&start>=sc.nodeValue.length){start=sc.nodeValue.length-1;} |
| 553 | +if(ec.nodeName=='#text'&&end>=ec.nodeValue.length){end=ec.nodeValue.length-1;}} |
552 | 554 | if(!sc||!ec){return context.$textarea;} |
553 | 555 | var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;} |
554 | 556 | while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;} |
— | — | @@ -626,9 +628,9 @@ |
627 | 629 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
628 | 630 | $('#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++;} |
629 | 631 | 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;}}} |
630 | | -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:$.wikiEditor.modules.templateEditor.fn.stylize,beforeUnwrap:function(node){},onSkip:function(){},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('span.wikiEditor-template-text')?ca1.parentNode:null;},model:model});}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={};},stylize:function(wrappedTemplate){$(wrappedTemplate).each(function(){if(typeof $(this).data('setupDone')!='undefined'){return;} |
631 | | -var model=$(this).data('marker').model;if(!model.isCollapsible()){$(this).addClass('wikiEditor-template-text');return;} |
632 | | -var $template=$(this).wrap('<span class="wikiEditor-template"></span>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed').data('model',model);var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(toggleWikiTextEditor).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').append('<img src="'+$.wikiEditor.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);$(this).data('setupDone',true);function toggleWikiTextEditor(){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());} |
| 632 | +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:$.wikiEditor.modules.templateEditor.fn.stylize,beforeUnwrap:function(node){},onSkip:function(){},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={};},stylize:function(wrappedTemplate){$(wrappedTemplate).each(function(){if(typeof $(this).data('setupDone')!='undefined'){return;} |
| 633 | +var model=$(this).data('marker').model;var context=$(this).data('marker').context;if(!model.isCollapsible()){return;} |
| 634 | +var $template=$(this).wrap('<span class="wikiEditor-template"></span>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed').data('model',model);var $templateName=$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(toggleWikiTextEditor).prependTo($template);var $templateExpand=$('<span />').addClass('wikiEditor-template-expand wikiEditor-noinclude').append('<img src="'+$.wikiEditor.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);$(this).data('setupDone',true);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());} |
633 | 635 | else{$wikitext.text($template.data('model').getText());} |
634 | 636 | return false;};function expandTemplate($displayDiv){$displayDiv.removeClass('wikiEditor-template-collapsed');$displayDiv.addClass('wikiEditor-template-expanded');$displayDiv.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');$displayDiv.removeClass('wikiEditor-template-expanded');$displayDiv.text(model.getName());};function createDialog($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></div>");var $title=$("<div>"+templateModel.getName()+"</div>").addClass('wikiEditor-template-dialog-title');var $table=$("<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;} |
635 | 637 | var $paramRow=$("<tr></tr>").addClass('wikiEditor-template-dialog-row');var $paramName=$("<td></td>").addClass('wikiEditor-template-dialog-name').text(param.name);var $paramVal=$("<td></td>").addClass('wikiEditor-template-dialog-value');var $paramInput=$("<input></input>").data('name',param.name).val(templateModel.getValue(param.name));$paramVal.append($paramInput);$paramRow.append($paramName).append($paramVal);$table.append($paramRow);} |
— | — | @@ -646,7 +648,8 @@ |
647 | 649 | this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){if(typeof ranges[i].newVal=='undefined'){newText+=wikitext.substring(ranges[i].begin,ranges[i].end);}else{newText+=ranges[i].newVal;}} |
648 | 650 | return newText;};this.isCollapsible=function(){return collapsible;} |
649 | 651 | this.updateRanges=function(){var adjustment=0;for(var i=0;i<ranges.length;i++){ranges[i].begin+=adjustment;if(typeof ranges[i].adjust!='undefined'){adjustment+=ranges[i].adjust();delete ranges[i].adjust;} |
650 | | -ranges[i].end+=adjustment;}};if(wikitext.match(/\s*{{\s*\S*:/)){collapsible=false;} |
| 652 | +ranges[i].end+=adjustment;}};if(wikitext.length<20){collapsible=false;} |
| 653 | +if(wikitext.match(/\s*{{\s*\S*:/)){collapsible=false;} |
651 | 654 | var sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);if(endBraces){sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+ |
652 | 655 | sanatizedStr.substring(endBraces.index+2);} |
653 | 656 | while(sanatizedStr.indexOf('<!')!=-1){startIndex=sanatizedStr.indexOf('<!');endIndex=sanatizedStr.indexOf('-->')+3;sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/\S/g,' ');sanatizedStr=sanatizedStr.substring(0,startIndex)+sanatizedSegment+sanatizedStr.substring(endIndex);} |