mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +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,
 | 
			
		||||
                "click_handlers": false,
 | 
			
		||||
                "color_data": false,
 | 
			
		||||
                "common": false,
 | 
			
		||||
                "compose": false,
 | 
			
		||||
                "compose_actions": false,
 | 
			
		||||
                "compose_fade": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ run_test("copy_data_attribute_value", (override) => {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
    // 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 + →"],
 | 
			
		||||
    ]);
 | 
			
		||||
 | 
			
		||||
    common.has_mac_keyboard = () => true;
 | 
			
		||||
    common.__Rewire__("has_mac_keyboard", () => true);
 | 
			
		||||
 | 
			
		||||
    const test_items = [];
 | 
			
		||||
    let key_no = 1;
 | 
			
		||||
 
 | 
			
		||||
@@ -82,7 +82,6 @@ const compose_ui = zrequire("compose_ui");
 | 
			
		||||
const peer_data = zrequire("peer_data");
 | 
			
		||||
const util = zrequire("util");
 | 
			
		||||
const rtl = zrequire("rtl");
 | 
			
		||||
zrequire("common");
 | 
			
		||||
const stream_data = zrequire("stream_data");
 | 
			
		||||
const compose_state = zrequire("compose_state");
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@
 | 
			
		||||
 | 
			
		||||
const {strict: assert} = require("assert");
 | 
			
		||||
 | 
			
		||||
const rewiremock = require("rewiremock/node");
 | 
			
		||||
 | 
			
		||||
const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
			
		||||
const {run_test} = require("../zjsunit/test");
 | 
			
		||||
const $ = require("../zjsunit/zjquery");
 | 
			
		||||
@@ -43,7 +45,7 @@ set_global("unread_ops", {
 | 
			
		||||
    notify_server_message_read: noop,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
set_global("common", {
 | 
			
		||||
rewiremock("../../static/js/common").with({
 | 
			
		||||
    status_classes: "status_classes",
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -55,6 +57,8 @@ set_global("current_msg_list", {
 | 
			
		||||
 | 
			
		||||
const channel = set_global("channel", {});
 | 
			
		||||
 | 
			
		||||
rewiremock.enable();
 | 
			
		||||
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
const compose_ui = zrequire("compose_ui");
 | 
			
		||||
const compose = zrequire("compose");
 | 
			
		||||
@@ -485,3 +489,4 @@ run_test("on_narrow", (override) => {
 | 
			
		||||
    });
 | 
			
		||||
    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 activity = zrequire("activity");
 | 
			
		||||
const hotkey = zrequire("hotkey");
 | 
			
		||||
zrequire("common");
 | 
			
		||||
 | 
			
		||||
emoji.initialize({
 | 
			
		||||
    realm_emoji: {},
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,6 @@ const stream_data = zrequire("stream_data");
 | 
			
		||||
const stream_topic_history = zrequire("stream_topic_history");
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
zrequire("unread");
 | 
			
		||||
zrequire("common");
 | 
			
		||||
const search = zrequire("search_suggestion");
 | 
			
		||||
 | 
			
		||||
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 people = zrequire("people");
 | 
			
		||||
zrequire("unread");
 | 
			
		||||
zrequire("common");
 | 
			
		||||
const search = zrequire("search_suggestion");
 | 
			
		||||
 | 
			
		||||
search.max_num_of_search_results = 15;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
import * as common from "../common";
 | 
			
		||||
 | 
			
		||||
$(() => {
 | 
			
		||||
    $("a.envelope-link").on("click", function () {
 | 
			
		||||
        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) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
@@ -18,4 +20,3 @@ $(() => {
 | 
			
		||||
        common.copy_data_attribute_value($(this), "copytext");
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
export {};
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@ import "../page_params";
 | 
			
		||||
import "../csrf";
 | 
			
		||||
import "../blueslip";
 | 
			
		||||
import "../../third/bootstrap/js/bootstrap";
 | 
			
		||||
import "../common";
 | 
			
		||||
import "../../third/bootstrap/css/bootstrap.css";
 | 
			
		||||
import "../../third/bootstrap/css/bootstrap-btn.css";
 | 
			
		||||
import "simplebar/dist/simplebar.css";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,15 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
// This reloads the module in development rather than refreshing the page
 | 
			
		||||
if (module.hot) {
 | 
			
		||||
    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");
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Return a boolean indicating whether the password is acceptable.
 | 
			
		||||
// 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
 | 
			
		||||
// 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.
 | 
			
		||||
    if (typeof zxcvbn === "undefined") {
 | 
			
		||||
        return undefined;
 | 
			
		||||
@@ -51,9 +49,9 @@ exports.password_quality = function (password, bar, password_field) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return acceptable;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.password_warning = function (password, password_field) {
 | 
			
		||||
export function password_warning(password, password_field) {
 | 
			
		||||
    if (typeof zxcvbn === "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");
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.phrase_match = function (query, phrase) {
 | 
			
		||||
export function phrase_match(query, phrase) {
 | 
			
		||||
    // match "tes" to "test" and "stream test" but not "hostess"
 | 
			
		||||
    let i;
 | 
			
		||||
    query = query.toLowerCase();
 | 
			
		||||
@@ -85,9 +83,9 @@ exports.phrase_match = function (query, phrase) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    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
 | 
			
		||||
    // attribute of the element to clipboard
 | 
			
		||||
    const temp = $(document.createElement("input"));
 | 
			
		||||
@@ -97,14 +95,14 @@ exports.copy_data_attribute_value = function (elem, key) {
 | 
			
		||||
    temp.remove();
 | 
			
		||||
    elem.fadeOut(250);
 | 
			
		||||
    elem.fadeIn(1000);
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.has_mac_keyboard = function () {
 | 
			
		||||
export function has_mac_keyboard() {
 | 
			
		||||
    return /mac/i.test(navigator.platform);
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {
 | 
			
		||||
    if (!exports.has_mac_keyboard()) {
 | 
			
		||||
export function adjust_mac_shortcuts(key_elem_class, require_cmd_style) {
 | 
			
		||||
    if (!has_mac_keyboard()) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -134,6 +132,4 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) {
 | 
			
		||||
 | 
			
		||||
        $(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_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const echo = require("./echo");
 | 
			
		||||
const peer_data = require("./peer_data");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ const autosize = require("autosize");
 | 
			
		||||
 | 
			
		||||
const fenced_code = require("../shared/js/fenced_code");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
 | 
			
		||||
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 click_handlers: any;
 | 
			
		||||
declare let color_data: any;
 | 
			
		||||
declare let common: any;
 | 
			
		||||
declare let compose: any;
 | 
			
		||||
declare let compose_actions: any;
 | 
			
		||||
declare let composebox_typeahead: any;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
const emoji = require("../shared/js/emoji");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const copy_and_paste = require("./copy_and_paste");
 | 
			
		||||
const feedback_widget = require("./feedback_widget");
 | 
			
		||||
const topic_zoom = require("./topic_zoom");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const components = require("./components");
 | 
			
		||||
 | 
			
		||||
// 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_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";
 | 
			
		||||
 | 
			
		||||
import * as common from "./common";
 | 
			
		||||
 | 
			
		||||
function reset_error_messages() {
 | 
			
		||||
    $("#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 * as common from "../common";
 | 
			
		||||
 | 
			
		||||
import * as google_analytics from "./google-analytics";
 | 
			
		||||
import {activate_correct_tab} from "./tabbed-instructions";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
import _ from "lodash";
 | 
			
		||||
 | 
			
		||||
import * as blueslip from "../blueslip";
 | 
			
		||||
import * as common from "../common";
 | 
			
		||||
 | 
			
		||||
import * as google_analytics from "./google-analytics";
 | 
			
		||||
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,
 | 
			
		||||
    // some of the jQuery selectors below will return empty lists.
 | 
			
		||||
@@ -210,4 +212,3 @@ $(() => {
 | 
			
		||||
        this.parentNode.submit();
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
export {};
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,5 @@
 | 
			
		||||
import * as common from "../common";
 | 
			
		||||
 | 
			
		||||
export function detect_user_os() {
 | 
			
		||||
    if (/android/i.test(navigator.userAgent)) {
 | 
			
		||||
        return "android";
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
const Handlebars = require("handlebars/runtime");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const huddle_data = require("./huddle_data");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
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_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const pill_typeahead = require("./pill_typeahead");
 | 
			
		||||
const settings_ui = require("./settings_ui");
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
const SimpleBar = require("simplebar/dist/simplebar");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
const {localstorage} = require("./localstorage");
 | 
			
		||||
 | 
			
		||||
// What, if anything, obscures the home tab?
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const _ = require("lodash");
 | 
			
		||||
 | 
			
		||||
const common = require("./common");
 | 
			
		||||
/* Arguments used in the report_* functions are,
 | 
			
		||||
   response- response that we want to display
 | 
			
		||||
   status_box- element being used to display the response
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import marked from "../third/marked/lib/marked";
 | 
			
		||||
 | 
			
		||||
import * as common from "./common";
 | 
			
		||||
import * as feedback_widget from "./feedback_widget";
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user