r62685 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62684‎ | r62685 | r62686 >
Date:00:49, 19 February 2010
Author:adam
Status:resolved (Comments)
Tags:
Comment:
WikiEditor - adding a ctrl+y handler for REDO in IE
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)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.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' => 142 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 143 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 33 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 49 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 17 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 268 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 269 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 268 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 269 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -306,7 +306,6 @@
307307 * processing of events which did not actually change the content of the iframe.
308308 */
309309 'keydown': function( event ) {
310 -
311310 switch ( event.which ) {
312311 case 90: // z
313312 if ( ( event.ctrlKey || event.metaKey ) && context.history.length ) {
@@ -343,6 +342,32 @@
344343 return false;
345344 }
346345 break;
 346+ case 89: //y
 347+ // ctrl + y handler for IE
 348+ if ( ( event.ctrlKey || event.metaKey ) && context.history.length && $.browser.msie ) {
 349+ newPosition = context.historyPosition + 1;
 350+ // Only act if we are switching to a valid state
 351+ if ( newPosition >= ( context.history.length * -1 ) && newPosition < 0 ) {
 352+ // Make sure we run the history storing code before we make this change
 353+ context.fn.updateHistory( context.oldDelayedHTML != context.$content.html() );
 354+ context.oldDelayedHistoryPosition = context.historyPosition;
 355+ context.historyPosition = newPosition;
 356+ // Change state
 357+ // FIXME: Destroys event handlers, will be a problem with template folding
 358+ context.$content.html(
 359+ context.history[context.history.length + context.historyPosition].html
 360+ );
 361+ context.fn.purgeOffsets();
 362+ if( context.history[context.history.length + context.historyPosition].sel ) {
 363+ context.fn.setSelection( {
 364+ start: context.history[context.history.length + context.historyPosition].sel[0],
 365+ end: context.history[context.history.length + context.historyPosition].sel[1]
 366+ } );
 367+ }
 368+ }
 369+ }
 370+ return false;
 371+ break;
347372 // Intercept all tab events to provide consisten behavior across browsers
348373 // Webkit browsers insert tab characters by default into the iframe rather than changing input focus
349374 case 9: //tab
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6739,7 +6739,6 @@
67406740 * processing of events which did not actually change the content of the iframe.
67416741 */
67426742 'keydown': function( event ) {
6743 -
67446743 switch ( event.which ) {
67456744 case 90: // z
67466745 if ( ( event.ctrlKey || event.metaKey ) && context.history.length ) {
@@ -6776,6 +6775,32 @@
67776776 return false;
67786777 }
67796778 break;
 6779+ case 89: //y
 6780+ // ctrl + y handler for IE
 6781+ if ( ( event.ctrlKey || event.metaKey ) && context.history.length && $.browser.msie ) {
 6782+ newPosition = context.historyPosition + 1;
 6783+ // Only act if we are switching to a valid state
 6784+ if ( newPosition >= ( context.history.length * -1 ) && newPosition < 0 ) {
 6785+ // Make sure we run the history storing code before we make this change
 6786+ context.fn.updateHistory( context.oldDelayedHTML != context.$content.html() );
 6787+ context.oldDelayedHistoryPosition = context.historyPosition;
 6788+ context.historyPosition = newPosition;
 6789+ // Change state
 6790+ // FIXME: Destroys event handlers, will be a problem with template folding
 6791+ context.$content.html(
 6792+ context.history[context.history.length + context.historyPosition].html
 6793+ );
 6794+ context.fn.purgeOffsets();
 6795+ if( context.history[context.history.length + context.historyPosition].sel ) {
 6796+ context.fn.setSelection( {
 6797+ start: context.history[context.history.length + context.historyPosition].sel[0],
 6798+ end: context.history[context.history.length + context.historyPosition].sel[1]
 6799+ } );
 6800+ }
 6801+ }
 6802+ }
 6803+ return false;
 6804+ break;
67806805 // Intercept all tab events to provide consisten behavior across browsers
67816806 // Webkit browsers insert tab characters by default into the iframe rather than changing input focus
67826807 case 9: //tab
@@ -6838,6 +6863,11 @@
68396864 setTimeout( function() {
68406865 // Unwrap the span found in webkit copies
68416866 context.$content.find( 'link, style, meta' ).remove(); //MS Word
 6867+ context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)') //MS Word+webkit
 6868+ .each( function(){
 6869+ var outerParent = $(this).parent();
 6870+ outerParent.replaceWith( outerParent.childNodes() );
 6871+ });
68426872 context.$content.find( 'span.Apple-style-span' ).each( function() {
68436873 $( this.childNodes ).insertBefore( this );
68446874 } ).remove(); //Apple Richtext
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -449,7 +449,8 @@
450450 if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'keydown':function(event){switch(event.which){case 90:if((event.ctrlKey||event.metaKey)&&context.history.length){var newPosition;if(event.shiftKey){newPosition=context.historyPosition+1;}else{newPosition=context.historyPosition-1;}
451451 if(newPosition>=(context.history.length*-1)&&newPosition<0){context.fn.updateHistory(context.oldDelayedHTML!=context.$content.html());context.oldDelayedHistoryPosition=context.historyPosition;context.historyPosition=newPosition;context.$content.html(context.history[context.history.length+context.historyPosition].html);context.fn.purgeOffsets();if(context.history[context.history.length+context.historyPosition].sel){context.fn.setSelection({start:context.history[context.history.length+context.historyPosition].sel[0],end:context.history[context.history.length+context.historyPosition].sel[1]});}}
452452 return false;}
453 -break;case 9:if(event.ctrlKey||event.altKey||event.shiftKey){return true;}else{var $tabindexList=$j('[tabindex]:visible').sort(function(a,b){return a.tabIndex-b.tabIndex;});for(var i=0;i<$tabindexList.length;i++){if($tabindexList.eq(i).attr('id')==context.$iframe.attr('id')){$tabindexList.get(i+1).focus();break;}}
 453+break;case 89:if((event.ctrlKey||event.metaKey)&&context.history.length&&$.browser.msie){newPosition=context.historyPosition+1;if(newPosition>=(context.history.length*-1)&&newPosition<0){context.fn.updateHistory(context.oldDelayedHTML!=context.$content.html());context.oldDelayedHistoryPosition=context.historyPosition;context.historyPosition=newPosition;context.$content.html(context.history[context.history.length+context.historyPosition].html);context.fn.purgeOffsets();if(context.history[context.history.length+context.historyPosition].sel){context.fn.setSelection({start:context.history[context.history.length+context.historyPosition].sel[0],end:context.history[context.history.length+context.historyPosition].sel[1]});}}}
 454+return false;break;case 9:if(event.ctrlKey||event.altKey||event.shiftKey){return true;}else{var $tabindexList=$j('[tabindex]:visible').sort(function(a,b){return a.tabIndex-b.tabIndex;});for(var i=0;i<$tabindexList.length;i++){if($tabindexList.eq(i).attr('id')==context.$iframe.attr('id')){$tabindexList.get(i+1).focus();break;}}
454455 return false;}
455456 break;case 86:if(event.ctrlKey){context.evt.paste(event);}
456457 break;}
@@ -457,7 +458,7 @@
458459 switch(event.which){case 8:break;}
459460 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';}
460461 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');}
461 -setTimeout(function(){context.$content.find('link, style, meta').remove();context.$content.find('span.Apple-style-span').each(function(){$(this.childNodes).insertBefore(this);}).remove();var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
 462+setTimeout(function(){context.$content.find('link, style, meta').remove();context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes());});context.$content.find('span.Apple-style-span').each(function(){$(this.childNodes).insertBefore(this);}).remove();var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
462463 var text=$currentElement.text();if($currentElement.is('br')){$currentElement.addClass('wikiEditor');}else if($currentElement.is('span')&&text.length==0){$currentElement.remove();}else{$newElement=$('<p></p>').addClass('wikiEditor').insertAfter($currentElement);if(text.length){$newElement.text(text);}else{$newElement.append($('<br>').addClass('wikiEditor'));}
463464 $currentElement.remove();}
464465 $selection=context.$content.find(':not(.wikiEditor)');}

Follow-up revisions

RevisionCommit summaryAuthorDate
r62709Follow up to r62685, incorporating Roan's commentsadam15:58, 19 February 2010

Comments

#Comment by Catrope (talk | contribs)   10:11, 19 February 2010

This can be done with a lot less code duplication by using

case 90: // z
case 89: // y

, tweaking the if ( event.shiftKey ) { condition and adding an if that bails out (break;) for Ctrl+Shift+Y

#Comment by DaSch (talk | contribs)   10:29, 19 February 2010

and it seams to me that this breaks input of y I updated to this revision and on my wiki trying to type y is like the key is broken because nothing happens

#Comment by Catrope (talk | contribs)   10:46, 19 February 2010
+					if ( ( event.ctrlKey || event.metaKey ) && context.history.length && $.browser.msie ) {
...
+					}
+					return false;

The return false; should be inside the if block.

Status & tagging log