2017-03-18 21:35:35 +01:00
|
|
|
// Add functions to this that have no non-trivial
|
|
|
|
// dependencies other than jQuery.
|
|
|
|
|
|
|
|
exports.change_tab_to = function (tabname) {
|
|
|
|
$('#gear-menu a[href="' + tabname + '"]').tab('show');
|
|
|
|
};
|
|
|
|
|
2020-03-27 01:32:21 +01:00
|
|
|
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
|
2017-11-13 21:38:00 +01:00
|
|
|
exports.place_caret_at_end = function (el) {
|
|
|
|
el.focus();
|
|
|
|
|
|
|
|
if (typeof window.getSelection !== "undefined"
|
|
|
|
&& typeof 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);
|
|
|
|
} else if (typeof 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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-18 21:35:35 +01:00
|
|
|
exports.blur_active_element = function () {
|
|
|
|
// this blurs anything that may perhaps be actively focused on.
|
|
|
|
document.activeElement.blur();
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.ui_util = exports;
|