Improve cross-browsers compatiblity for text editor

This commit is contained in:
Frederic Guillot
2016-12-01 20:54:33 -05:00
parent 9c06bc4ed2
commit be83821ef7
4 changed files with 35 additions and 18 deletions

View File

@@ -11,3 +11,24 @@ KB.utils.formatDuration = function (d) {
return d + "s";
};
KB.utils.getSelectionPosition = function (element) {
var selectionStart, selectionEnd;
if (element.value.length < element.selectionStart) {
selectionStart = element.value.length;
} else {
selectionStart = element.selectionStart;
}
if (element.selectionStart === element.selectionEnd) {
selectionEnd = selectionStart;
} else {
selectionEnd = element.selectionEnd;
}
return {
selectionStart: selectionStart,
selectionEnd: selectionEnd
};
};