2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2017-03-18 21:35:35 +01:00
|
|
|
// Add functions to this that have no non-trivial
|
|
|
|
// dependencies other than jQuery.
|
|
|
|
|
2021-02-28 01:00:36 +01:00
|
|
|
export function change_tab_to(tabname) {
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#gear-menu a[href="${CSS.escape(tabname)}"]`).tab("show");
|
2021-02-28 01:00:36 +01:00
|
|
|
}
|
2017-03-18 21:35:35 +01:00
|
|
|
|
2020-03-27 01:32:21 +01:00
|
|
|
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
|
2021-02-28 01:00:36 +01:00
|
|
|
export function place_caret_at_end(el) {
|
2020-07-22 02:58:29 +02:00
|
|
|
el.focus();
|
2017-11-13 21:38:00 +01:00
|
|
|
|
2021-03-24 20:14:12 +01:00
|
|
|
if (window.getSelection !== undefined && document.createRange !== undefined) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const range = document.createRange();
|
2017-11-13 21:38:00 +01:00
|
|
|
range.selectNodeContents(el);
|
|
|
|
range.collapse(false);
|
2019-11-02 00:06:25 +01:00
|
|
|
const sel = window.getSelection();
|
2017-11-13 21:38:00 +01:00
|
|
|
sel.removeAllRanges();
|
|
|
|
sel.addRange(range);
|
2021-03-24 20:14:12 +01:00
|
|
|
} else if (document.body.createTextRange !== undefined) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const textRange = document.body.createTextRange();
|
2017-11-13 21:38:00 +01:00
|
|
|
textRange.moveToElementText(el);
|
|
|
|
textRange.collapse(false);
|
|
|
|
textRange.select();
|
|
|
|
}
|
2021-02-28 01:00:36 +01:00
|
|
|
}
|
2017-11-13 21:38:00 +01:00
|
|
|
|
2021-02-28 01:00:36 +01:00
|
|
|
export function blur_active_element() {
|
2017-03-18 21:35:35 +01:00
|
|
|
// this blurs anything that may perhaps be actively focused on.
|
|
|
|
document.activeElement.blur();
|
2021-02-28 01:00:36 +01:00
|
|
|
}
|
2021-03-31 05:36:08 +02:00
|
|
|
|
|
|
|
export function convert_enter_to_click(e) {
|
|
|
|
const key = e.which;
|
|
|
|
if (key === 13) {
|
|
|
|
// Enter
|
|
|
|
$(e.currentTarget).trigger("click");
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 09:18:43 +02:00
|
|
|
|
|
|
|
export function update_unread_count_in_dom(unread_count_elem, count) {
|
|
|
|
// This function is used to update unread count in top left corner
|
|
|
|
// elements.
|
2021-04-09 09:20:15 +02:00
|
|
|
const unread_count_span = unread_count_elem.find(".unread_count");
|
2021-04-09 09:18:43 +02:00
|
|
|
|
|
|
|
if (count === 0) {
|
2021-04-09 09:20:15 +02:00
|
|
|
unread_count_span.hide();
|
|
|
|
unread_count_span.text("");
|
2021-04-09 09:18:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-09 09:20:15 +02:00
|
|
|
unread_count_span.show();
|
|
|
|
unread_count_span.text(count);
|
2021-04-09 09:18:43 +02:00
|
|
|
}
|