mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
js: Convert static/js/common.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
4df3fef88f
commit
a3e6ebb04c
@@ -139,7 +139,6 @@
|
|||||||
"channel": false,
|
"channel": false,
|
||||||
"click_handlers": false,
|
"click_handlers": false,
|
||||||
"color_data": false,
|
"color_data": false,
|
||||||
"common": false,
|
|
||||||
"compose": false,
|
"compose": false,
|
||||||
"compose_actions": false,
|
"compose_actions": false,
|
||||||
"compose_fade": false,
|
"compose_fade": false,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ run_test("copy_data_attribute_value", (override) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test("adjust_mac_shortcuts non-mac", () => {
|
run_test("adjust_mac_shortcuts non-mac", () => {
|
||||||
common.has_mac_keyboard = () => false;
|
common.__Rewire__("has_mac_keyboard", () => false);
|
||||||
|
|
||||||
// The adjust_mac_shortcuts has a really simple guard
|
// The adjust_mac_shortcuts has a really simple guard
|
||||||
// at the top, and we just test the early-return behavior
|
// at the top, and we just test the early-return behavior
|
||||||
@@ -95,7 +95,7 @@ run_test("adjust_mac_shortcuts mac", () => {
|
|||||||
["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],
|
["Ctrl + Backspace + End", "⌘ + Delete + Fn + →"],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
common.has_mac_keyboard = () => true;
|
common.__Rewire__("has_mac_keyboard", () => true);
|
||||||
|
|
||||||
const test_items = [];
|
const test_items = [];
|
||||||
let key_no = 1;
|
let key_no = 1;
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ const compose_ui = zrequire("compose_ui");
|
|||||||
const peer_data = zrequire("peer_data");
|
const peer_data = zrequire("peer_data");
|
||||||
const util = zrequire("util");
|
const util = zrequire("util");
|
||||||
const rtl = zrequire("rtl");
|
const rtl = zrequire("rtl");
|
||||||
zrequire("common");
|
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const compose_state = zrequire("compose_state");
|
const compose_state = zrequire("compose_state");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
|
const rewiremock = require("rewiremock/node");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const $ = require("../zjsunit/zjquery");
|
const $ = require("../zjsunit/zjquery");
|
||||||
@@ -43,7 +45,7 @@ set_global("unread_ops", {
|
|||||||
notify_server_message_read: noop,
|
notify_server_message_read: noop,
|
||||||
});
|
});
|
||||||
|
|
||||||
set_global("common", {
|
rewiremock("../../static/js/common").with({
|
||||||
status_classes: "status_classes",
|
status_classes: "status_classes",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,6 +57,8 @@ set_global("current_msg_list", {
|
|||||||
|
|
||||||
const channel = set_global("channel", {});
|
const channel = set_global("channel", {});
|
||||||
|
|
||||||
|
rewiremock.enable();
|
||||||
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const compose_ui = zrequire("compose_ui");
|
const compose_ui = zrequire("compose_ui");
|
||||||
const compose = zrequire("compose");
|
const compose = zrequire("compose");
|
||||||
@@ -485,3 +489,4 @@ run_test("on_narrow", (override) => {
|
|||||||
});
|
});
|
||||||
assert(cancel_called);
|
assert(cancel_called);
|
||||||
});
|
});
|
||||||
|
rewiremock.disable();
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
|
|||||||
const emoji = zrequire("emoji", "shared/js/emoji");
|
const emoji = zrequire("emoji", "shared/js/emoji");
|
||||||
const activity = zrequire("activity");
|
const activity = zrequire("activity");
|
||||||
const hotkey = zrequire("hotkey");
|
const hotkey = zrequire("hotkey");
|
||||||
zrequire("common");
|
|
||||||
|
|
||||||
emoji.initialize({
|
emoji.initialize({
|
||||||
realm_emoji: {},
|
realm_emoji: {},
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ const stream_data = zrequire("stream_data");
|
|||||||
const stream_topic_history = zrequire("stream_topic_history");
|
const stream_topic_history = zrequire("stream_topic_history");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
zrequire("unread");
|
zrequire("unread");
|
||||||
zrequire("common");
|
|
||||||
const search = zrequire("search_suggestion");
|
const search = zrequire("search_suggestion");
|
||||||
|
|
||||||
search.max_num_of_search_results = 15;
|
search.max_num_of_search_results = 15;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ const stream_data = zrequire("stream_data");
|
|||||||
const stream_topic_history = zrequire("stream_topic_history");
|
const stream_topic_history = zrequire("stream_topic_history");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
zrequire("unread");
|
zrequire("unread");
|
||||||
zrequire("common");
|
|
||||||
const search = zrequire("search_suggestion");
|
const search = zrequire("search_suggestion");
|
||||||
|
|
||||||
search.max_num_of_search_results = 15;
|
search.max_num_of_search_results = 15;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
$("a.envelope-link").on("click", function () {
|
$("a.envelope-link").on("click", function () {
|
||||||
common.copy_data_attribute_value($(this), "admin-emails");
|
common.copy_data_attribute_value($(this), "admin-emails");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
export {};
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
$("body").on("click", ".scrub-realm-button", function (e) {
|
$("body").on("click", ".scrub-realm-button", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -18,4 +20,3 @@ $(() => {
|
|||||||
common.copy_data_attribute_value($(this), "copytext");
|
common.copy_data_attribute_value($(this), "copytext");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
export {};
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import "../page_params";
|
|||||||
import "../csrf";
|
import "../csrf";
|
||||||
import "../blueslip";
|
import "../blueslip";
|
||||||
import "../../third/bootstrap/js/bootstrap";
|
import "../../third/bootstrap/js/bootstrap";
|
||||||
import "../common";
|
|
||||||
import "../../third/bootstrap/css/bootstrap.css";
|
import "../../third/bootstrap/css/bootstrap.css";
|
||||||
import "../../third/bootstrap/css/bootstrap-btn.css";
|
import "../../third/bootstrap/css/bootstrap-btn.css";
|
||||||
import "simplebar/dist/simplebar.css";
|
import "simplebar/dist/simplebar.css";
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
// This reloads the module in development rather than refreshing the page
|
// This reloads the module in development rather than refreshing the page
|
||||||
if (module.hot) {
|
if (module.hot) {
|
||||||
module.hot.accept();
|
module.hot.accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.status_classes = "alert-error alert-success alert-info alert-warning";
|
export const status_classes = "alert-error alert-success alert-info alert-warning";
|
||||||
|
|
||||||
exports.autofocus = function (selector) {
|
export function autofocus(selector) {
|
||||||
$(() => {
|
$(() => {
|
||||||
$(selector).trigger("focus");
|
$(selector).trigger("focus");
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
// Return a boolean indicating whether the password is acceptable.
|
// Return a boolean indicating whether the password is acceptable.
|
||||||
// Also updates a Bootstrap progress bar control (a jQuery object)
|
// Also updates a Bootstrap progress bar control (a jQuery object)
|
||||||
@@ -21,7 +19,7 @@ exports.autofocus = function (selector) {
|
|||||||
//
|
//
|
||||||
// This is in common.js because we want to use it from the signup page
|
// This is in common.js because we want to use it from the signup page
|
||||||
// and also from the in-app password change interface.
|
// and also from the in-app password change interface.
|
||||||
exports.password_quality = function (password, bar, password_field) {
|
export function password_quality(password, bar, password_field) {
|
||||||
// We load zxcvbn.js asynchronously, so the variable might not be set.
|
// We load zxcvbn.js asynchronously, so the variable might not be set.
|
||||||
if (typeof zxcvbn === "undefined") {
|
if (typeof zxcvbn === "undefined") {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -51,9 +49,9 @@ exports.password_quality = function (password, bar, password_field) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return acceptable;
|
return acceptable;
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.password_warning = function (password, password_field) {
|
export function password_warning(password, password_field) {
|
||||||
if (typeof zxcvbn === "undefined") {
|
if (typeof zxcvbn === "undefined") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -66,9 +64,9 @@ exports.password_warning = function (password, password_field) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return zxcvbn(password).feedback.warning || i18n.t("Password is too weak");
|
return zxcvbn(password).feedback.warning || i18n.t("Password is too weak");
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.phrase_match = function (query, phrase) {
|
export function phrase_match(query, phrase) {
|
||||||
// match "tes" to "test" and "stream test" but not "hostess"
|
// match "tes" to "test" and "stream test" but not "hostess"
|
||||||
let i;
|
let i;
|
||||||
query = query.toLowerCase();
|
query = query.toLowerCase();
|
||||||
@@ -85,9 +83,9 @@ exports.phrase_match = function (query, phrase) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.copy_data_attribute_value = function (elem, key) {
|
export function copy_data_attribute_value(elem, key) {
|
||||||
// function to copy the value of data-key
|
// function to copy the value of data-key
|
||||||
// attribute of the element to clipboard
|
// attribute of the element to clipboard
|
||||||
const temp = $(document.createElement("input"));
|
const temp = $(document.createElement("input"));
|
||||||
@@ -97,14 +95,14 @@ exports.copy_data_attribute_value = function (elem, key) {
|
|||||||
temp.remove();
|
temp.remove();
|
||||||
elem.fadeOut(250);
|
elem.fadeOut(250);
|
||||||
elem.fadeIn(1000);
|
elem.fadeIn(1000);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.has_mac_keyboard = function () {
|
export function has_mac_keyboard() {
|
||||||
return /mac/i.test(navigator.platform);
|
return /mac/i.test(navigator.platform);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {
|
export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
|
||||||
if (!exports.has_mac_keyboard()) {
|
if (!has_mac_keyboard()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +132,4 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {
|
|||||||
|
|
||||||
$(this).text(key_text);
|
$(this).text(key_text);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
window.common = exports;
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const render_compose_invite_users = require("../templates/compose_invite_users.h
|
|||||||
const render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs");
|
const render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs");
|
||||||
const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");
|
const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const echo = require("./echo");
|
const echo = require("./echo");
|
||||||
const peer_data = require("./peer_data");
|
const peer_data = require("./peer_data");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const autosize = require("autosize");
|
|||||||
|
|
||||||
const fenced_code = require("../shared/js/fenced_code");
|
const fenced_code = require("../shared/js/fenced_code");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
|
|
||||||
exports.blur_compose_inputs = function () {
|
exports.blur_compose_inputs = function () {
|
||||||
|
|||||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -17,7 +17,6 @@ declare let buddy_list: any;
|
|||||||
declare let channel: any;
|
declare let channel: any;
|
||||||
declare let click_handlers: any;
|
declare let click_handlers: any;
|
||||||
declare let color_data: any;
|
declare let color_data: any;
|
||||||
declare let common: any;
|
|
||||||
declare let compose: any;
|
declare let compose: any;
|
||||||
declare let compose_actions: any;
|
declare let compose_actions: any;
|
||||||
declare let composebox_typeahead: any;
|
declare let composebox_typeahead: any;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const emoji = require("../shared/js/emoji");
|
const emoji = require("../shared/js/emoji");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const copy_and_paste = require("./copy_and_paste");
|
const copy_and_paste = require("./copy_and_paste");
|
||||||
const feedback_widget = require("./feedback_widget");
|
const feedback_widget = require("./feedback_widget");
|
||||||
const topic_zoom = require("./topic_zoom");
|
const topic_zoom = require("./topic_zoom");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const components = require("./components");
|
const components = require("./components");
|
||||||
|
|
||||||
// Make it explicit that our toggler is undefined until
|
// Make it explicit that our toggler is undefined until
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import render_invitation_failed_error from "../templates/invitation_failed_error
|
|||||||
import render_invite_subscription from "../templates/invite_subscription.hbs";
|
import render_invite_subscription from "../templates/invite_subscription.hbs";
|
||||||
import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";
|
import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";
|
||||||
|
|
||||||
|
import * as common from "./common";
|
||||||
|
|
||||||
function reset_error_messages() {
|
function reset_error_messages() {
|
||||||
$("#invite_status").hide().text("").removeClass(common.status_classes);
|
$("#invite_status").hide().text("").removeClass(common.status_classes);
|
||||||
$("#multiuse_invite_status").hide().text("").removeClass(common.status_classes);
|
$("#multiuse_invite_status").hide().text("").removeClass(common.status_classes);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import SimpleBar from "simplebar/dist/simplebar";
|
import SimpleBar from "simplebar/dist/simplebar";
|
||||||
|
|
||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
import * as google_analytics from "./google-analytics";
|
import * as google_analytics from "./google-analytics";
|
||||||
import {activate_correct_tab} from "./tabbed-instructions";
|
import {activate_correct_tab} from "./tabbed-instructions";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
|
||||||
import * as blueslip from "../blueslip";
|
import * as blueslip from "../blueslip";
|
||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
import * as google_analytics from "./google-analytics";
|
import * as google_analytics from "./google-analytics";
|
||||||
import {path_parts} from "./landing-page";
|
import {path_parts} from "./landing-page";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
// NB: this file is included on multiple pages. In each context,
|
// NB: this file is included on multiple pages. In each context,
|
||||||
// some of the jQuery selectors below will return empty lists.
|
// some of the jQuery selectors below will return empty lists.
|
||||||
@@ -210,4 +212,3 @@ $(() => {
|
|||||||
this.parentNode.submit();
|
this.parentNode.submit();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
export {};
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as common from "../common";
|
||||||
|
|
||||||
export function detect_user_os() {
|
export function detect_user_os() {
|
||||||
if (/android/i.test(navigator.userAgent)) {
|
if (/android/i.test(navigator.userAgent)) {
|
||||||
return "android";
|
return "android";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const Handlebars = require("handlebars/runtime");
|
const Handlebars = require("handlebars/runtime");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const huddle_data = require("./huddle_data");
|
const huddle_data = require("./huddle_data");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const settings_data = require("./settings_data");
|
const settings_data = require("./settings_data");
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const render_settings_api_key_modal = require("../templates/settings/api_key_mod
|
|||||||
const render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");
|
const render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");
|
||||||
const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");
|
const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const pill_typeahead = require("./pill_typeahead");
|
const pill_typeahead = require("./pill_typeahead");
|
||||||
const settings_ui = require("./settings_ui");
|
const settings_ui = require("./settings_ui");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const SimpleBar = require("simplebar/dist/simplebar");
|
const SimpleBar = require("simplebar/dist/simplebar");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
const {localstorage} = require("./localstorage");
|
const {localstorage} = require("./localstorage");
|
||||||
|
|
||||||
// What, if anything, obscures the home tab?
|
// What, if anything, obscures the home tab?
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
|
|
||||||
|
const common = require("./common");
|
||||||
/* Arguments used in the report_* functions are,
|
/* Arguments used in the report_* functions are,
|
||||||
response- response that we want to display
|
response- response that we want to display
|
||||||
status_box- element being used to display the response
|
status_box- element being used to display the response
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import marked from "../third/marked/lib/marked";
|
import marked from "../third/marked/lib/marked";
|
||||||
|
|
||||||
|
import * as common from "./common";
|
||||||
import * as feedback_widget from "./feedback_widget";
|
import * as feedback_widget from "./feedback_widget";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user