Skip to content
Snippets Groups Projects
Commit 28f6aae1 authored by Adrian Lang's avatar Adrian Lang
Browse files

Support getSelection in input fields in IE

parent ba29aad7
No related branches found
No related tags found
No related merge requests found
...@@ -41,7 +41,6 @@ function getSelection(textArea) { ...@@ -41,7 +41,6 @@ function getSelection(textArea) {
sel.obj = textArea; sel.obj = textArea;
sel.start = textArea.value.length; sel.start = textArea.value.length;
sel.end = textArea.value.length; sel.end = textArea.value.length;
textArea.focus(); textArea.focus();
if(document.getSelection) { // Mozilla et al. if(document.getSelection) { // Mozilla et al.
sel.start = textArea.selectionStart; sel.start = textArea.selectionStart;
...@@ -57,9 +56,13 @@ function getSelection(textArea) { ...@@ -57,9 +56,13 @@ function getSelection(textArea) {
// The current selection // The current selection
sel.rangeCopy = document.selection.createRange().duplicate(); sel.rangeCopy = document.selection.createRange().duplicate();
if (textArea.tagName === 'INPUT') {
var before_range = document.body.createTextRange(); var before_range = textArea.createTextRange();
before_range.moveToElementText(textArea); // Selects all the text before_range.expand('textedit'); // Selects all the text
} else {
var before_range = document.body.createTextRange();
before_range.moveToElementText(textArea); // Selects all the text
}
before_range.setEndPoint("EndToStart", sel.rangeCopy); // Moves the end where we need it before_range.setEndPoint("EndToStart", sel.rangeCopy); // Moves the end where we need it
var before_finished = false, selection_finished = false; var before_finished = false, selection_finished = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment