mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +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
|
||||
|
||||
(function () {
|
||||
{
|
||||
const sel = ["#stream_filters", "#global_filters", "#user_presences"].join(", ");
|
||||
|
||||
$(sel).on("click", "a", function () {
|
||||
this.blur();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
popovers.register_click_handlers();
|
||||
emoji_picker.register_click_handlers();
|
||||
@@ -765,7 +765,7 @@ export function initialize() {
|
||||
// Don't focus links on context menu.
|
||||
$("body").on("contextmenu", "a", (e) => e.target.blur());
|
||||
|
||||
(function () {
|
||||
{
|
||||
const map = {
|
||||
".stream-description-editable": {
|
||||
on_start: stream_edit.set_raw_description,
|
||||
@@ -841,7 +841,7 @@ export function initialize() {
|
||||
$(`[data-make-editable='${CSS.escape(selector)}']`).html("");
|
||||
}
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
// HOTSPOTS
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@ import * as keydown_util from "./keydown_util";
|
||||
*/
|
||||
|
||||
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) {
|
||||
// add a check inside passed arguments in case some extra
|
||||
// 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()) {
|
||||
// create a tab with a tab-id so they don't have to be referenced
|
||||
@@ -48,10 +47,8 @@ export function toggle(opts) {
|
||||
} else {
|
||||
tab.addClass("middle");
|
||||
}
|
||||
_component.append(tab);
|
||||
component.append(tab);
|
||||
}
|
||||
return _component;
|
||||
})(opts);
|
||||
|
||||
const meta = {
|
||||
$ind_tab: component.find(".ind-tab"),
|
||||
@@ -103,7 +100,6 @@ export function toggle(opts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
(function () {
|
||||
meta.$ind_tab.on("click", function () {
|
||||
const idx = $(this).data("tab-id");
|
||||
select_tab(idx);
|
||||
@@ -121,7 +117,6 @@ export function toggle(opts) {
|
||||
if (typeof opts.selected === "number") {
|
||||
select_tab(opts.selected);
|
||||
}
|
||||
})();
|
||||
|
||||
const prototype = {
|
||||
// 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) => {
|
||||
const char = e.keyCode || e.charCode;
|
||||
|
||||
@@ -380,7 +380,7 @@ export function create(opts) {
|
||||
);
|
||||
e.preventDefault();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
// the external, user-accessible prototype.
|
||||
const prototype = {
|
||||
|
||||
@@ -321,7 +321,7 @@ export function activate(raw_operators, opts) {
|
||||
|
||||
const select_immediately = id_info.local_select_id !== undefined;
|
||||
|
||||
(function fetch_messages() {
|
||||
{
|
||||
let anchor;
|
||||
|
||||
// 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);
|
||||
},
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
if (select_immediately) {
|
||||
update_selection({
|
||||
|
||||
@@ -85,21 +85,17 @@ function elem_to_user_id(elem) {
|
||||
// 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
|
||||
// ones that no longer have valid parents in the DOM.
|
||||
(function (popover) {
|
||||
$.fn.popover = function (...args) {
|
||||
const old_popover = $.fn.popover;
|
||||
$.fn.popover = Object.assign(function (...args) {
|
||||
// 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
|
||||
// push it to the array.
|
||||
if (this.data("popover")) {
|
||||
list_of_popovers.push(this.data("popover"));
|
||||
}
|
||||
};
|
||||
|
||||
// add back all shallow properties of $.fn.popover to the new proxied version.
|
||||
Object.assign($.fn.popover, popover);
|
||||
})($.fn.popover);
|
||||
}, old_popover);
|
||||
|
||||
function copy_email_handler(e) {
|
||||
const email_el = $(e.trigger.parentElement);
|
||||
@@ -1325,7 +1321,7 @@ export function register_click_handlers() {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
(function () {
|
||||
{
|
||||
let last_scroll = 0;
|
||||
|
||||
$(".app").on("scroll", () => {
|
||||
@@ -1346,7 +1342,7 @@ export function register_click_handlers() {
|
||||
// retrigger `hide_all` while still scrolling.
|
||||
last_scroll = date;
|
||||
});
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
export function any_active() {
|
||||
|
||||
@@ -123,7 +123,6 @@ function left_userlist_get_new_heights() {
|
||||
}
|
||||
|
||||
export function watch_manual_resize(element) {
|
||||
return (function on_box_resize(cb) {
|
||||
const box = document.querySelector(element);
|
||||
|
||||
if (!box) {
|
||||
@@ -145,23 +144,19 @@ export function watch_manual_resize(element) {
|
||||
|
||||
// If the user resizes the textarea manually, we use the
|
||||
// callback to stop autosize from adjusting the height.
|
||||
// It will be re-enabled when this component is next opened.
|
||||
const body_handler = function () {
|
||||
if (meta.mousedown === true) {
|
||||
meta.mousedown = false;
|
||||
if (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);
|
||||
|
||||
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) {
|
||||
|
||||
@@ -279,10 +279,7 @@ export function populate_user_groups() {
|
||||
pill_typeahead.set_up(input, pills, opts);
|
||||
}
|
||||
|
||||
(function pill_remove() {
|
||||
if (!can_edit(data.id)) {
|
||||
return;
|
||||
}
|
||||
if (can_edit(data.id)) {
|
||||
pills.onPillRemove(() => {
|
||||
// onPillRemove is fired before the pill is removed from
|
||||
// the DOM.
|
||||
@@ -291,7 +288,7 @@ export function populate_user_groups() {
|
||||
input.trigger("focus");
|
||||
}, 100);
|
||||
});
|
||||
})();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1030,7 +1030,7 @@ export function initialize() {
|
||||
$(".subscriptions-header").removeClass("slide-left");
|
||||
});
|
||||
|
||||
(function defocus_sub_settings() {
|
||||
{
|
||||
const sel = ".search-container, .streams-list, .subscriptions-header";
|
||||
|
||||
$("#subscriptions_table").on("click", sel, (e) => {
|
||||
@@ -1038,5 +1038,5 @@ export function initialize() {
|
||||
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) {
|
||||
// lang is ignored except for 'quote', as we
|
||||
// don't do syntax highlighting yet
|
||||
return (function () {
|
||||
const lines = [];
|
||||
if (lang === "quote") {
|
||||
return {
|
||||
@@ -180,7 +179,6 @@ export function process_fenced_code(content) {
|
||||
handler_stack.pop();
|
||||
},
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
function default_hander() {
|
||||
|
||||
Reference in New Issue
Block a user