Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Remove some pointless IIFEs.

Anders Kaseorgfc9481a24e62
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 015a14687df..b5c455d0641 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -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
diff --git a/static/js/components.js b/static/js/components.js
index fa91a6bcfd7..f0107a22ca1 100644
--- a/static/js/components.js
+++ b/static/js/components.js
@@ -14,44 +14,41 @@ import * as keydown_util from "./keydown_util";
*/
export function toggle(opts) {
- const component = (function render_component(opts) {
- 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);
+ 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);
+ }
+ for (const [i, value] of opts.values.entries()) {
+ // create a tab with a tab-id so they don't have to be referenced
+ // by text value which can be inconsistent.
+ const tab = $("<div>", {
+ class: "ind-tab",
+ "data-tab-key": value.key,
+ "data-tab-id": i,
+ tabindex: 0,
+ });
+
+ /* istanbul ignore if */
+ if (value.label_html !== undefined) {
+ const html = value.label_html;
+ tab.html(html);
+ } else {
+ tab.text(value.label);
}
- for (const [i, value] of opts.values.entries()) {
- // create a tab with a tab-id so they don't have to be referenced
- // by text value which can be inconsistent.
- const tab = $("<div>", {
- class: "ind-tab",
- "data-tab-key": value.key,
- "data-tab-id": i,
- tabindex: 0,
- });
-
- /* istanbul ignore if */
- if (value.label_html !== undefined) {
- const html = value.label_html;
- tab.html(html);
- } else {
- tab.text(value.label);
- }
- // add proper classes for styling in CSS.
- if (i === 0) {
- // this should be default selected unless otherwise specified.
- tab.addClass("first selected");
- } else if (i === opts.values.length - 1) {
- tab.addClass("last");
- } else {
- tab.addClass("middle");
- }
- _component.append(tab);
+ // add proper classes for styling in CSS.
+ if (i === 0) {
+ // this should be default selected unless otherwise specified.
+ tab.addClass("first selected");
+ } else if (i === opts.values.length - 1) {
+ tab.addClass("last");
+ } else {
+ tab.addClass("middle");
}
- return _component;
- })(opts);
+ component.append(tab);
+ }
const meta = {
$ind_tab: component.find(".ind-tab"),
@@ -103,25 +100,23 @@ export function toggle(opts) {
return false;
}
- (function () {
- meta.$ind_tab.on("click", function () {
- const idx = $(this).data("tab-id");
- select_tab(idx);
- });
+ meta.$ind_tab.on("click", function () {
+ const idx = $(this).data("tab-id");
+ select_tab(idx);
+ });
- keydown_util.handle({
- elem: meta.$ind_tab,
- handlers: {
- left_arrow: maybe_go_left,
- right_arrow: maybe_go_right,
- },
- });
+ keydown_util.handle({
+ elem: meta.$ind_tab,
+ handlers: {
+ left_arrow: maybe_go_left,
+ right_arrow: maybe_go_right,
+ },
+ });
- // We should arguably default opts.selected to 0.
- if (typeof opts.selected === "number") {
- select_tab(opts.selected);
- }
- })();
+ // We should arguably default opts.selected to 0.
+ if (typeof opts.selected === "number") {
+ select_tab(opts.selected);
+ }
const prototype = {
// Skip disabled tabs and go to the next one.
diff --git a/static/js/input_pill.js b/static/js/input_pill.js
index 85f30ea00a4..4d04e6ce0fe 100644
--- a/static/js/input_pill.js
+++ b/static/js/input_pill.js
@@ -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 = {
diff --git a/static/js/narrow.js b/static/js/narrow.js
index 805b6547687..c0c18f03f0e 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -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({
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 35b5d1cbb63..bc24c516e82 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -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) {
- // apply the jQuery object as `this`, and popover function arguments.
- 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);
+const old_popover = $.fn.popover;
+$.fn.popover = Object.assign(function (...args) {
+ // apply the jQuery object as `this`, and popover function arguments.
+ 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"));
+ }
+}, 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() {
diff --git a/static/js/resize.js b/static/js/resize.js
index 07056df32fe..55526a54af6 100644
--- a/static/js/resize.js
+++ b/static/js/resize.js
@@ -123,45 +123,40 @@ function left_userlist_get_new_heights() {
}
export function watch_manual_resize(element) {
- return (function on_box_resize(cb) {
- const box = document.querySelector(element);
+ const box = document.querySelector(element);
- if (!box) {
- blueslip.error("Bad selector in watch_manual_resize: " + element);
- return undefined;
- }
+ if (!box) {
+ blueslip.error("Bad selector in watch_manual_resize: " + element);
+ return undefined;
+ }
- const meta = {
- box,
- height: null,
- mousedown: false,
- };
-
- const box_handler = function () {
- meta.mousedown = true;
- meta.height = meta.box.clientHeight;
- };
- meta.box.addEventListener("mousedown", box_handler);
-
- // If the user resizes the textarea manually, we use the
- // callback to stop autosize from adjusting the height.
- 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);
- }
+ const meta = {
+ box,
+ height: null,
+ mousedown: false,
+ };
+
+ const box_handler = function () {
+ meta.mousedown = true;
+ meta.height = meta.box.clientHeight;
+ };
+ meta.box.addEventListener("mousedown", box_handler);
+
+ // 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;
+ 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");
- });
+ }
+ };
+ document.body.addEventListener("mouseup", body_handler);
+
+ return [box_handler, body_handler];
}
export function resize_bottom_whitespace(h) {
diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js
index ad9cc2704d8..79fb3357341 100644
--- a/static/js/settings_user_groups.js
+++ b/static/js/settings_user_groups.js
@@ -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);
});
- })();
+ }
}
}
diff --git a/static/js/subs.js b/static/js/subs.js
index 062339c0749..dd88563f91e 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -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();
}
});
- })();
+ }
}
diff --git a/static/shared/js/fenced_code.js b/static/shared/js/fenced_code.js
index 05fe65a4da2..5c2fb5ab52f 100644
--- a/static/shared/js/fenced_code.js
+++ b/static/shared/js/fenced_code.js
@@ -106,81 +106,79 @@ 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 {
- handle_line(line) {
- if (line === fence) {
- this.done();
- } else {
- consume_line(lines, line);
- }
- },
-
- done() {
- const text = wrap_quote(lines.join("\n"));
- output_lines.push("", text, "");
- handler_stack.pop();
- },
- };
- }
-
- if (lang === "math") {
- return {
- handle_line(line) {
- if (line === fence) {
- this.done();
- } else {
- lines.push(line);
- }
- },
-
- done() {
- const text = wrap_tex(lines.join("\n"));
- const placeholder = stash_func(text, true);
- output_lines.push("", placeholder, "");
- handler_stack.pop();
- },
- };
- }
-
- if (lang === "spoiler") {
- return {
- handle_line(line) {
- if (line === fence) {
- this.done();
- } else {
- lines.push(line);
- }
- },
-
- done() {
- const text = wrap_spoiler(header, lines.join("\n"), stash_func);
- output_lines.push("", text, "");
- handler_stack.pop();
- },
- };
- }
+ const lines = [];
+ if (lang === "quote") {
+ return {
+ handle_line(line) {
+ if (line === fence) {
+ this.done();
+ } else {
+ consume_line(lines, line);
+ }
+ },
+ done() {
+ const text = wrap_quote(lines.join("\n"));
+ output_lines.push("", text, "");
+ handler_stack.pop();
+ },
+ };
+ }
+
+ if (lang === "math") {
return {
handle_line(line) {
if (line === fence) {
this.done();
} else {
- lines.push(line.trimEnd());
+ lines.push(line);
}
},
done() {
- const text = wrap_code(lines.join("\n"), lang);
- // insert safe HTML that is passed through the parsing
+ const text = wrap_tex(lines.join("\n"));
const placeholder = stash_func(text, true);
output_lines.push("", placeholder, "");
handler_stack.pop();
},
};
- })();
+ }
+
+ if (lang === "spoiler") {
+ return {
+ handle_line(line) {
+ if (line === fence) {
+ this.done();
+ } else {
+ lines.push(line);
+ }
+ },
+
+ done() {
+ const text = wrap_spoiler(header, lines.join("\n"), stash_func);
+ output_lines.push("", text, "");
+ handler_stack.pop();
+ },
+ };
+ }
+
+ return {
+ handle_line(line) {
+ if (line === fence) {
+ this.done();
+ } else {
+ lines.push(line.trimEnd());
+ }
+ },
+
+ done() {
+ const text = wrap_code(lines.join("\n"), lang);
+ // insert safe HTML that is passed through the parsing
+ const placeholder = stash_func(text, true);
+ output_lines.push("", placeholder, "");
+ handler_stack.pop();
+ },
+ };
}
function default_hander() {