Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -63,7 +63,7 @@ |
64 | 64 | array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ), |
65 | 65 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
66 | 66 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 4 ), |
67 | | - array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 11 ), |
| 67 | + array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 12 ), |
68 | 68 | array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 6 ), |
69 | 69 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ), |
70 | 70 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 3 ), |
— | — | @@ -73,10 +73,10 @@ |
74 | 74 | array( 'src' => 'js/js2/jquery-ui-1.7.2.js', 'version' => '1.7.2y' ), |
75 | 75 | ), |
76 | 76 | 'combined' => array( |
77 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 27 ), |
| 77 | + array( 'src' => 'js/plugins.combined.js', 'version' => 28 ), |
78 | 78 | ), |
79 | 79 | 'minified' => array( |
80 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 27 ), |
| 80 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 28 ), |
81 | 81 | ), |
82 | 82 | ), |
83 | 83 | ); |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js |
— | — | @@ -1234,10 +1234,11 @@ |
1235 | 1235 | var searchStr = $j( '#edittoolbar-replace-search' ).val(); |
1236 | 1236 | var replaceStr = $j( '#edittoolbar-replace-replace' ).val(); |
1237 | 1237 | var flags = ''; |
| 1238 | + var replaceAll = $j( '#edittoolbar-replace-all' ).is( ':checked' ); |
1238 | 1239 | if ( !$j( '#edittoolbar-replace-case' ).is( ':checked' ) ) { |
1239 | 1240 | flags += 'i'; |
1240 | 1241 | } |
1241 | | - if ( $j( '#edittoolbar-replace-all' ).is( ':checked' ) ) { |
| 1242 | + if ( replaceAll ) { |
1242 | 1243 | flags += 'g'; |
1243 | 1244 | } |
1244 | 1245 | if ( !$j( '#edittoolbar-replace-regex' ).is( ':checked' ) ) { |
— | — | @@ -1249,21 +1250,30 @@ |
1250 | 1251 | var matches = text.match( regex ); |
1251 | 1252 | if ( !matches ) { |
1252 | 1253 | alert( gM( 'edittoolbar-tool-replace-nomatch' ) ); |
| 1254 | + } else if ( replaceAll ) { |
| 1255 | + // Prepare to select the last match |
| 1256 | + var start = text.lastIndexOf( matches[matches.length - 1] ); |
| 1257 | + var end = start + replaceStr.length; |
| 1258 | + var corr = ( matches.length - 1 ) * ( replaceStr.length - searchStr.length ); |
| 1259 | + $textarea |
| 1260 | + .val( $textarea.val().replace( regex, replaceStr ) ) |
| 1261 | + .change() |
| 1262 | + .setSelection( start + corr, end + corr ) |
| 1263 | + .scrollToCaretPosition(); |
| 1264 | + |
| 1265 | + alert( gM( 'edittoolbar-tool-replace-success', matches.length ) ); |
| 1266 | + $j(this).data( 'offset', 0 ); |
1253 | 1267 | } else { |
1254 | | - var start, end; |
1255 | | - for ( var i = 0; i < matches.length; i++ ) { |
1256 | | - start = text.indexOf( matches[i] ); |
1257 | | - end = start + matches[i].length; |
1258 | | - $textarea.setSelection( start, end ); |
1259 | | - $textarea.encapsulateSelection( '', replaceStr, '', false, true ); |
1260 | | - |
1261 | | - // $textarea.val() has changed |
1262 | | - text = fixOperaBrokenness( $textarea.val() ); |
1263 | | - } |
1264 | | - if ( $j( '#edittoolbar-replace-all' ).is( ':checked' ) ) |
1265 | | - alert( gM( 'edittoolbar-tool-replace-success', i ) ); |
1266 | | - $textarea.scrollToCaretPosition( start ); |
1267 | | - $textarea.setSelection( start, start + replaceStr.length ); |
| 1268 | + var start = text.indexOf( matches[0], |
| 1269 | + $j(this).data( 'offset' ) ); |
| 1270 | + var end = start + matches[0].length; |
| 1271 | + var newEnd = start + replaceStr.length; |
| 1272 | + $textarea |
| 1273 | + .setSelection( start, end ) |
| 1274 | + .encapsulateSelection( '', replaceStr, '', false, true ) |
| 1275 | + .setSelection( start, newEnd ) |
| 1276 | + .scrollToCaretPosition(); |
| 1277 | + $j(this).data( 'offset', newEnd ); |
1268 | 1278 | } |
1269 | 1279 | }, |
1270 | 1280 | 'edittoolbar-tool-replace-close': function() { |
— | — | @@ -1272,6 +1282,7 @@ |
1273 | 1283 | } |
1274 | 1284 | }, |
1275 | 1285 | open: function() { |
| 1286 | + $j(this).data( 'offset', 0 ); |
1276 | 1287 | if ( !( $j(this).data( 'dialogkeypressset' ) ) ) { |
1277 | 1288 | $j(this).data( 'dialogkeypressset', true ); |
1278 | 1289 | // Execute the action associated with the first button |
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | /* Configuration */ |
21 | 21 | |
22 | 22 | // Bump the version number every time you change any of the .css/.js files |
23 | | -$wgEditToolbarStyleVersion = 38; |
| 23 | +$wgEditToolbarStyleVersion = 39; |
24 | 24 | |
25 | 25 | // Set this to true to simply override the stock toolbar for everyone |
26 | 26 | $wgEditToolbarGlobalEnable = false; |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js |
— | — | @@ -30,81 +30,82 @@ |
31 | 31 | * @param replace If true, replaces any selected text with peri; if false, peri is ignored and selected text is left alone |
32 | 32 | */ |
33 | 33 | encapsulateSelection: function( pre, peri, post, ownline, replace ) { |
34 | | - /** |
35 | | - * Check if the selected text is the same as the insert text |
36 | | - */ |
37 | | - function checkSelectedText() { |
38 | | - if ( !selText ) { |
39 | | - selText = peri; |
40 | | - isSample = true; |
41 | | - } else if ( replace ) { |
42 | | - selText = peri; |
43 | | - } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
44 | | - // Exclude ending space char |
45 | | - selText = selText.substring(0, selText.length - 1); |
46 | | - post += ' ' |
| 34 | + return this.each( function() { |
| 35 | + /** |
| 36 | + * Check if the selected text is the same as the insert text |
| 37 | + */ |
| 38 | + function checkSelectedText() { |
| 39 | + if ( !selText ) { |
| 40 | + selText = peri; |
| 41 | + isSample = true; |
| 42 | + } else if ( replace ) { |
| 43 | + selText = peri; |
| 44 | + } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
| 45 | + // Exclude ending space char |
| 46 | + selText = selText.substring(0, selText.length - 1); |
| 47 | + post += ' ' |
| 48 | + } |
47 | 49 | } |
48 | | - } |
49 | | - var e = this.jquery ? this[0] : this; |
50 | | - var selText = $(this).getSelection(); |
51 | | - var isSample = false; |
52 | | - if ( e.style.display == 'none' ) { |
53 | | - // Do nothing |
54 | | - } else if ( document.selection && document.selection.createRange ) { |
55 | | - // IE/Opera |
56 | | - $(this).focus(); |
57 | | - var range = document.selection.createRange(); |
58 | | - if ( ownline && range.moveStart ) { |
59 | | - var range2 = document.selection.createRange(); |
60 | | - range2.collapse(); |
61 | | - range2.moveStart( 'character', -1 ); |
62 | | - // FIXME: Which check is correct? |
63 | | - if ( range2.text != "\r" && range2.text != "\n" && range3.text != "" ) { |
64 | | - pre = "\n" + pre; |
| 50 | + var selText = $(this).getSelection(); |
| 51 | + var isSample = false; |
| 52 | + if ( this.style.display == 'none' ) { |
| 53 | + // Do nothing |
| 54 | + } else if ( document.selection && document.selection.createRange ) { |
| 55 | + // IE/Opera |
| 56 | + $(this).focus(); |
| 57 | + var range = document.selection.createRange(); |
| 58 | + if ( ownline && range.moveStart ) { |
| 59 | + var range2 = document.selection.createRange(); |
| 60 | + range2.collapse(); |
| 61 | + range2.moveStart( 'character', -1 ); |
| 62 | + // FIXME: Which check is correct? |
| 63 | + if ( range2.text != "\r" && range2.text != "\n" && range3.text != "" ) { |
| 64 | + pre = "\n" + pre; |
| 65 | + } |
| 66 | + var range3 = document.selection.createRange(); |
| 67 | + range3.collapse( false ); |
| 68 | + range3.moveEnd( 'character', 1 ); |
| 69 | + if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
| 70 | + post += "\n"; |
| 71 | + } |
65 | 72 | } |
66 | | - var range3 = document.selection.createRange(); |
67 | | - range3.collapse( false ); |
68 | | - range3.moveEnd( 'character', 1 ); |
69 | | - if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
70 | | - post += "\n"; |
| 73 | + checkSelectedText(); |
| 74 | + range.text = pre + selText + post; |
| 75 | + if ( isSample && range.moveStart ) { |
| 76 | + if ( window.opera ) { |
| 77 | + post = post.replace( /\n/g, '' ); |
| 78 | + } |
| 79 | + range.moveStart( 'character', - post.length - selText.length ); |
| 80 | + range.moveEnd( 'character', - post.length ); |
71 | 81 | } |
72 | | - } |
73 | | - checkSelectedText(); |
74 | | - range.text = pre + selText + post; |
75 | | - if ( isSample && range.moveStart ) { |
76 | | - if ( window.opera ) { |
77 | | - post = post.replace( /\n/g, '' ); |
| 82 | + range.select(); |
| 83 | + } else if ( this.selectionStart || this.selectionStart == '0' ) { |
| 84 | + // Mozilla |
| 85 | + $(this).focus(); |
| 86 | + var startPos = this.selectionStart; |
| 87 | + var endPos = this.selectionEnd; |
| 88 | + checkSelectedText(); |
| 89 | + if ( ownline ) { |
| 90 | + if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" ) { |
| 91 | + pre = "\n" + pre; |
| 92 | + } |
| 93 | + if ( this.value.charAt( endPos ) != "\n" ) { |
| 94 | + post += "\n"; |
| 95 | + } |
78 | 96 | } |
79 | | - range.moveStart( 'character', - post.length - selText.length ); |
80 | | - range.moveEnd( 'character', - post.length ); |
81 | | - } |
82 | | - range.select(); |
83 | | - } else if ( e.selectionStart || e.selectionStart == '0' ) { |
84 | | - // Mozilla |
85 | | - $(this).focus(); |
86 | | - var startPos = e.selectionStart; |
87 | | - var endPos = e.selectionEnd; |
88 | | - checkSelectedText(); |
89 | | - if ( ownline ) { |
90 | | - if ( startPos != 0 && e.value.charAt( startPos - 1 ) != "\n" ) { |
91 | | - pre = "\n" + pre; |
| 97 | + this.value = this.value.substring( 0, startPos ) + pre + selText + post + this.value.substring( endPos, this.value.length ); |
| 98 | + if ( isSample ) { |
| 99 | + this.selectionStart = startPos + pre.length; |
| 100 | + this.selectionEnd = startPos + pre.length + selText.length; |
| 101 | + } else { |
| 102 | + this.selectionStart = startPos + pre.length + selText.length + post.length; |
| 103 | + this.selectionEnd = this.selectionStart; |
92 | 104 | } |
93 | | - if ( e.value.charAt( endPos ) != "\n" ) { |
94 | | - post += "\n"; |
95 | | - } |
96 | 105 | } |
97 | | - e.value = e.value.substring( 0, startPos ) + pre + selText + post + e.value.substring( endPos, e.value.length ); |
98 | | - if ( isSample ) { |
99 | | - e.selectionStart = startPos + pre.length; |
100 | | - e.selectionEnd = startPos + pre.length + selText.length; |
101 | | - } else { |
102 | | - e.selectionStart = startPos + pre.length + selText.length + post.length; |
103 | | - e.selectionEnd = e.selectionStart; |
104 | | - } |
105 | | - } |
106 | | - // Scroll the textarea to the inserted text |
107 | | - $(this).scrollToCaretPosition(); |
108 | | - $(this).trigger( 'encapsulateSelection', [ pre, peri, post, ownline, replace ] ); |
| 106 | + // Scroll the textarea to the inserted text |
| 107 | + $(this).scrollToCaretPosition(); |
| 108 | + $(this).trigger( 'encapsulateSelection', [ pre, peri, post, ownline, replace ] ); |
| 109 | + }); |
109 | 110 | }, |
110 | 111 | /** |
111 | 112 | * Ported from Wikia's LinkSuggest extension |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -842,81 +842,82 @@ |
843 | 843 | * @param replace If true, replaces any selected text with peri; if false, peri is ignored and selected text is left alone |
844 | 844 | */ |
845 | 845 | encapsulateSelection: function( pre, peri, post, ownline, replace ) { |
846 | | - /** |
847 | | - * Check if the selected text is the same as the insert text |
848 | | - */ |
849 | | - function checkSelectedText() { |
850 | | - if ( !selText ) { |
851 | | - selText = peri; |
852 | | - isSample = true; |
853 | | - } else if ( replace ) { |
854 | | - selText = peri; |
855 | | - } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
856 | | - // Exclude ending space char |
857 | | - selText = selText.substring(0, selText.length - 1); |
858 | | - post += ' ' |
| 846 | + return this.each( function() { |
| 847 | + /** |
| 848 | + * Check if the selected text is the same as the insert text |
| 849 | + */ |
| 850 | + function checkSelectedText() { |
| 851 | + if ( !selText ) { |
| 852 | + selText = peri; |
| 853 | + isSample = true; |
| 854 | + } else if ( replace ) { |
| 855 | + selText = peri; |
| 856 | + } else if ( selText.charAt( selText.length - 1 ) == ' ' ) { |
| 857 | + // Exclude ending space char |
| 858 | + selText = selText.substring(0, selText.length - 1); |
| 859 | + post += ' ' |
| 860 | + } |
859 | 861 | } |
860 | | - } |
861 | | - var e = this.jquery ? this[0] : this; |
862 | | - var selText = $(this).getSelection(); |
863 | | - var isSample = false; |
864 | | - if ( e.style.display == 'none' ) { |
865 | | - // Do nothing |
866 | | - } else if ( document.selection && document.selection.createRange ) { |
867 | | - // IE/Opera |
868 | | - $(this).focus(); |
869 | | - var range = document.selection.createRange(); |
870 | | - if ( ownline && range.moveStart ) { |
871 | | - var range2 = document.selection.createRange(); |
872 | | - range2.collapse(); |
873 | | - range2.moveStart( 'character', -1 ); |
874 | | - // FIXME: Which check is correct? |
875 | | - if ( range2.text != "\r" && range2.text != "\n" && range3.text != "" ) { |
876 | | - pre = "\n" + pre; |
| 862 | + var selText = $(this).getSelection(); |
| 863 | + var isSample = false; |
| 864 | + if ( this.style.display == 'none' ) { |
| 865 | + // Do nothing |
| 866 | + } else if ( document.selection && document.selection.createRange ) { |
| 867 | + // IE/Opera |
| 868 | + $(this).focus(); |
| 869 | + var range = document.selection.createRange(); |
| 870 | + if ( ownline && range.moveStart ) { |
| 871 | + var range2 = document.selection.createRange(); |
| 872 | + range2.collapse(); |
| 873 | + range2.moveStart( 'character', -1 ); |
| 874 | + // FIXME: Which check is correct? |
| 875 | + if ( range2.text != "\r" && range2.text != "\n" && range3.text != "" ) { |
| 876 | + pre = "\n" + pre; |
| 877 | + } |
| 878 | + var range3 = document.selection.createRange(); |
| 879 | + range3.collapse( false ); |
| 880 | + range3.moveEnd( 'character', 1 ); |
| 881 | + if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
| 882 | + post += "\n"; |
| 883 | + } |
877 | 884 | } |
878 | | - var range3 = document.selection.createRange(); |
879 | | - range3.collapse( false ); |
880 | | - range3.moveEnd( 'character', 1 ); |
881 | | - if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { |
882 | | - post += "\n"; |
| 885 | + checkSelectedText(); |
| 886 | + range.text = pre + selText + post; |
| 887 | + if ( isSample && range.moveStart ) { |
| 888 | + if ( window.opera ) { |
| 889 | + post = post.replace( /\n/g, '' ); |
| 890 | + } |
| 891 | + range.moveStart( 'character', - post.length - selText.length ); |
| 892 | + range.moveEnd( 'character', - post.length ); |
883 | 893 | } |
884 | | - } |
885 | | - checkSelectedText(); |
886 | | - range.text = pre + selText + post; |
887 | | - if ( isSample && range.moveStart ) { |
888 | | - if ( window.opera ) { |
889 | | - post = post.replace( /\n/g, '' ); |
| 894 | + range.select(); |
| 895 | + } else if ( this.selectionStart || this.selectionStart == '0' ) { |
| 896 | + // Mozilla |
| 897 | + $(this).focus(); |
| 898 | + var startPos = this.selectionStart; |
| 899 | + var endPos = this.selectionEnd; |
| 900 | + checkSelectedText(); |
| 901 | + if ( ownline ) { |
| 902 | + if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" ) { |
| 903 | + pre = "\n" + pre; |
| 904 | + } |
| 905 | + if ( this.value.charAt( endPos ) != "\n" ) { |
| 906 | + post += "\n"; |
| 907 | + } |
890 | 908 | } |
891 | | - range.moveStart( 'character', - post.length - selText.length ); |
892 | | - range.moveEnd( 'character', - post.length ); |
893 | | - } |
894 | | - range.select(); |
895 | | - } else if ( e.selectionStart || e.selectionStart == '0' ) { |
896 | | - // Mozilla |
897 | | - $(this).focus(); |
898 | | - var startPos = e.selectionStart; |
899 | | - var endPos = e.selectionEnd; |
900 | | - checkSelectedText(); |
901 | | - if ( ownline ) { |
902 | | - if ( startPos != 0 && e.value.charAt( startPos - 1 ) != "\n" ) { |
903 | | - pre = "\n" + pre; |
| 909 | + this.value = this.value.substring( 0, startPos ) + pre + selText + post + this.value.substring( endPos, this.value.length ); |
| 910 | + if ( isSample ) { |
| 911 | + this.selectionStart = startPos + pre.length; |
| 912 | + this.selectionEnd = startPos + pre.length + selText.length; |
| 913 | + } else { |
| 914 | + this.selectionStart = startPos + pre.length + selText.length + post.length; |
| 915 | + this.selectionEnd = this.selectionStart; |
904 | 916 | } |
905 | | - if ( e.value.charAt( endPos ) != "\n" ) { |
906 | | - post += "\n"; |
907 | | - } |
908 | 917 | } |
909 | | - e.value = e.value.substring( 0, startPos ) + pre + selText + post + e.value.substring( endPos, e.value.length ); |
910 | | - if ( isSample ) { |
911 | | - e.selectionStart = startPos + pre.length; |
912 | | - e.selectionEnd = startPos + pre.length + selText.length; |
913 | | - } else { |
914 | | - e.selectionStart = startPos + pre.length + selText.length + post.length; |
915 | | - e.selectionEnd = e.selectionStart; |
916 | | - } |
917 | | - } |
918 | | - // Scroll the textarea to the inserted text |
919 | | - $(this).scrollToCaretPosition(); |
920 | | - $(this).trigger( 'encapsulateSelection', [ pre, peri, post, ownline, replace ] ); |
| 918 | + // Scroll the textarea to the inserted text |
| 919 | + $(this).scrollToCaretPosition(); |
| 920 | + $(this).trigger( 'encapsulateSelection', [ pre, peri, post, ownline, replace ] ); |
| 921 | + }); |
921 | 922 | }, |
922 | 923 | /** |
923 | 924 | * Ported from Wikia's LinkSuggest extension |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -52,15 +52,15 @@ |
53 | 53 | context.data.$textbox.focus();})).appendTo($('body'));$(this).attr('autocomplete','off').keydown(function(e){context.data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;context.data.keypressedCount=0;switch(context.data.keypressed){case 40:e.preventDefault();e.stopImmediatePropagation();break;case 38:case 27:case 13:if(context.data.$container.is(':visible')){e.preventDefault();e.stopImmediatePropagation();}}}).keypress(function(e){context.data.keypressedCount++;$.suggestions.keypress(e,context,context.data.keypressed);}).keyup(function(e){if(context.data.keypressedCount==0){$.suggestions.keypress(e,context,context.data.keypressed);}}).blur(function(){if(context.data.mouseDownOn.size()>0){return;} |
54 | 54 | context.data.$container.hide();$.suggestions.cancel(context);});} |
55 | 55 | $(this).data('suggestions-context',context);});return returnValue!==null?returnValue:$(this);};})(jQuery);(function($){$.fn.extend({getSelection:function(){var e=this.jquery?this[0]:this;var retval='';if(e.style.display=='none'){}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();retval=range.text;}else if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);} |
56 | | -return retval;},encapsulateSelection:function(pre,peri,post,ownline,replace){function checkSelectedText(){if(!selText){selText=peri;isSample=true;}else if(replace){selText=peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' '}} |
57 | | -var e=this.jquery?this[0]:this;var selText=$(this).getSelection();var isSample=false;if(e.style.display=='none'){}else if(document.selection&&document.selection.createRange){$(this).focus();var range=document.selection.createRange();if(ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range3.text!=""){pre="\n"+pre;} |
| 56 | +return retval;},encapsulateSelection:function(pre,peri,post,ownline,replace){return this.each(function(){function checkSelectedText(){if(!selText){selText=peri;isSample=true;}else if(replace){selText=peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' '}} |
| 57 | +var selText=$(this).getSelection();var isSample=false;if(this.style.display=='none'){}else if(document.selection&&document.selection.createRange){$(this).focus();var range=document.selection.createRange();if(ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range3.text!=""){pre="\n"+pre;} |
58 | 58 | var range3=document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}} |
59 | 59 | checkSelectedText();range.text=pre+selText+post;if(isSample&&range.moveStart){if(window.opera){post=post.replace(/\n/g,'');} |
60 | 60 | range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);} |
61 | | -range.select();}else if(e.selectionStart||e.selectionStart=='0'){$(this).focus();var startPos=e.selectionStart;var endPos=e.selectionEnd;checkSelectedText();if(ownline){if(startPos!=0&&e.value.charAt(startPos-1)!="\n"){pre="\n"+pre;} |
62 | | -if(e.value.charAt(endPos)!="\n"){post+="\n";}} |
63 | | -e.value=e.value.substring(0,startPos)+pre+selText+post+e.value.substring(endPos,e.value.length);if(isSample){e.selectionStart=startPos+pre.length;e.selectionEnd=startPos+pre.length+selText.length;}else{e.selectionStart=startPos+pre.length+selText.length+post.length;e.selectionEnd=e.selectionStart;}} |
64 | | -$(this).scrollToCaretPosition();$(this).trigger('encapsulateSelection',[pre,peri,post,ownline,replace]);},getCaretPosition:function(){function getCaret(e){var caretPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1) |
| 61 | +range.select();}else if(this.selectionStart||this.selectionStart=='0'){$(this).focus();var startPos=this.selectionStart;var endPos=this.selectionEnd;checkSelectedText();if(ownline){if(startPos!=0&&this.value.charAt(startPos-1)!="\n"){pre="\n"+pre;} |
| 62 | +if(this.value.charAt(endPos)!="\n"){post+="\n";}} |
| 63 | +this.value=this.value.substring(0,startPos)+pre+selText+post+this.value.substring(endPos,this.value.length);if(isSample){this.selectionStart=startPos+pre.length;this.selectionEnd=startPos+pre.length+selText.length;}else{this.selectionStart=startPos+pre.length+selText.length+post.length;this.selectionEnd=this.selectionStart;}} |
| 64 | +$(this).scrollToCaretPosition();$(this).trigger('encapsulateSelection',[pre,peri,post,ownline,replace]);});},getCaretPosition:function(){function getCaret(e){var caretPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1) |
65 | 65 | if(preRange.text==preText){rawPreText+="\r\n";}else{postFinished=true;}}} |
66 | 66 | if(!periFinished){if(periRange.compareEndPoints("StartToEnd",periRange)==0){periFinished=true;}else{periRange.moveEnd("character",-1) |
67 | 67 | if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}} |