Files
zulip/static/js/ui_util.js
Steve Howell 1cee29c2d1 refactor: Extract stream_bar.decorate.
This makes input_pill no longer depend on
stream_data and stream_color, and it
probably reduces some other dependencies.
2021-03-22 13:21:56 -07:00

33 lines
1.1 KiB
JavaScript

import $ from "jquery";
// Add functions to this that have no non-trivial
// dependencies other than jQuery.
export function change_tab_to(tabname) {
$(`#gear-menu a[href="${CSS.escape(tabname)}"]`).tab("show");
}
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
export function place_caret_at_end(el) {
el.focus();
if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {
const range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange !== "undefined") {
const textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
}
export function blur_active_element() {
// this blurs anything that may perhaps be actively focused on.
document.activeElement.blur();
}