From: Derk-Jan Hartman Date: Sat, 26 Jul 2014 13:47:03 +0000 (+0200) Subject: jquery.textSelection: Add setContents function X-Git-Tag: 1.31.0-rc.0~14707^2~1 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=35d38efa4ae1c0a66937ff1a8c8200d24ae4f96b jquery.textSelection: Add setContents function This function is specified in the commands handler below, but did not have an implementation for the plain textarea case. Better we make this work. A user wanted this api call so his JS cleanup script could work consistently on both plain textarea and the CodeEditor Change-Id: Ib3afc505037a5b12269e55b4b130a38a3fac7823 --- diff --git a/resources/src/jquery/jquery.textSelection.js b/resources/src/jquery/jquery.textSelection.js index 0573f660e8..e5444ebfd6 100644 --- a/resources/src/jquery/jquery.textSelection.js +++ b/resources/src/jquery/jquery.textSelection.js @@ -62,6 +62,12 @@ getContents: function () { return this.val(); }, + /** + * Set the contents of the textarea, replacing anything that was there before + */ + setContents: function ( content ) { + this.val( content ); + }, /** * Get the currently selected text in this textarea. Will focus the textarea * in some browsers (IE/Opera) diff --git a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js index 2191c3b1c2..56b0fa92c4 100644 --- a/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js @@ -43,11 +43,7 @@ $( '#qunit-fixture' ).append( $textarea ); - // This method is actually missing atm... - //$textarea.textSelection( 'setContents', opt.before.text); - - // Won't work with the WikiEditor iframe? - $textarea.val( opt.before.text ); + $textarea.textSelection( 'setContents', opt.before.text ); start = opt.before.start; end = opt.before.end;