mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
js: Remove some pointless IIFEs.
Some of these were there because they predate block-scoped const/let. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
707d23d1e8
commit
fc9481a24e
@@ -607,13 +607,13 @@ export function initialize() {
|
|||||||
|
|
||||||
// MISC
|
// MISC
|
||||||
|
|
||||||
(function () {
|
{
|
||||||
const sel = ["#stream_filters", "#global_filters", "#user_presences"].join(", ");
|
const sel = ["#stream_filters", "#global_filters", "#user_presences"].join(", ");
|
||||||
|
|
||||||
$(sel).on("click", "a", function () {
|
$(sel).on("click", "a", function () {
|
||||||
this.blur();
|
this.blur();
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
|
|
||||||
popovers.register_click_handlers();
|
popovers.register_click_handlers();
|
||||||
emoji_picker.register_click_handlers();
|
emoji_picker.register_click_handlers();
|
||||||
@@ -765,7 +765,7 @@ export function initialize() {
|
|||||||
// Don't focus links on context menu.
|
// Don't focus links on context menu.
|
||||||
$("body").on("contextmenu", "a", (e) => e.target.blur());
|
$("body").on("contextmenu", "a", (e) => e.target.blur());
|
||||||
|
|
||||||
(function () {
|
{
|
||||||
const map = {
|
const map = {
|
||||||
".stream-description-editable": {
|
".stream-description-editable": {
|
||||||
on_start: stream_edit.set_raw_description,
|
on_start: stream_edit.set_raw_description,
|
||||||
@@ -841,7 +841,7 @@ export function initialize() {
|
|||||||
$(`[data-make-editable='${CSS.escape(selector)}']`).html("");
|
$(`[data-make-editable='${CSS.escape(selector)}']`).html("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
|
|
||||||
// HOTSPOTS
|
// HOTSPOTS
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ import * as keydown_util from "./keydown_util";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function toggle(opts) {
|
export function toggle(opts) {
|
||||||
const component = (function render_component(opts) {
|
const component = $("<div class='tab-switcher'></div>");
|
||||||
const _component = $("<div class='tab-switcher'></div>");
|
|
||||||
if (opts.html_class) {
|
if (opts.html_class) {
|
||||||
// add a check inside passed arguments in case some extra
|
// add a check inside passed arguments in case some extra
|
||||||
// classes need to be added for correct alignment or other purposes
|
// classes need to be added for correct alignment or other purposes
|
||||||
_component.addClass(opts.html_class);
|
component.addClass(opts.html_class);
|
||||||
}
|
}
|
||||||
for (const [i, value] of opts.values.entries()) {
|
for (const [i, value] of opts.values.entries()) {
|
||||||
// create a tab with a tab-id so they don't have to be referenced
|
// create a tab with a tab-id so they don't have to be referenced
|
||||||
@@ -48,10 +47,8 @@ export function toggle(opts) {
|
|||||||
} else {
|
} else {
|
||||||
tab.addClass("middle");
|
tab.addClass("middle");
|
||||||
}
|
}
|
||||||
_component.append(tab);
|
component.append(tab);
|
||||||
}
|
}
|
||||||
return _component;
|
|
||||||
})(opts);
|
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
$ind_tab: component.find(".ind-tab"),
|
$ind_tab: component.find(".ind-tab"),
|
||||||
@@ -103,7 +100,6 @@ export function toggle(opts) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
(function () {
|
|
||||||
meta.$ind_tab.on("click", function () {
|
meta.$ind_tab.on("click", function () {
|
||||||
const idx = $(this).data("tab-id");
|
const idx = $(this).data("tab-id");
|
||||||
select_tab(idx);
|
select_tab(idx);
|
||||||
@@ -121,7 +117,6 @@ export function toggle(opts) {
|
|||||||
if (typeof opts.selected === "number") {
|
if (typeof opts.selected === "number") {
|
||||||
select_tab(opts.selected);
|
select_tab(opts.selected);
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
const prototype = {
|
const prototype = {
|
||||||
// Skip disabled tabs and go to the next one.
|
// Skip disabled tabs and go to the next one.
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ export function create(opts) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
(function events() {
|
{
|
||||||
store.$parent.on("keydown", ".input", (e) => {
|
store.$parent.on("keydown", ".input", (e) => {
|
||||||
const char = e.keyCode || e.charCode;
|
const char = e.keyCode || e.charCode;
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ export function create(opts) {
|
|||||||
);
|
);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
|
|
||||||
// the external, user-accessible prototype.
|
// the external, user-accessible prototype.
|
||||||
const prototype = {
|
const prototype = {
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ export function activate(raw_operators, opts) {
|
|||||||
|
|
||||||
const select_immediately = id_info.local_select_id !== undefined;
|
const select_immediately = id_info.local_select_id !== undefined;
|
||||||
|
|
||||||
(function fetch_messages() {
|
{
|
||||||
let anchor;
|
let anchor;
|
||||||
|
|
||||||
// Either we're trying to center the narrow around a
|
// Either we're trying to center the narrow around a
|
||||||
@@ -354,7 +354,7 @@ export function activate(raw_operators, opts) {
|
|||||||
maybe_report_narrow_time(msg_list);
|
maybe_report_narrow_time(msg_list);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
|
|
||||||
if (select_immediately) {
|
if (select_immediately) {
|
||||||
update_selection({
|
update_selection({
|
||||||
|
|||||||
@@ -85,21 +85,17 @@ function elem_to_user_id(elem) {
|
|||||||
// and push the $.fn.data($o, "popover") results to an array.
|
// and push the $.fn.data($o, "popover") results to an array.
|
||||||
// this is needed so that when we try to unload popovers, we can kill all dead
|
// this is needed so that when we try to unload popovers, we can kill all dead
|
||||||
// ones that no longer have valid parents in the DOM.
|
// ones that no longer have valid parents in the DOM.
|
||||||
(function (popover) {
|
const old_popover = $.fn.popover;
|
||||||
$.fn.popover = function (...args) {
|
$.fn.popover = Object.assign(function (...args) {
|
||||||
// apply the jQuery object as `this`, and popover function arguments.
|
// apply the jQuery object as `this`, and popover function arguments.
|
||||||
popover.apply(this, args);
|
old_popover.apply(this, args);
|
||||||
|
|
||||||
// if there is a valid "popover" key in the jQuery data object then
|
// if there is a valid "popover" key in the jQuery data object then
|
||||||
// push it to the array.
|
// push it to the array.
|
||||||
if (this.data("popover")) {
|
if (this.data("popover")) {
|
||||||
list_of_popovers.push(this.data("popover"));
|
list_of_popovers.push(this.data("popover"));
|
||||||
}
|
}
|
||||||
};
|
}, old_popover);
|
||||||
|
|
||||||
// add back all shallow properties of $.fn.popover to the new proxied version.
|
|
||||||
Object.assign($.fn.popover, popover);
|
|
||||||
})($.fn.popover);
|
|
||||||
|
|
||||||
function copy_email_handler(e) {
|
function copy_email_handler(e) {
|
||||||
const email_el = $(e.trigger.parentElement);
|
const email_el = $(e.trigger.parentElement);
|
||||||
@@ -1325,7 +1321,7 @@ export function register_click_handlers() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
(function () {
|
{
|
||||||
let last_scroll = 0;
|
let last_scroll = 0;
|
||||||
|
|
||||||
$(".app").on("scroll", () => {
|
$(".app").on("scroll", () => {
|
||||||
@@ -1346,7 +1342,7 @@ export function register_click_handlers() {
|
|||||||
// retrigger `hide_all` while still scrolling.
|
// retrigger `hide_all` while still scrolling.
|
||||||
last_scroll = date;
|
last_scroll = date;
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function any_active() {
|
export function any_active() {
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ function left_userlist_get_new_heights() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function watch_manual_resize(element) {
|
export function watch_manual_resize(element) {
|
||||||
return (function on_box_resize(cb) {
|
|
||||||
const box = document.querySelector(element);
|
const box = document.querySelector(element);
|
||||||
|
|
||||||
if (!box) {
|
if (!box) {
|
||||||
@@ -145,23 +144,19 @@ export function watch_manual_resize(element) {
|
|||||||
|
|
||||||
// If the user resizes the textarea manually, we use the
|
// If the user resizes the textarea manually, we use the
|
||||||
// callback to stop autosize from adjusting the height.
|
// callback to stop autosize from adjusting the height.
|
||||||
|
// It will be re-enabled when this component is next opened.
|
||||||
const body_handler = function () {
|
const body_handler = function () {
|
||||||
if (meta.mousedown === true) {
|
if (meta.mousedown === true) {
|
||||||
meta.mousedown = false;
|
meta.mousedown = false;
|
||||||
if (meta.height !== meta.box.clientHeight) {
|
if (meta.height !== meta.box.clientHeight) {
|
||||||
meta.height = meta.box.clientHeight;
|
meta.height = meta.box.clientHeight;
|
||||||
cb.call(meta.box, meta.height);
|
autosize.destroy($(element)).height(meta.height + "px");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
document.body.addEventListener("mouseup", body_handler);
|
document.body.addEventListener("mouseup", body_handler);
|
||||||
|
|
||||||
return [box_handler, body_handler];
|
return [box_handler, body_handler];
|
||||||
})((height) => {
|
|
||||||
// This callback disables autosize on the textarea. It
|
|
||||||
// will be re-enabled when this component is next opened.
|
|
||||||
autosize.destroy($(element)).height(height + "px");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resize_bottom_whitespace(h) {
|
export function resize_bottom_whitespace(h) {
|
||||||
|
|||||||
@@ -279,10 +279,7 @@ export function populate_user_groups() {
|
|||||||
pill_typeahead.set_up(input, pills, opts);
|
pill_typeahead.set_up(input, pills, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
(function pill_remove() {
|
if (can_edit(data.id)) {
|
||||||
if (!can_edit(data.id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pills.onPillRemove(() => {
|
pills.onPillRemove(() => {
|
||||||
// onPillRemove is fired before the pill is removed from
|
// onPillRemove is fired before the pill is removed from
|
||||||
// the DOM.
|
// the DOM.
|
||||||
@@ -291,7 +288,7 @@ export function populate_user_groups() {
|
|||||||
input.trigger("focus");
|
input.trigger("focus");
|
||||||
}, 100);
|
}, 100);
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1030,7 +1030,7 @@ export function initialize() {
|
|||||||
$(".subscriptions-header").removeClass("slide-left");
|
$(".subscriptions-header").removeClass("slide-left");
|
||||||
});
|
});
|
||||||
|
|
||||||
(function defocus_sub_settings() {
|
{
|
||||||
const sel = ".search-container, .streams-list, .subscriptions-header";
|
const sel = ".search-container, .streams-list, .subscriptions-header";
|
||||||
|
|
||||||
$("#subscriptions_table").on("click", sel, (e) => {
|
$("#subscriptions_table").on("click", sel, (e) => {
|
||||||
@@ -1038,5 +1038,5 @@ export function initialize() {
|
|||||||
stream_edit.open_edit_panel_empty();
|
stream_edit.open_edit_panel_empty();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ export function process_fenced_code(content) {
|
|||||||
function handler_for_fence(output_lines, fence, lang, header) {
|
function handler_for_fence(output_lines, fence, lang, header) {
|
||||||
// lang is ignored except for 'quote', as we
|
// lang is ignored except for 'quote', as we
|
||||||
// don't do syntax highlighting yet
|
// don't do syntax highlighting yet
|
||||||
return (function () {
|
|
||||||
const lines = [];
|
const lines = [];
|
||||||
if (lang === "quote") {
|
if (lang === "quote") {
|
||||||
return {
|
return {
|
||||||
@@ -180,7 +179,6 @@ export function process_fenced_code(content) {
|
|||||||
handler_stack.pop();
|
handler_stack.pop();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function default_hander() {
|
function default_hander() {
|
||||||
|
|||||||
Reference in New Issue
Block a user