From b03a6af0c848cf6bb10ea43dcc6cdc9aeeac2051 Mon Sep 17 00:00:00 2001 From: Dan Bauer Date: Sun, 9 Apr 2017 14:34:04 -0700 Subject: [PATCH] added -nofocus variant of all methods --- README.md | 6 +++++- bower.json | 2 +- jquery-textrange.js | 7 +++++-- package.json | 2 +- textrange.jquery.json | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8de815d..ab3f1c0 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ $('input[name="example"]').textrange('setcursor', 5); ### 'replace' -You can use this method to replace the selection with given text. +You can use this method to replace the selection with given text. ```javascript $('input[name="example"]').textrange('replace', 'some text'); @@ -115,6 +115,10 @@ $('input[name="example"]').textrange('replace', 'some text'); There is also an `insert` alias for `replace` if you're using this method to insert text at the cursor location. They work the same way. +### 'get-nofocus', 'set-nofocus', 'setcursor-nofocus', 'replace-nofocus', 'insert-nofocus' + +You can add the suffix '-nofocus' to any of the method names to perform the corresponding operation without setting focus on the target element. + ## Minified Version A minified version of this plugin can be generated using UglifyJS during your build process or via CLI tools: diff --git a/bower.json b/bower.json index 8f0cb9a..74d465a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-textrange", - "version": "1.3.3", + "version": "1.3.4", "main": "jquery-textrange.js", "dependencies": { "jquery": ">=1.3" diff --git a/jquery-textrange.js b/jquery-textrange.js index c66c6c9..e764c8e 100644 --- a/jquery-textrange.js +++ b/jquery-textrange.js @@ -230,8 +230,11 @@ return this; } - // Focus on the element before operating upon it. - if (document.activeElement !== this[0]) { + // Focus on the element before operating upon it, + // unless the specified method ends in '-nofocus' + if (method.slice(-8)==='-nofocus') { + method = method.slice(0,-8); //strip the -nofocus suffix and bypass focus() + } else if (document.activeElement !== this[0]) { this[0].focus(); } diff --git a/package.json b/package.json index a9e8006..34d5de9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-textrange", - "version": "1.3.3", + "version": "1.3.4", "description": "A jQuery plugin for getting, setting and replacing the selected text in input fields and textareas.", "main": "jquery-textrange.js", "dependencies": { diff --git a/textrange.jquery.json b/textrange.jquery.json index 6913a8d..9272ee6 100644 --- a/textrange.jquery.json +++ b/textrange.jquery.json @@ -18,7 +18,7 @@ "substring", "substr" ], - "version": "1.3.3", + "version": "1.3.4", "author": { "name": "Daniel Imhoff", "email": "dwieeb@gmail.com",