Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Remove ancient IE createTextRange API.

Anders Kaseorg95185451289d
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index cb816e013f6..3ffe51d5ea3 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -181,8 +181,7 @@ export function initialize() {
// on the other hand, on mobile it should be done with a long tap.
} else {
$("#main_div").on("longtap", ".messagebox", function (e) {
- // find the correct selection API for the browser.
- const sel = window.getSelection ? window.getSelection() : document.selection;
+ const sel = window.getSelection();
// if one matches, remove the current selections.
// after a longtap that is valid, there should be no text selected.
if (sel) {
diff --git a/static/js/subs.js b/static/js/subs.js
index a8d23aecaf8..7d5544a26ed 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -117,20 +117,12 @@ export function get_active_data() {
}
function selectText(element) {
- let range;
- let sel;
- if (window.getSelection) {
- sel = window.getSelection();
- range = document.createRange();
- range.selectNodeContents(element);
-
- sel.removeAllRanges();
- sel.addRange(range);
- } else if (document.body.createTextRange) {
- range = document.body.createTextRange();
- range.moveToElementText(element);
- range.select();
- }
+ const sel = window.getSelection();
+ const range = document.createRange();
+ range.selectNodeContents(element);
+
+ sel.removeAllRanges();
+ sel.addRange(range);
}
function should_list_all_streams() {
diff --git a/static/js/ui_util.js b/static/js/ui_util.js
index b88c01f1f73..6ac5b3d7c93 100644
--- a/static/js/ui_util.js
+++ b/static/js/ui_util.js
@@ -11,19 +11,12 @@ export function change_tab_to(tabname) {
export function place_caret_at_end(el) {
el.focus();
- if (window.getSelection !== undefined && document.createRange !== undefined) {
- const range = document.createRange();
- range.selectNodeContents(el);
- range.collapse(false);
- const sel = window.getSelection();
- sel.removeAllRanges();
- sel.addRange(range);
- } else if (document.body.createTextRange !== undefined) {
- const textRange = document.body.createTextRange();
- textRange.moveToElementText(el);
- textRange.collapse(false);
- textRange.select();
- }
+ const range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ const sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
}
export function blur_active_element() {