From 6018d5fc4c8a26397d1b4cfa16a78b6fdcc8a758 Mon Sep 17 00:00:00 2001 From: John Du Hart Date: Fri, 30 Sep 2011 01:57:00 +0000 Subject: [PATCH] Followup r95572, replace insertAtCaret with textSelection per CR --- modules/ext.abuseFilter.edit.js | 38 +++------------------------------ 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/modules/ext.abuseFilter.edit.js b/modules/ext.abuseFilter.edit.js index 52c2d7b3b..63680ff99 100644 --- a/modules/ext.abuseFilter.edit.js +++ b/modules/ext.abuseFilter.edit.js @@ -96,7 +96,9 @@ new ( function( $, mw ) { return; } - $filterBox.insertAtCaret( $filterBuilder.val() + " " ); + $filterBox.textSelection( + 'encapsulateSelection', { 'pre': $filterBuilder.val() + " " } + ); $filterBuilder.prop( 'selectedIndex', 0 ); }; @@ -172,40 +174,6 @@ new ( function( $, mw ) { window.location = mw.config.get( 'wgScript' ) + '?title=MediaWiki:' + mw.util.wikiUrlencode( message ) + '&action=edit'; }; - // From http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery/2819568#2819568 - $.fn.extend({ - /** - * Inserts a string in a textarea at the current caret position - * - * @param {String} myValue String to insert - * @returns {jQuery} - */ - insertAtCaret: function(myValue){ - return this.each( function() { - if ( document.selection ) { - this.focus(); - sel = document.selection.createRange(); - sel.text = myValue; - this.focus(); - } else if ( this.selectionStart || this.selectionStart == '0' ) { - var startPos = this.selectionStart; - var endPos = this.selectionEnd; - var scrollTop = this.scrollTop; - this.value = this.value.substring( 0, startPos ) - + myValue - + this.value.substring( endPos, this.value.length ); - this.focus(); - this.selectionStart = startPos + myValue.length; - this.selectionEnd = startPos + myValue.length; - this.scrollTop = scrollTop; - } else { - this.value += myValue; - this.focus(); - } - } ); - } - }); - /* * On ready initialization */