r63785 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63784‎ | r63785 | r63786 >
Date:22:07, 15 March 2010
Author:adam
Status:ok
Tags:
Comment:
Template Editor - partial fix for return keypress events in the template text
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,20 +72,20 @@
7373 array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 171 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 172 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 43 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 52 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 21 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 97 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
82 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 57 ),
 82+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 58 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 337 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 338 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 337 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 338 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -33,7 +33,6 @@
3434 var tokenArray = context.modules.highlight.tokenArray;
3535 // Collect matching level 0 template call boundaries from the tokenArray
3636 var level = 0;
37 -
3837 var tokenIndex = 0;
3938 while ( tokenIndex < tokenArray.length ){
4039 while ( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN' ) {
@@ -139,6 +138,8 @@
140139 } else if ( $evtElem.hasClass( 'wikiEditor-template-text' ) ) {
141140 switch ( event.which ) {
142141 case 13: //enter
 142+ // Ensure that the user can't break this by holding in the enter key
 143+ context.$iframe.data( 'ignoreKeypress', true );
143144 //FIXME: may be a more elegant way to do this, but this works too
144145 context.fn.encapsulateSelection( { 'pre':'\n', 'peri':'', 'post':'' } );
145146 return false;
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -1174,7 +1174,8 @@
11751175 return $( [] );
11761176 }
11771177 var sc = selection.getRangeAt( 0 ).startContainer;
1178 - return $( sc.parentNode );
 1178+ if ( sc.nodeName == "#text" ) sc = sc.parentNode;
 1179+ return $( sc );
11791180 } else {
11801181 return $( [] );
11811182 }
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7717,7 +7717,8 @@
77187718 return $( [] );
77197719 }
77207720 var sc = selection.getRangeAt( 0 ).startContainer;
7721 - return $( sc.parentNode );
 7721+ if ( sc.nodeName == "#text" ) sc = sc.parentNode;
 7722+ return $( sc );
77227723 } else {
77237724 return $( [] );
77247725 }
@@ -9277,7 +9278,6 @@
92789279 var tokenArray = context.modules.highlight.tokenArray;
92799280 // Collect matching level 0 template call boundaries from the tokenArray
92809281 var level = 0;
9281 -
92829282 var tokenIndex = 0;
92839283 while ( tokenIndex < tokenArray.length ){
92849284 while ( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN' ) {
@@ -9383,6 +9383,8 @@
93849384 } else if ( $evtElem.hasClass( 'wikiEditor-template-text' ) ) {
93859385 switch ( event.which ) {
93869386 case 13: //enter
 9387+ // Ensure that the user can't break this by holding in the enter key
 9388+ context.$iframe.data( 'ignoreKeypress', true );
93879389 //FIXME: may be a more elegant way to do this, but this works too
93889390 context.fn.encapsulateSelection( { 'pre':'\n', 'peri':'', 'post':'' } );
93899391 return false;
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -521,7 +521,7 @@
522522 context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val().replace(/&esc;/g,'&esc;esc;').replace(/\<p\>/g,'&esc;&lt;p&gt;').replace(/\<\/p\>/g,'&esc;&lt;/p&gt;').replace(/\<span class="wikiEditor-tab"\>\<\/span\>/g,'&esc;&lt;span&nbsp;class=&quot;wikiEditor-tab&quot;&gt;&lt;/span&gt;').replace(/&nbsp;/g,'&esc;&amp;nbsp;');if($.browser.msie){html=html.replace(/\t/g,'<span class="wikiEditor-tab"></span>');if($.browser.versionNumber<=7){html=html.replace(/ /g,"&nbsp;");}else{html=html.replace(/(^|\n) /g,"$1&nbsp;");}}
523523 html=$('<div />').text('<p>'+html.replace(/\r?\n/g,'</p><p>')+'</p>').html().replace(/&amp;nbsp;/g,'&nbsp;').replace(/&lt;p&gt;/g,'<p>').replace(/&lt;\/p&gt;/g,'</p>').replace(/&lt;span( |&nbsp;)class=("|&quot;)wikiEditor-tab("|&quot;)&gt;&lt;\/span&gt;/g,'<span class="wikiEditor-tab"></span>').replace(/<p><\/p>/g,'<p><br></p>').replace(/&amp;esc;&amp;amp;nbsp;/g,'&amp;nbsp;').replace(/&amp;esc;&amp;lt;p&amp;gt;/g,'&lt;p&gt;').replace(/&amp;esc;&amp;lt;\/p&amp;gt;/g,'&lt;/p&gt;').replace(/&amp;esc;&amp;lt;span&amp;nbsp;class=&amp;quot;wikiEditor-tab&amp;quot;&amp;gt;&amp;lt;\/span&amp;gt;/g,'&lt;span class="wikiEditor-tab"&gt;&lt;\/span&gt;').replace(/&amp;esc;esc;/g,'&amp;esc;');context.$content.html(html);if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
524524 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');context.oldHTML=context.oldDelayedHTML=context.$content.html();$(context.$iframe[0].contentWindow.document).bind('keydown',function(event){event.jQueryNode=context.fn.getElementAtCursor();return context.fn.trigger('keydown',event);}).bind('keyup',function(event){event.jQueryNode=context.fn.getElementAtCursor();return context.fn.trigger('keyup',event);}).bind('keypress',function(event){event.jQueryNode=context.fn.getElementAtCursor();return context.fn.trigger('keypress',event);}).bind('paste',function(event){return context.fn.trigger('paste',event);}).bind('cut',function(event){return context.fn.trigger('cut',event);}).bind('keyup paste mouseup cut encapsulateSelection',function(event){return context.fn.trigger('change',event);}).delayedBind(250,'keyup paste mouseup cut encapsulateSelection',function(event){context.fn.trigger('delayedChange',event);});});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});context.fallbackWindowOnBeforeUnload=window.onbeforeunload;window.onbeforeunload=function(){context.$textarea.val(context.$textarea.textSelection('getContents'));if(context.fallbackWindowOnBeforeUnload){return context.fallbackWindowOnBeforeUnload();}};},'getElementAtCursor':function(){if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.rangeCount==0){return $([]);}
525 -var sc=selection.getRangeAt(0).startContainer;return $(sc.parentNode);}else{return $([]);}},'getContents':function(){var html;if($.browser.msie){var $c=$(context.$content.get(0).cloneNode(true));$c.find('p').each(function(){if($(this).html()==''){$(this).replaceWith('<p></p>');}});html=$c.html();}else{html=context.$content.html();}
 525+var sc=selection.getRangeAt(0).startContainer;if(sc.nodeName=="#text")sc=sc.parentNode;return $(sc);}else{return $([]);}},'getContents':function(){var html;if($.browser.msie){var $c=$(context.$content.get(0).cloneNode(true));$c.find('p').each(function(){if($(this).html()==''){$(this).replaceWith('<p></p>');}});html=$c.html();}else{html=context.$content.html();}
526526 return context.fn.htmlToText(html);},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();if($.browser.opera){if(retval.rangeCount>0){retval=context.fn.htmlToText($('<pre />').append(retval.getRangeAt(0).cloneContents()).html());}else{retval='';}}}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
527527 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(typeof retval.toString!='undefined'){retval=retval.toString();}
528528 return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var collapseToEnd=false;var selectAfter=false;var setSelectionTo=null;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.peri==selText.replace(/\s+$/,'')){selText=selText.replace(/\s+$/,'');collapseToEnd=true;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
@@ -646,7 +646,7 @@
647647 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;}}}
648648 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;}
649649 var model=$.wikiEditor.modules.templateEditor.fn.updateModel($(node));if($(node).parent().hasClass('wikiEditor-template')){var $label=$(node).parent().find('.wikiEditor-template-label');if($label.text()!=model.getName()){$label.text(model.getName());}}
650 -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;}}}},keydown:function(context,event){if(context.$iframe.data('ignoreKeypress'))context.$iframe.data('ignoreKeypress',false);var $evtElem=event.jQueryNode;if($evtElem.hasClass('wikiEditor-template-name')){if(event.ctrlKey||event.metaKey)return true;switch(event.which){case 37:case 38:case 39:case 40:return true;default:context.$iframe.data('ignoreKeypress',true);return false;}}else if($evtElem.hasClass('wikiEditor-template-text')){switch(event.which){case 13:context.fn.encapsulateSelection({'pre':'\n','peri':'','post':''});return false;default:return true;}}},keyup:function(context,event){if(context.$iframe.data('ignoreKeypress'))context.$iframe.data('ignoreKeypress',false);return true;},keypress:function(context,event){return(context.$iframe.data('ignoreKeypress')?false:true);}},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').prepend($('<span class="wikiEditor-template-expand wikiEditor-noinclude"></span>'+'<span class="wikiEditor-template-name wikiEditor-noinclude">'+'<span class="wikiEditor-template-label wikiEditor-noinclude">'+model.getName()+'</span>'+'<span class="wikiEditor-template-dialog wikiEditor-noinclude"></span>'+'</span>'));},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;});},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':'\
 650+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;}}}},keydown:function(context,event){if(context.$iframe.data('ignoreKeypress'))context.$iframe.data('ignoreKeypress',false);var $evtElem=event.jQueryNode;if($evtElem.hasClass('wikiEditor-template-name')){if(event.ctrlKey||event.metaKey)return true;switch(event.which){case 37:case 38:case 39:case 40:return true;default:context.$iframe.data('ignoreKeypress',true);return false;}}else if($evtElem.hasClass('wikiEditor-template-text')){switch(event.which){case 13:context.$iframe.data('ignoreKeypress',true);context.fn.encapsulateSelection({'pre':'\n','peri':'','post':''});return false;default:return true;}}},keyup:function(context,event){if(context.$iframe.data('ignoreKeypress'))context.$iframe.data('ignoreKeypress',false);return true;},keypress:function(context,event){return(context.$iframe.data('ignoreKeypress')?false:true);}},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').prepend($('<span class="wikiEditor-template-expand wikiEditor-noinclude"></span>'+'<span class="wikiEditor-template-name wikiEditor-noinclude">'+'<span class="wikiEditor-template-label wikiEditor-noinclude">'+model.getName()+'</span>'+'<span class="wikiEditor-template-dialog wikiEditor-noinclude"></span>'+'</span>'));},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;});},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':'\
651651 <fieldset>\
652652 <div class="wikiEditor-template-dialog-title" />\
653653 <div class="wikiEditor-template-dialog-fields" />\

Status & tagging log