summaryrefslogtreecommitdiff
path: root/assets/js/core
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-12-01 20:54:33 -0500
committerFrederic Guillot <fred@kanboard.net>2016-12-01 20:54:33 -0500
commitbe83821ef7885ca45da36f15ea7a26cbf3e33fd9 (patch)
tree80c8a978db27445b52b02f7a3aef22bbd14519c9 /assets/js/core
parent9c06bc4ed25a08e75d4677834a29f801f6e42423 (diff)
Improve cross-browsers compatiblity for text editor
Diffstat (limited to 'assets/js/core')
-rw-r--r--assets/js/core/utils.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/assets/js/core/utils.js b/assets/js/core/utils.js
index 7d631526..e8e74b17 100644
--- a/assets/js/core/utils.js
+++ b/assets/js/core/utils.js
@@ -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
+ };
+};