From 2a49ce1b6ca9952ea79ea8777a105c3993c0a4a6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Feb 2021 16:28:13 -0800 Subject: [PATCH] js: Convert static/js/search_pill_widget.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/narrow_activate.js | 2 +- frontend_tests/node_tests/search.js | 2 +- frontend_tests/node_tests/ui_init.js | 1 - static/js/bundles/app.js | 1 - static/js/global.d.ts | 1 - static/js/narrow.js | 1 + static/js/search.js | 1 + static/js/search_pill_widget.js | 20 +++++++++----------- static/js/ui_init.js | 1 + 10 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 32e0b52c58..91e1c8053b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -147,7 +147,6 @@ "page_params": false, "pointer": false, "realm_night_logo": false, - "search_pill_widget": false, "settings_profile_fields": false, "stream_list": false, "StripeCheckout": false, diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js index a82e2bd9c2..09886b6570 100644 --- a/frontend_tests/node_tests/narrow_activate.js +++ b/frontend_tests/node_tests/narrow_activate.js @@ -45,7 +45,7 @@ rewiremock("../../static/js/typing_events").with(typing_events); const ui_util = {__esModule: true}; rewiremock("../../static/js/ui_util").with(ui_util); const unread_ops = set_global("unread_ops", {}); -set_global("search_pill_widget", { +rewiremock("../../static/js/search_pill_widget").with({ widget: { clear() { return true; diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index 0a4f508cb0..6207fc831f 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -26,7 +26,7 @@ rewiremock("../../static/js/ui_util").with({ place_caret_at_end: noop, }); const narrow = set_global("narrow", {}); -set_global("search_pill_widget", { +rewiremock("../../static/js/search_pill_widget").with({ widget: { getByID: () => true, }, diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index e713815e4a..c5595bab12 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -113,7 +113,6 @@ rewiremock.enable(); const util = zrequire("util"); -zrequire("search_pill_widget"); zrequire("unread"); const upload = zrequire("upload"); const compose = zrequire("compose"); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index a8007a7133..c765146648 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -38,7 +38,6 @@ import "../dropdown_list_widget"; import "../settings_profile_fields"; import "../settings"; import "../ui_init"; -import "../search_pill_widget"; import "../desktop_integration"; // Import styles diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 179ce508ad..62458bee5d 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -19,7 +19,6 @@ declare let message_list: any; declare let narrow: any; declare let page_params: any; declare let pointer: any; -declare let search_pill_widget: any; declare let settings_profile_fields: any; declare let stream_list: any; declare let subs: any; diff --git a/static/js/narrow.js b/static/js/narrow.js index 48c95cefc9..db13da509a 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -20,6 +20,7 @@ const recent_topics = require("./recent_topics"); const resize = require("./resize"); const search = require("./search"); const search_pill = require("./search_pill"); +const search_pill_widget = require("./search_pill_widget"); const stream_data = require("./stream_data"); const stream_topic_history = require("./stream_topic_history"); const top_left_corner = require("./top_left_corner"); diff --git a/static/js/search.js b/static/js/search.js index fb685db33b..9031478c8c 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -2,6 +2,7 @@ import {Filter} from "./filter"; import * as message_view_header from "./message_view_header"; import * as narrow_state from "./narrow_state"; import * as search_pill from "./search_pill"; +import * as search_pill_widget from "./search_pill_widget"; import * as search_suggestion from "./search_suggestion"; import * as ui_util from "./ui_util"; diff --git a/static/js/search_pill_widget.js b/static/js/search_pill_widget.js index 3865f28ed6..442d0dfa11 100644 --- a/static/js/search_pill_widget.js +++ b/static/js/search_pill_widget.js @@ -1,22 +1,20 @@ -"use strict"; +import * as hashchange from "./hashchange"; +import * as search_pill from "./search_pill"; -const hashchange = require("./hashchange"); -const search_pill = require("./search_pill"); +export let widget; -exports.initialize = function () { +export function initialize() { if (!page_params.search_pills_enabled) { return; } const container = $("#search_arrows"); - exports.widget = search_pill.create_pills(container); + widget = search_pill.create_pills(container); - exports.widget.onPillRemove(() => { - if (exports.widget.items().length === 0) { + widget.onPillRemove(() => { + if (widget.items().length === 0) { hashchange.go_to_location(""); } }); - exports.widget.createPillonPaste(() => false); -}; - -window.search_pill_widget = exports; + widget.createPillonPaste(() => false); +} diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 556a3b17a1..ae495ad1f0 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -45,6 +45,7 @@ import * as resize from "./resize"; import * as rows from "./rows"; import * as scroll_bar from "./scroll_bar"; import * as search from "./search"; +import * as search_pill_widget from "./search_pill_widget"; import * as sent_messages from "./sent_messages"; import * as server_events from "./server_events"; import * as settings_panel_menu from "./settings_panel_menu";