r62247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62246‎ | r62247 | r62248 >
Date:14:56, 10 February 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: (bug 22379) Cursor moves to beginning of inserted text on non-IE browsers. We're now back at the previous behavior where the cursor is placed at the end of the inserted text, or selects part of the inserted text in certain cases
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' => 117 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 118 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 48 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 235 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 236 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 235 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 236 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -622,6 +622,7 @@
623623 var selText = $(this).textSelection( 'getSelection' );
624624 var selTextArr;
625625 var selectAfter = false;
 626+ var setSelectionTo = null;
626627 var pre = options.pre, post = options.post;
627628 if ( !selText ) {
628629 selText = options.peri;
@@ -691,16 +692,57 @@
692693 range.extractContents();
693694 // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen
694695 // in reverse order
695 - var lastNode;
 696+ // Track the first and last inserted node, and if we need to also track where the text we need to select
 697+ // afterwards starts and ends
 698+ var firstNode = null, lastNode = null;
 699+ var selSC = null, selEC = null, selSO = null, selEO = null, offset = 0;
696700 for ( var i = insertLines.length - 1; i >= 0; i-- ) {
697 - range.insertNode( context.$iframe[0].contentWindow.document.createTextNode( insertLines[i] ) );
 701+ firstNode = context.$iframe[0].contentWindow.document.createTextNode( insertLines[i] );
 702+ range.insertNode( firstNode );
 703+ lastNode = lastNode || firstNode;
 704+ var newOffset = offset + insertLines[i].length;
 705+ if ( !selSC && pre.length < newOffset ) {
 706+ selSC = firstNode;
 707+ selSO = pre.length - offset;
 708+ }
 709+ if ( selSC && insertText.length - post.length < newOffset ) {
 710+ selEC = firstNode;
 711+ selEO = insertText.length - pre.length - offset;
 712+ }
 713+ offset = newOffset;
698714 if ( i > 0 ) {
699 - lastNode = range.insertNode( context.$iframe[0].contentWindow.document.createElement( 'br' ) );
 715+ firstNode = context.$iframe[0].contentWindow.document.createElement( 'br' );
 716+ range.insertNode( firstNode );
 717+ newOffset = offset + 1;
 718+ if ( !selSC && pre.length < newOffset ) {
 719+ selSC = firstNode;
 720+ selSO = pre.length - offset;
 721+ }
 722+ if ( selSC && insertText.length - post.length < newOffset ) {
 723+ selEC = firstNode;
 724+ selEO = insertText.length - pre.length - offset;
 725+ }
 726+ offset = newOffset;
700727 }
701728 }
702 - if ( lastNode ) {
703 - context.fn.scrollToTop( lastNode );
 729+ if ( firstNode ) {
 730+ context.fn.scrollToTop( $( firstNode.parentNode ) );
704731 }
 732+ if ( selectAfter ) {
 733+ setSelectionTo = {
 734+ startContainer: selSC,
 735+ endContainer: selEC,
 736+ start: selSO,
 737+ end: selEO
 738+ };
 739+ } else if ( lastNode ) {
 740+ setSelectionTo = {
 741+ startContainer: lastNode,
 742+ endContainer: lastNode,
 743+ start: lastNode.nodeValue.length,
 744+ end: lastNode.nodeValue.length
 745+ };
 746+ }
705747 } else if ( context.$iframe[0].contentWindow.document.selection ) {
706748 // IE
707749 context.$iframe[0].contentWindow.focus();
@@ -743,7 +785,16 @@
744786 .replace( />/g, '&gt;' )
745787 .replace( /\r?\n/g, '<br />' )
746788 );
 789+ if ( selectAfter ) {
 790+ range.moveStart( 'character', -post.length - selText.length );
 791+ range.moveEnd( 'character', -post.length );
 792+ range.select();
 793+ }
747794 }
 795+
 796+ if ( setSelectionTo ) {
 797+ context.fn.setSelection( setSelectionTo );
 798+ }
748799 // Trigger the encapsulateSelection event (this might need to get named something else/done differently)
749800 $( context.$iframe[0].contentWindow.document ).trigger(
750801 'encapsulateSelection', [ pre, options.peri, post, options.ownline, options.replace ]
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6820,7 +6820,7 @@
68216821 }
68226822 $selection = context.$content.find( ':not(.wikiEditor)' );
68236823 }
6824 - }, 100 );
 6824+ }, 0 );
68256825 return true;
68266826 }
68276827 };
@@ -7055,6 +7055,7 @@
70567056 var selText = $(this).textSelection( 'getSelection' );
70577057 var selTextArr;
70587058 var selectAfter = false;
 7059+ var setSelectionTo = null;
70597060 var pre = options.pre, post = options.post;
70607061 if ( !selText ) {
70617062 selText = options.peri;
@@ -7124,16 +7125,57 @@
71257126 range.extractContents();
71267127 // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen
71277128 // in reverse order
7128 - var lastNode;
 7129+ // Track the first and last inserted node, and if we need to also track where the text we need to select
 7130+ // afterwards starts and ends
 7131+ var firstNode = null, lastNode = null;
 7132+ var selSC = null, selEC = null, selSO = null, selEO = null, offset = 0;
71297133 for ( var i = insertLines.length - 1; i >= 0; i-- ) {
7130 - range.insertNode( context.$iframe[0].contentWindow.document.createTextNode( insertLines[i] ) );
 7134+ firstNode = context.$iframe[0].contentWindow.document.createTextNode( insertLines[i] );
 7135+ range.insertNode( firstNode );
 7136+ lastNode = lastNode || firstNode;
 7137+ var newOffset = offset + insertLines[i].length;
 7138+ if ( !selSC && pre.length < newOffset ) {
 7139+ selSC = firstNode;
 7140+ selSO = pre.length - offset;
 7141+ }
 7142+ if ( selSC && insertText.length - post.length < newOffset ) {
 7143+ selEC = firstNode;
 7144+ selEO = insertText.length - pre.length - offset;
 7145+ }
 7146+ offset = newOffset;
71317147 if ( i > 0 ) {
7132 - lastNode = range.insertNode( context.$iframe[0].contentWindow.document.createElement( 'br' ) );
 7148+ firstNode = context.$iframe[0].contentWindow.document.createElement( 'br' );
 7149+ range.insertNode( firstNode );
 7150+ newOffset = offset + 1;
 7151+ if ( !selSC && pre.length < newOffset ) {
 7152+ selSC = firstNode;
 7153+ selSO = pre.length - offset;
 7154+ }
 7155+ if ( selSC && insertText.length - post.length < newOffset ) {
 7156+ selEC = firstNode;
 7157+ selEO = insertText.length - pre.length - offset;
 7158+ }
 7159+ offset = newOffset;
71337160 }
71347161 }
7135 - if ( lastNode ) {
7136 - context.fn.scrollToTop( lastNode );
 7162+ if ( firstNode ) {
 7163+ context.fn.scrollToTop( $( firstNode.parentNode ) );
71377164 }
 7165+ if ( selectAfter ) {
 7166+ setSelectionTo = {
 7167+ startContainer: selSC,
 7168+ endContainer: selEC,
 7169+ start: selSO,
 7170+ end: selEO
 7171+ };
 7172+ } else if ( lastNode ) {
 7173+ setSelectionTo = {
 7174+ startContainer: lastNode,
 7175+ endContainer: lastNode,
 7176+ start: lastNode.nodeValue.length,
 7177+ end: lastNode.nodeValue.length
 7178+ };
 7179+ }
71387180 } else if ( context.$iframe[0].contentWindow.document.selection ) {
71397181 // IE
71407182 context.$iframe[0].contentWindow.focus();
@@ -7176,7 +7218,16 @@
71777219 .replace( />/g, '&gt;' )
71787220 .replace( /\r?\n/g, '<br />' )
71797221 );
 7222+ if ( selectAfter ) {
 7223+ range.moveStart( 'character', -post.length - selText.length );
 7224+ range.moveEnd( 'character', -post.length );
 7225+ range.select();
 7226+ }
71807227 }
 7228+
 7229+ if ( setSelectionTo ) {
 7230+ context.fn.setSelection( setSelectionTo );
 7231+ }
71817232 // Trigger the encapsulateSelection event (this might need to get named something else/done differently)
71827233 $( context.$iframe[0].contentWindow.document ).trigger(
71837234 'encapsulateSelection', [ pre, options.peri, post, options.ownline, options.replace ]
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -457,7 +457,7 @@
458458 context.history.push({'html':newHTML});while(context.history.length>10){context.history.shift();}}
459459 return true;},'paste':function(event){context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');setTimeout(function(){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();}
460460 if($currentElement.is('br')){$currentElement.addClass('wikiEditor');}else{$('<p></p>').text($currentElement.text()).addClass('wikiEditor').insertAfter($currentElement);$currentElement.remove();}
461 -$selection=context.$content.find(':not(.wikiEditor)');}},100);return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
 461+$selection=context.$content.find(':not(.wikiEditor)');}},0);return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
462462 if(typeof event.data=='undefined'){event.data={};}
463463 if(name in context.evt){if(!context.evt[name](event)){return false;}}
464464 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);}}
@@ -473,18 +473,24 @@
474474 return context.htmlToTextMap[origHTML]=leading+retval+trailing;},'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();}
475475 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();}
476476 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(typeof retval.toString!='undefined'){retval=retval.toString();}
477 -return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
 477+return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var setSelectionTo=null;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
478478 if(options.splitlines){selTextArr=selText.split(/\n/);}
479479 if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){var atStart=false,atEnd=false;var body=context.$content.get(0);if(range.startOffset==0){atStart=true;}else if(range.startContainer==body){var n=body.firstChild;for(var i=0;i<range.startOffset-1&&n;i++){n=n.nextSibling;}
480480 if(n&&n.nodeName=='BR'){atStart=true;}else{atEnd=true;}}else if(range.startContainer.nodeName=='#text'&&range.startOffset==range.startContainer.nodeValue.length){atEnd=true;}
481481 if(!atStart){pre="\n"+options.pre;}
482482 if(!atEnd){post+="\n";}}
483483 var insertText="";if(options.splitlines){for(var j=0;j<selTextArr.length;j++){insertText=insertText+pre+selTextArr[j]+post;if(j!=selTextArr.length-1){insertText+="\n";}}}else{insertText=pre+selText+post;}
484 -var insertLines=insertText.split("\n");range.extractContents();var lastNode;for(var i=insertLines.length-1;i>=0;i--){range.insertNode(context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]));if(i>0){lastNode=range.insertNode(context.$iframe[0].contentWindow.document.createElement('br'));}}
485 -if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;}
 484+var insertLines=insertText.split("\n");range.extractContents();var firstNode=null,lastNode=null;var selSC=null,selEC=null,selSO=null,selEO=null,offset=0;for(var i=insertLines.length-1;i>=0;i--){firstNode=context.$iframe[0].contentWindow.document.createTextNode(insertLines[i]);range.insertNode(firstNode);lastNode=lastNode||firstNode;var newOffset=offset+insertLines[i].length;if(!selSC&&pre.length<newOffset){selSC=firstNode;selSO=pre.length-offset;}
 485+if(selSC&&insertText.length-post.length<newOffset){selEC=firstNode;selEO=insertText.length-pre.length-offset;}
 486+offset=newOffset;if(i>0){firstNode=context.$iframe[0].contentWindow.document.createElement('br');range.insertNode(firstNode);newOffset=offset+1;if(!selSC&&pre.length<newOffset){selSC=firstNode;selSO=pre.length-offset;}
 487+if(selSC&&insertText.length-post.length<newOffset){selEC=firstNode;selEO=insertText.length-pre.length-offset;}
 488+offset=newOffset;}}
 489+if(firstNode){context.fn.scrollToTop($(firstNode.parentNode));}
 490+if(selectAfter){setSelectionTo={startContainer:selSC,endContainer:selEC,start:selSO,end:selEO};}else if(lastNode){setSelectionTo={startContainer:lastNode,endContainer:lastNode,start:lastNode.nodeValue.length,end:lastNode.nodeValue.length};}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=context.$iframe[0].contentWindow.document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;}
486491 var range3=context.$iframe[0].contentWindow.document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}}
487492 var insertText="";if(options.splitlines){for(var j=0;j<selTextArr.length;j++){insertText=insertText+pre+selTextArr[j]+post;if(j!=selTextArr.length-1){insertText+="\n";}}}else{insertText=pre+selText+post;}
488 -range.pasteHTML(insertText.replace(/\</g,'&lt;').replace(/>/g,'&gt;').replace(/\r?\n/g,'<br />'));}
 493+range.pasteHTML(insertText.replace(/\</g,'&lt;').replace(/>/g,'&gt;').replace(/\r?\n/g,'<br />'));if(selectAfter){range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);range.select();}}
 494+if(setSelectionTo){context.fn.setSelection(setSelectionTo);}
489495 $(context.$iframe[0].contentWindow.document).trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'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;}
490496 if(!sc||!ec){return context.$textarea;}
491497 var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}

Status & tagging log