Skip to content

Commit d61a22a

Browse files
committed
selectionStart is not supported by every HTML 5 input type, so jut ignore it, refs #45, #39, #20
1 parent 0adedc0 commit d61a22a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/angular-advanced-searchbox.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,23 @@ angular.module('angular-advanced-searchbox', [])
277277
}
278278

279279
function getCurrentCaretPosition(input) {
280-
if (!input || input.type !== 'text')
280+
if (!input)
281281
return 0;
282282

283-
// Firefox & co
284-
if (typeof input.selectionStart === 'number') {
285-
return input.selectionDirection === 'backward' ? input.selectionStart : input.selectionEnd;
286-
287-
} else if (document.selection) { // IE
288-
input.focus();
289-
var selection = document.selection.createRange();
290-
var selectionLength = document.selection.createRange().text.length;
291-
selection.moveStart('character', -input.value.length);
292-
return selection.text.length - selectionLength;
283+
try {
284+
// Firefox & co
285+
if (typeof input.selectionStart === 'number') {
286+
return input.selectionDirection === 'backward' ? input.selectionStart : input.selectionEnd;
287+
288+
} else if (document.selection) { // IE
289+
input.focus();
290+
var selection = document.selection.createRange();
291+
var selectionLength = document.selection.createRange().text.length;
292+
selection.moveStart('character', -input.value.length);
293+
return selection.text.length - selectionLength;
294+
}
295+
} catch(err) {
296+
// selectionStart is not supported by HTML 5 input type, so jut ignore it
293297
}
294298

295299
return 0;

0 commit comments

Comments
 (0)