mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
js: Convert static/js/search.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
9d9c716dd2
commit
b9137e3de8
@@ -176,7 +176,6 @@
|
||||
"realm_night_logo": false,
|
||||
"recent_topics": false,
|
||||
"reminder": false,
|
||||
"search": false,
|
||||
"search_pill_widget": false,
|
||||
"server_events": false,
|
||||
"settings": false,
|
||||
|
||||
@@ -15,7 +15,7 @@ set_global("location", {
|
||||
});
|
||||
set_global("to_$", () => window_stub);
|
||||
|
||||
set_global("search", {
|
||||
rewiremock("../../static/js/search").with({
|
||||
update_button_visibility: () => {},
|
||||
});
|
||||
set_global("document", "document-stub");
|
||||
|
||||
@@ -92,7 +92,8 @@ rewiremock("../../static/js/muting_ui").with(muting_ui);
|
||||
const narrow = set_global("narrow", {});
|
||||
const navigate = set_global("navigate", {});
|
||||
const reactions = set_global("reactions", {});
|
||||
const search = set_global("search", {});
|
||||
const search = {__esModule: true};
|
||||
rewiremock("../../static/js/search").with(search);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const subs = set_global("subs", {});
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ rewiremock("../../static/js/message_scroll").with(message_scroll);
|
||||
set_global("message_util", {});
|
||||
const notifications = set_global("notifications", {});
|
||||
set_global("page_params", {});
|
||||
const search = set_global("search", {});
|
||||
const search = {__esModule: true};
|
||||
rewiremock("../../static/js/search").with(search);
|
||||
const stream_list = set_global("stream_list", {});
|
||||
const message_view_header = set_global("message_view_header", {});
|
||||
const top_left_corner = {__esModule: true};
|
||||
|
||||
@@ -195,7 +195,7 @@ run_test("initialize", () => {
|
||||
assert(!is_blurred);
|
||||
assert(is_append_search_string_called);
|
||||
|
||||
search.is_using_input_method = true;
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
_setup("stream:Verona");
|
||||
|
||||
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
||||
@@ -222,7 +222,7 @@ run_test("initialize", () => {
|
||||
searchbox.trigger("focusout");
|
||||
assert.deepEqual(searchbox.css(), {"box-shadow": "unset"});
|
||||
|
||||
search.is_using_input_method = false;
|
||||
search.__Rewire__("is_using_input_method", false);
|
||||
searchbox_form.trigger("compositionend");
|
||||
assert(search.is_using_input_method);
|
||||
|
||||
@@ -303,7 +303,7 @@ run_test("initialize", () => {
|
||||
assert(is_blurred);
|
||||
|
||||
_setup("ver");
|
||||
search.is_using_input_method = true;
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
searchbox_form.trigger(ev);
|
||||
// No change on Enter keyup event when using input tool
|
||||
assert(!is_blurred);
|
||||
|
||||
@@ -161,7 +161,7 @@ run_test("initialize", () => {
|
||||
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
||||
assert(is_blurred);
|
||||
|
||||
search.is_using_input_method = true;
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
_setup("stream:Verona");
|
||||
assert.equal(opts.updater("stream:Verona"), "stream:Verona");
|
||||
assert(!is_blurred);
|
||||
@@ -181,7 +181,7 @@ run_test("initialize", () => {
|
||||
search_query_box.trigger("blur");
|
||||
assert.equal(search_query_box.val(), "test string");
|
||||
|
||||
search.is_using_input_method = false;
|
||||
search.__Rewire__("is_using_input_method", false);
|
||||
searchbox_form.trigger("compositionend");
|
||||
assert(search.is_using_input_method);
|
||||
|
||||
@@ -261,7 +261,7 @@ run_test("initialize", () => {
|
||||
assert(is_blurred);
|
||||
|
||||
_setup("ver");
|
||||
search.is_using_input_method = true;
|
||||
search.__Rewire__("is_using_input_method", true);
|
||||
searchbox_form.trigger(ev);
|
||||
// No change on Enter keyup event when using input tool
|
||||
assert(!is_blurred);
|
||||
|
||||
@@ -119,7 +119,6 @@ const upload = zrequire("upload");
|
||||
const compose = zrequire("compose");
|
||||
zrequire("composebox_typeahead");
|
||||
zrequire("narrow");
|
||||
zrequire("search");
|
||||
zrequire("notifications");
|
||||
zrequire("stream_list");
|
||||
zrequire("starred_messages");
|
||||
|
||||
@@ -27,7 +27,6 @@ import "../reload";
|
||||
import "../compose_actions";
|
||||
import "../subs";
|
||||
import "../ui";
|
||||
import "../search";
|
||||
import "../composebox_typeahead";
|
||||
import "../navigate";
|
||||
import "../list_util";
|
||||
|
||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -49,7 +49,6 @@ declare let realm_icon: any;
|
||||
declare let realm_logo: any;
|
||||
declare let recent_topics: any;
|
||||
declare let reminder: any;
|
||||
declare let search: any;
|
||||
declare let search_pill_widget: any;
|
||||
declare let server_events: any;
|
||||
declare let settings: any;
|
||||
|
||||
@@ -6,6 +6,7 @@ const info_overlay = require("./info_overlay");
|
||||
const invite = require("./invite");
|
||||
const message_viewport = require("./message_viewport");
|
||||
const overlays = require("./overlays");
|
||||
const search = require("./search");
|
||||
const settings_panel_menu = require("./settings_panel_menu");
|
||||
const top_left_corner = require("./top_left_corner");
|
||||
const ui_util = require("./ui_util");
|
||||
|
||||
@@ -15,6 +15,7 @@ const message_edit = require("./message_edit");
|
||||
const muting_ui = require("./muting_ui");
|
||||
const overlays = require("./overlays");
|
||||
const popovers = require("./popovers");
|
||||
const search = require("./search");
|
||||
const stream_popover = require("./stream_popover");
|
||||
const topic_zoom = require("./topic_zoom");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ const render_message_view_header = require("../templates/message_view_header.hbs
|
||||
const narrow_state = require("./narrow_state");
|
||||
const peer_data = require("./peer_data");
|
||||
const rendered_markdown = require("./rendered_markdown");
|
||||
const search = require("./search");
|
||||
|
||||
function get_formatted_sub_count(sub_count) {
|
||||
if (sub_count >= 1000) {
|
||||
|
||||
@@ -12,6 +12,7 @@ const message_scroll = require("./message_scroll");
|
||||
const narrow_state = require("./narrow_state");
|
||||
const people = require("./people");
|
||||
const resize = require("./resize");
|
||||
const search = require("./search");
|
||||
const search_pill = require("./search_pill");
|
||||
const stream_data = require("./stream_data");
|
||||
const stream_topic_history = require("./stream_topic_history");
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
const {Filter} = require("./filter");
|
||||
const narrow_state = require("./narrow_state");
|
||||
const search_pill = require("./search_pill");
|
||||
const search_suggestion = require("./search_suggestion");
|
||||
const ui_util = require("./ui_util");
|
||||
import {Filter} from "./filter";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as search_pill from "./search_pill";
|
||||
import * as search_suggestion from "./search_suggestion";
|
||||
import * as ui_util from "./ui_util";
|
||||
|
||||
// Exported for unit testing
|
||||
exports.is_using_input_method = false;
|
||||
export let is_using_input_method = false;
|
||||
|
||||
exports.narrow_or_search_for_term = function (search_string) {
|
||||
export function narrow_or_search_for_term(search_string) {
|
||||
const search_query_box = $("#search_query");
|
||||
if (exports.is_using_input_method) {
|
||||
if (is_using_input_method) {
|
||||
// Neither narrow nor search when using input tools as
|
||||
// `updater` is also triggered when 'enter' is triggered
|
||||
// while using input tool
|
||||
@@ -43,7 +41,7 @@ exports.narrow_or_search_for_term = function (search_string) {
|
||||
search_query_box.trigger("blur");
|
||||
}
|
||||
return search_query_box.val();
|
||||
};
|
||||
}
|
||||
|
||||
function update_buttons_with_focus(focused) {
|
||||
const search_query_box = $("#search_query");
|
||||
@@ -55,11 +53,11 @@ function update_buttons_with_focus(focused) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.update_button_visibility = function () {
|
||||
export function update_button_visibility() {
|
||||
update_buttons_with_focus($("#search_query").is(":focus"));
|
||||
};
|
||||
}
|
||||
|
||||
exports.initialize = function () {
|
||||
export function initialize() {
|
||||
const search_query_box = $("#search_query");
|
||||
const searchbox_form = $("#searchbox_form");
|
||||
const searchbox = $("#searchbox");
|
||||
@@ -100,7 +98,7 @@ exports.initialize = function () {
|
||||
search_pill.append_search_string(search_string, search_pill_widget.widget);
|
||||
return search_query_box.val();
|
||||
}
|
||||
return exports.narrow_or_search_for_term(search_string);
|
||||
return narrow_or_search_for_term(search_string);
|
||||
},
|
||||
sorter(items) {
|
||||
return items;
|
||||
@@ -124,12 +122,12 @@ exports.initialize = function () {
|
||||
// we suppress searching triggered by this Enter key by checking
|
||||
// `is_using_input_method` before searching.
|
||||
// More details in the commit message that added this line.
|
||||
exports.is_using_input_method = true;
|
||||
is_using_input_method = true;
|
||||
});
|
||||
|
||||
searchbox_form
|
||||
.on("keydown", (e) => {
|
||||
exports.update_button_visibility();
|
||||
update_button_visibility();
|
||||
const code = e.which;
|
||||
if (code === 13 && search_query_box.is(":focus")) {
|
||||
// Don't submit the form so that the typeahead can instead
|
||||
@@ -139,8 +137,8 @@ exports.initialize = function () {
|
||||
}
|
||||
})
|
||||
.on("keyup", (e) => {
|
||||
if (exports.is_using_input_method) {
|
||||
exports.is_using_input_method = false;
|
||||
if (is_using_input_method) {
|
||||
is_using_input_method = false;
|
||||
return;
|
||||
}
|
||||
const code = e.which;
|
||||
@@ -153,7 +151,7 @@ exports.initialize = function () {
|
||||
// indicate that they've done what they need to do)
|
||||
|
||||
// Pill is already added during keydown event of input pills.
|
||||
exports.narrow_or_search_for_term(search_query_box.val());
|
||||
narrow_or_search_for_term(search_query_box.val());
|
||||
search_query_box.trigger("blur");
|
||||
update_buttons_with_focus(false);
|
||||
}
|
||||
@@ -163,7 +161,7 @@ exports.initialize = function () {
|
||||
// but the code was moved here from elsewhere, and it would be
|
||||
// more work to re-order everything and make them private.
|
||||
|
||||
search_query_box.on("focus", exports.focus_search);
|
||||
search_query_box.on("focus", focus_search);
|
||||
search_query_box.on("blur", (e) => {
|
||||
// The search query box is a visual cue as to
|
||||
// whether search or narrowing is active. If
|
||||
@@ -193,7 +191,7 @@ exports.initialize = function () {
|
||||
}
|
||||
}
|
||||
setTimeout(() => {
|
||||
exports.update_button_visibility();
|
||||
update_button_visibility();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
@@ -206,14 +204,14 @@ exports.initialize = function () {
|
||||
searchbox.css({"box-shadow": "unset"});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.focus_search = function () {
|
||||
export function focus_search() {
|
||||
// The search bar is not focused yet, but will be.
|
||||
update_buttons_with_focus(true);
|
||||
};
|
||||
}
|
||||
|
||||
exports.initiate_search = function () {
|
||||
export function initiate_search() {
|
||||
message_view_header.open_search_bar_and_close_narrow_description();
|
||||
$("#searchbox").css({"box-shadow": "inset 0px 0px 0px 2px hsl(204, 20%, 74%)"});
|
||||
$("#search_query").typeahead("lookup").trigger("select");
|
||||
@@ -221,12 +219,10 @@ exports.initiate_search = function () {
|
||||
$("#search_query").trigger("focus");
|
||||
ui_util.place_caret_at_end($("#search_query")[0]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.clear_search_form = function () {
|
||||
export function clear_search_form() {
|
||||
$("#search_query").val("");
|
||||
$("#search_query").trigger("blur");
|
||||
$(".search_button").prop("disabled", true);
|
||||
};
|
||||
|
||||
window.search = exports;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ const reload = require("./reload");
|
||||
const resize = require("./resize");
|
||||
const rows = require("./rows");
|
||||
const scroll_bar = require("./scroll_bar");
|
||||
const search = require("./search");
|
||||
const sent_messages = require("./sent_messages");
|
||||
const settings_panel_menu = require("./settings_panel_menu");
|
||||
const settings_toggle = require("./settings_toggle");
|
||||
|
||||
Reference in New Issue
Block a user