r63629 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63628‎ | r63629 | r63630 >
Date:04:43, 12 March 2010
Author:nimishg
Status:resolved (Comments)
Tags:
Comment:
keydown handler for templateEditor, slightly monsterous due to lack of key binding events in a content-editable iframe
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' => 163 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 164 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 40 ),
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' => 50 ),
 82+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 51 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 325 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 326 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 325 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 326 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -116,7 +116,22 @@
117117 }
118118 }//if opentemplates
119119 }
120 - }
 120+ }, //mark
 121+
 122+ keydown: function( context, event ){
 123+ var $evtElem = event.jQueryNode;
 124+ if ( $evtElem ) {
 125+ if( $evtElem.hasClass( 'wikiEditor-template-name' ) ){
 126+ switch ( event.which ) {
 127+ case 37://left
 128+ case 38://up
 129+ case 39://right
 130+ case 40: return true;//down
 131+ default: return false; //can't type in a template name
 132+ }
 133+ }
 134+ }
 135+ } //keydown
121136 },
122137 /**
123138 * Regular expressions that produce tokens
@@ -181,7 +196,8 @@
182197 var $template = $wrapper.parent( '.wikiEditor-template' );
183198 $template.find( '.wikiEditor-template-name' )
184199 .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } )
185 - .mousedown( function() { return false; } );
 200+ .mousedown( function() { return false; } )
 201+ .data("keydownHandler", function(){console.log("CARLOS!");});
186202 $template.find( '.wikiEditor-template-expand' )
187203 .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } )
188204 .mousedown( function() { return false; } );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -521,6 +521,8 @@
522522 return false;
523523 }
524524 }
 525+
 526+ var returnFromModules = null; //they return null by default
525527 // Pass the event around to all modules activated on this context
526528 for ( var module in context.modules ) {
527529 if (
@@ -528,10 +530,22 @@
529531 'evt' in $.wikiEditor.modules[module] &&
530532 name in $.wikiEditor.modules[module].evt
531533 ) {
532 - $.wikiEditor.modules[module].evt[name]( context, event );
 534+ var ret = $.wikiEditor.modules[module].evt[name]( context, event );
 535+ if(ret != null){
 536+ //if 1 returns false, the end result is false
 537+ if( returnFromModules == null ) {
 538+ returnFromModules = ret;
 539+ } else {
 540+ returnFromModules = returnFromModules && ret;
 541+ }
 542+ }
533543 }
534544 }
535 - return true;
 545+ if(returnFromModules != null){
 546+ return returnFromModules;
 547+ } else{
 548+ return true;
 549+ }
536550 },
537551 /**
538552 * Adds a button to the UI
@@ -1111,7 +1125,10 @@
11121126 // Setup event handling on the iframe
11131127 $( context.$iframe[0].contentWindow.document )
11141128 .bind( 'keydown', function( event ) {
 1129+ var $cElem = context.fn.getElementAtCursor();
 1130+ event.jQueryNode = $cElem
11151131 return context.fn.trigger( 'keydown', event );
 1132+
11161133 } )
11171134 .bind( 'paste', function( event ) {
11181135 return context.fn.trigger( 'paste', event );
@@ -1148,6 +1165,20 @@
11491166 * equivilant functionality to the otherwise textarea-based functionality.
11501167 */
11511168
 1169+ 'getElementAtCursor': function(){
 1170+ //firefox only
 1171+ if ( context.$iframe[0].contentWindow.getSelection ) {
 1172+ var selection = context.$iframe[0].contentWindow.getSelection();
 1173+ if ( selection.rangeCount == 0 ) {
 1174+ // We don't know where the cursor is
 1175+ return null;
 1176+ }
 1177+ var sc = selection.getRangeAt( 0 ).startContainer;
 1178+ return $( sc.parentNode ).eq( 0 );
 1179+ }
 1180+ else return null;
 1181+ },
 1182+
11521183 /**
11531184 * Gets the complete contents of the iframe (in plain text, not HTML)
11541185 */
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7064,6 +7064,8 @@
70657065 return false;
70667066 }
70677067 }
 7068+
 7069+ var returnFromModules = null; //they return null by default
70687070 // Pass the event around to all modules activated on this context
70697071 for ( var module in context.modules ) {
70707072 if (
@@ -7071,10 +7073,22 @@
70727074 'evt' in $.wikiEditor.modules[module] &&
70737075 name in $.wikiEditor.modules[module].evt
70747076 ) {
7075 - $.wikiEditor.modules[module].evt[name]( context, event );
 7077+ var ret = $.wikiEditor.modules[module].evt[name]( context, event );
 7078+ if(ret != null){
 7079+ //if 1 returns false, the end result is false
 7080+ if( returnFromModules == null ) {
 7081+ returnFromModules = ret;
 7082+ } else {
 7083+ returnFromModules = returnFromModules && ret;
 7084+ }
 7085+ }
70767086 }
70777087 }
7078 - return true;
 7088+ if(returnFromModules != null){
 7089+ return returnFromModules;
 7090+ } else{
 7091+ return true;
 7092+ }
70797093 },
70807094 /**
70817095 * Adds a button to the UI
@@ -7654,7 +7668,10 @@
76557669 // Setup event handling on the iframe
76567670 $( context.$iframe[0].contentWindow.document )
76577671 .bind( 'keydown', function( event ) {
 7672+ var $cElem = context.fn.getElementAtCursor();
 7673+ event.jQueryNode = $cElem
76587674 return context.fn.trigger( 'keydown', event );
 7675+
76597676 } )
76607677 .bind( 'paste', function( event ) {
76617678 return context.fn.trigger( 'paste', event );
@@ -7691,6 +7708,20 @@
76927709 * equivilant functionality to the otherwise textarea-based functionality.
76937710 */
76947711
 7712+ 'getElementAtCursor': function(){
 7713+ //firefox only
 7714+ if ( context.$iframe[0].contentWindow.getSelection ) {
 7715+ var selection = context.$iframe[0].contentWindow.getSelection();
 7716+ if ( selection.rangeCount == 0 ) {
 7717+ // We don't know where the cursor is
 7718+ return null;
 7719+ }
 7720+ var sc = selection.getRangeAt( 0 ).startContainer;
 7721+ return $( sc.parentNode ).eq( 0 );
 7722+ }
 7723+ else return null;
 7724+ },
 7725+
76957726 /**
76967727 * Gets the complete contents of the iframe (in plain text, not HTML)
76977728 */
@@ -9359,7 +9390,22 @@
93609391 }
93619392 }//if opentemplates
93629393 }
9363 - }
 9394+ }, //mark
 9395+
 9396+ keydown: function( context, event ){
 9397+ var $evtElem = event.jQueryNode;
 9398+ if ( $evtElem ) {
 9399+ if( $evtElem.hasClass( 'wikiEditor-template-name' ) ){
 9400+ switch ( event.which ) {
 9401+ case 37://left
 9402+ case 38://up
 9403+ case 39://right
 9404+ case 40: return true;//down
 9405+ default: return false; //can't type in a template name
 9406+ }
 9407+ }
 9408+ }
 9409+ } //keydown
93649410 },
93659411 /**
93669412 * Regular expressions that produce tokens
@@ -9424,7 +9470,8 @@
94259471 var $template = $wrapper.parent( '.wikiEditor-template' );
94269472 $template.find( '.wikiEditor-template-name' )
94279473 .click( function() { $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); return false; } )
9428 - .mousedown( function() { return false; } );
 9474+ .mousedown( function() { return false; } )
 9475+ .data("keydownHandler", function(){console.log("CARLOS!");});
94299476 $template.find( '.wikiEditor-template-expand' )
94309477 .click( function() { $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); return false; } )
94319478 .mousedown( function() { return false; } );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -473,8 +473,8 @@
474474 context.fn.purgeOffsets();var restoreTo=cursorPos[1]+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'};}
475475 if(typeof event.data=='undefined'){event.data={};}
476476 if(name in context.evt){if(!context.evt[name](event)){return false;}}
477 -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);}}
478 -return true;},'addButton':function(options){context.$controls.show();context.$buttons.show();return $('<button />').text($.wikiEditor.autoMsg(options,'caption')).click(options.action).appendTo(context.$buttons);},'addView':function(options){function addTab(options){context.$controls.show();context.$tabs.show();return $('<div></div>').attr('rel','wikiEditor-ui-view-'+options.name).addClass(context.view==options.name?'current':null).append($('<a></a>').attr('href','#').mousedown(function(){return false;}).click(function(event){context.$ui.find('.wikiEditor-ui-view').hide();context.$ui.find('.'+$(this).parent().attr('rel')).show();context.$tabs.find('div').removeClass('current');$(this).parent().addClass('current');$(this).blur();if('init'in options&&typeof options.init=='function'){options.init(context);}
 477+var returnFromModules=null;for(var module in context.modules){if(module in $.wikiEditor.modules&&'evt'in $.wikiEditor.modules[module]&&name in $.wikiEditor.modules[module].evt){var ret=$.wikiEditor.modules[module].evt[name](context,event);if(ret!=null){if(returnFromModules==null){returnFromModules=ret;}else{returnFromModules=returnFromModules&&ret;}}}}
 478+if(returnFromModules!=null){return returnFromModules;}else{return true;}},'addButton':function(options){context.$controls.show();context.$buttons.show();return $('<button />').text($.wikiEditor.autoMsg(options,'caption')).click(options.action).appendTo(context.$buttons);},'addView':function(options){function addTab(options){context.$controls.show();context.$tabs.show();return $('<div></div>').attr('rel','wikiEditor-ui-view-'+options.name).addClass(context.view==options.name?'current':null).append($('<a></a>').attr('href','#').mousedown(function(){return false;}).click(function(event){context.$ui.find('.wikiEditor-ui-view').hide();context.$ui.find('.'+$(this).parent().attr('rel')).show();context.$tabs.find('div').removeClass('current');$(this).parent().addClass('current');$(this).blur();if('init'in options&&typeof options.init=='function'){options.init(context);}
479479 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
480480 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
481481 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'highlightLine':function($element,mode){if(!$element.is('p')){$element=$element.closest('p');}
@@ -519,7 +519,10 @@
520520 context.oldDelayedHistoryPosition=context.historyPosition;},'setupIframe':function(){context.$iframe=$('<iframe></iframe>').attr({'frameBorder':0,'border':0,'tabindex':1,'src':wgScriptPath+'/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?'+'instance='+context.instance+'&ts='+(new Date()).getTime()+'&is=content','id':'wikiEditor-iframe-'+context.instance}).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none','overflow-y':'scroll','overflow-x':'hidden'}).insertAfter(context.$textarea).load(function(){if(!this.isSecondRun){context.$iframe[0].contentWindow.document.designMode='on';if($.browser.msie){this.isSecondRun=true;return;}}
521521 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;");}}
522522 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');}
523 -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){return context.fn.trigger('keydown',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();}};},'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();}
 523+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){var $cElem=context.fn.getElementAtCursor();event.jQueryNode=$cElem
 524+return context.fn.trigger('keydown',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 null;}
 525+var sc=selection.getRangeAt(0).startContainer;return $(sc.parentNode).eq(0);}
 526+else return null;},'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();}
524527 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();}
525528 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(typeof retval.toString!='undefined'){retval=retval.toString();}
526529 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+=' ';}
@@ -647,7 +650,7 @@
648651 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;}}}
649652 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;}
650653 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));$.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':'\
 654+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){var $evtElem=event.jQueryNode;if($evtElem){if($evtElem.hasClass('wikiEditor-template-name')){switch(event.which){case 37:case 38:case 39:case 40:return true;default:return false;}}}}},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;}).data("keydownHandler",function(){console.log("CARLOS!");});$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':'\
652655 <fieldset>\
653656 <div class="wikiEditor-template-dialog-title" />\
654657 <div class="wikiEditor-template-dialog-fields" />\

Follow-up revisions

RevisionCommit summaryAuthorDate
r63662UsabilityInitiative: Followup to r63629: make getElementAtCursor() always ret...catrope23:04, 12 March 2010

Comments

#Comment by Catrope (talk | contribs)   13:37, 12 March 2010
+			.data("keydownHandler", function(){console.log("CARLOS!");});

That's a very original debugging phrase ;)

+			var returnFromModules = null; //they return null by default

We should simply enforce that all evt handlers return true or false. The MediaWiki hook system, for instance, also does this.

#Comment by Nimish Gautam (talk | contribs)   18:12, 12 March 2010

Ha, yeah, I left some debugging info...fixed that (and more!) in r63635

Status & tagging log