Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,7 +72,7 @@ |
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' => 117 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 118 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 48 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ), |
— | — | @@ -82,10 +82,10 @@ |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 235 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 236 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 235 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 236 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -622,6 +622,7 @@ |
623 | 623 | var selText = $(this).textSelection( 'getSelection' ); |
624 | 624 | var selTextArr; |
625 | 625 | var selectAfter = false; |
| 626 | + var setSelectionTo = null; |
626 | 627 | var pre = options.pre, post = options.post; |
627 | 628 | if ( !selText ) { |
628 | 629 | selText = options.peri; |
— | — | @@ -691,16 +692,57 @@ |
692 | 693 | range.extractContents(); |
693 | 694 | // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen |
694 | 695 | // 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; |
696 | 700 | 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; |
698 | 714 | 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; |
700 | 727 | } |
701 | 728 | } |
702 | | - if ( lastNode ) { |
703 | | - context.fn.scrollToTop( lastNode ); |
| 729 | + if ( firstNode ) { |
| 730 | + context.fn.scrollToTop( $( firstNode.parentNode ) ); |
704 | 731 | } |
| 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 | + } |
705 | 747 | } else if ( context.$iframe[0].contentWindow.document.selection ) { |
706 | 748 | // IE |
707 | 749 | context.$iframe[0].contentWindow.focus(); |
— | — | @@ -743,7 +785,16 @@ |
744 | 786 | .replace( />/g, '>' ) |
745 | 787 | .replace( /\r?\n/g, '<br />' ) |
746 | 788 | ); |
| 789 | + if ( selectAfter ) { |
| 790 | + range.moveStart( 'character', -post.length - selText.length ); |
| 791 | + range.moveEnd( 'character', -post.length ); |
| 792 | + range.select(); |
| 793 | + } |
747 | 794 | } |
| 795 | + |
| 796 | + if ( setSelectionTo ) { |
| 797 | + context.fn.setSelection( setSelectionTo ); |
| 798 | + } |
748 | 799 | // Trigger the encapsulateSelection event (this might need to get named something else/done differently) |
749 | 800 | $( context.$iframe[0].contentWindow.document ).trigger( |
750 | 801 | 'encapsulateSelection', [ pre, options.peri, post, options.ownline, options.replace ] |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6820,7 +6820,7 @@ |
6821 | 6821 | } |
6822 | 6822 | $selection = context.$content.find( ':not(.wikiEditor)' ); |
6823 | 6823 | } |
6824 | | - }, 100 ); |
| 6824 | + }, 0 ); |
6825 | 6825 | return true; |
6826 | 6826 | } |
6827 | 6827 | }; |
— | — | @@ -7055,6 +7055,7 @@ |
7056 | 7056 | var selText = $(this).textSelection( 'getSelection' ); |
7057 | 7057 | var selTextArr; |
7058 | 7058 | var selectAfter = false; |
| 7059 | + var setSelectionTo = null; |
7059 | 7060 | var pre = options.pre, post = options.post; |
7060 | 7061 | if ( !selText ) { |
7061 | 7062 | selText = options.peri; |
— | — | @@ -7124,16 +7125,57 @@ |
7125 | 7126 | range.extractContents(); |
7126 | 7127 | // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen |
7127 | 7128 | // 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; |
7129 | 7133 | 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; |
7131 | 7147 | 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; |
7133 | 7160 | } |
7134 | 7161 | } |
7135 | | - if ( lastNode ) { |
7136 | | - context.fn.scrollToTop( lastNode ); |
| 7162 | + if ( firstNode ) { |
| 7163 | + context.fn.scrollToTop( $( firstNode.parentNode ) ); |
7137 | 7164 | } |
| 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 | + } |
7138 | 7180 | } else if ( context.$iframe[0].contentWindow.document.selection ) { |
7139 | 7181 | // IE |
7140 | 7182 | context.$iframe[0].contentWindow.focus(); |
— | — | @@ -7176,7 +7218,16 @@ |
7177 | 7219 | .replace( />/g, '>' ) |
7178 | 7220 | .replace( /\r?\n/g, '<br />' ) |
7179 | 7221 | ); |
| 7222 | + if ( selectAfter ) { |
| 7223 | + range.moveStart( 'character', -post.length - selText.length ); |
| 7224 | + range.moveEnd( 'character', -post.length ); |
| 7225 | + range.select(); |
| 7226 | + } |
7180 | 7227 | } |
| 7228 | + |
| 7229 | + if ( setSelectionTo ) { |
| 7230 | + context.fn.setSelection( setSelectionTo ); |
| 7231 | + } |
7181 | 7232 | // Trigger the encapsulateSelection event (this might need to get named something else/done differently) |
7182 | 7233 | $( context.$iframe[0].contentWindow.document ).trigger( |
7183 | 7234 | 'encapsulateSelection', [ pre, options.peri, post, options.ownline, options.replace ] |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -457,7 +457,7 @@ |
458 | 458 | context.history.push({'html':newHTML});while(context.history.length>10){context.history.shift();}} |
459 | 459 | 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();} |
460 | 460 | 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'};} |
462 | 462 | if(typeof event.data=='undefined'){event.data={};} |
463 | 463 | if(name in context.evt){if(!context.evt[name](event)){return false;}} |
464 | 464 | 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 @@ |
474 | 474 | 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();} |
475 | 475 | 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();} |
476 | 476 | 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+=' ';} |
478 | 478 | if(options.splitlines){selTextArr=selText.split(/\n/);} |
479 | 479 | 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;} |
480 | 480 | if(n&&n.nodeName=='BR'){atStart=true;}else{atEnd=true;}}else if(range.startContainer.nodeName=='#text'&&range.startOffset==range.startContainer.nodeValue.length){atEnd=true;} |
481 | 481 | if(!atStart){pre="\n"+options.pre;} |
482 | 482 | if(!atEnd){post+="\n";}} |
483 | 483 | 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;} |
486 | 491 | 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";}} |
487 | 492 | 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,'<').replace(/>/g,'>').replace(/\r?\n/g,'<br />'));} |
| 493 | +range.pasteHTML(insertText.replace(/\</g,'<').replace(/>/g,'>').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);} |
489 | 495 | $(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;} |
490 | 496 | if(!sc||!ec){return context.$textarea;} |
491 | 497 | var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;} |