2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
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) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$('#gear-menu a[href="' + tabname + '"]').tab("show");
|
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
|
2017-11-13 21:38:00 +01:00
|
|
|
exports.place_caret_at_end = function (el) {
|
2020-07-22 02:58:29 +02:00
|
|
|
el.focus();
|
2017-11-13 21:38:00 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2020-05-12 10:50:50 +02:00
|
|
|
function update_lock_icon_for_stream(stream_name) {
|
|
|
|
const icon = $("#compose-lock-icon");
|
|
|
|
const streamfield = $("#stream_message_recipient_stream");
|
|
|
|
if (stream_data.get_invite_only(stream_name)) {
|
|
|
|
icon.show();
|
|
|
|
streamfield.addClass("lock-padding");
|
|
|
|
} else {
|
|
|
|
icon.hide();
|
|
|
|
streamfield.removeClass("lock-padding");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In an attempt to decrease mixing, set stream bar
|
|
|
|
// color look like the stream being used.
|
|
|
|
// (In particular, if there's a color associated with it,
|
|
|
|
// have that color be reflected here too.)
|
2020-05-12 11:02:13 +02:00
|
|
|
exports.decorate_stream_bar = function (stream_name, element, is_compose) {
|
|
|
|
if (stream_name === undefined) {
|
2020-09-24 07:50:36 +02:00
|
|
|
return;
|
2020-05-12 11:02:13 +02:00
|
|
|
}
|
2020-05-12 10:50:50 +02:00
|
|
|
const color = stream_data.get_color(stream_name);
|
2020-05-12 11:02:13 +02:00
|
|
|
if (is_compose) {
|
|
|
|
update_lock_icon_for_stream(stream_name);
|
|
|
|
}
|
2020-07-15 00:34:28 +02:00
|
|
|
element
|
|
|
|
.css("background-color", color)
|
2020-05-12 10:50:50 +02:00
|
|
|
.removeClass(stream_color.color_classes)
|
|
|
|
.addClass(stream_color.get_color_class(color));
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.ui_util = exports;
|