mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 01:16:19 +00:00
js: Convert static/js/widgetize.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
3e8ddc229b
commit
68872f44f6
@@ -151,7 +151,6 @@
|
|||||||
"subs": false,
|
"subs": false,
|
||||||
"ui": false,
|
"ui": false,
|
||||||
"ui_init": false,
|
"ui_init": false,
|
||||||
"widgetize": false,
|
|
||||||
"zxcvbn": false
|
"zxcvbn": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ const {strict: assert} = require("assert");
|
|||||||
|
|
||||||
const rewiremock = require("rewiremock/node");
|
const rewiremock = require("rewiremock/node");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
|
|
||||||
const channel = {__esModule: true};
|
const channel = {__esModule: true};
|
||||||
rewiremock("../../static/js/channel").with(channel);
|
rewiremock("../../static/js/channel").with(channel);
|
||||||
const widgetize = set_global("widgetize", {});
|
const widgetize = {__esModule: true};
|
||||||
|
rewiremock("../../static/js/widgetize").with(widgetize);
|
||||||
const message_store = {__esModule: true};
|
const message_store = {__esModule: true};
|
||||||
|
|
||||||
rewiremock("../../static/js/message_store").with(message_store);
|
rewiremock("../../static/js/message_store").with(message_store);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
|
|||||||
import "../i18n";
|
import "../i18n";
|
||||||
import "../fold_dict";
|
import "../fold_dict";
|
||||||
import "../setup";
|
import "../setup";
|
||||||
import "../widgetize";
|
|
||||||
import "../message_list";
|
import "../message_list";
|
||||||
import "../narrow";
|
import "../narrow";
|
||||||
import "../reload";
|
import "../reload";
|
||||||
|
|||||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -20,7 +20,6 @@ declare let pointer: any;
|
|||||||
declare let settings_profile_fields: any;
|
declare let settings_profile_fields: any;
|
||||||
declare let subs: any;
|
declare let subs: any;
|
||||||
declare let ui: any;
|
declare let ui: any;
|
||||||
declare let widgetize: any;
|
|
||||||
declare let zulip_test: any;
|
declare let zulip_test: any;
|
||||||
|
|
||||||
interface JQuery {
|
interface JQuery {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const ui_util = require("./ui_util");
|
|||||||
const unread = require("./unread");
|
const unread = require("./unread");
|
||||||
const unread_ops = require("./unread_ops");
|
const unread_ops = require("./unread_ops");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
const widgetize = require("./widgetize");
|
||||||
|
|
||||||
let unnarrow_times;
|
let unnarrow_times;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
|
import * as widgetize from "./widgetize";
|
||||||
|
|
||||||
export function get_message_events(message) {
|
export function get_message_events(message) {
|
||||||
if (message.locally_echoed) {
|
if (message.locally_echoed) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
"use strict";
|
import * as narrow_state from "./narrow_state";
|
||||||
|
import * as poll_widget from "./poll_widget";
|
||||||
const narrow_state = require("./narrow_state");
|
import * as todo_widget from "./todo_widget";
|
||||||
const poll_widget = require("./poll_widget");
|
import * as zform from "./zform";
|
||||||
const todo_widget = require("./todo_widget");
|
|
||||||
const zform = require("./zform");
|
|
||||||
|
|
||||||
const widgets = new Map([
|
const widgets = new Map([
|
||||||
["poll", poll_widget],
|
["poll", poll_widget],
|
||||||
@@ -11,15 +9,14 @@ const widgets = new Map([
|
|||||||
["zform", zform],
|
["zform", zform],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const widget_contents = new Map();
|
export const widget_contents = new Map();
|
||||||
exports.widget_contents = widget_contents;
|
|
||||||
|
|
||||||
function set_widget_in_message(row, widget_elem) {
|
function set_widget_in_message(row, widget_elem) {
|
||||||
const content_holder = row.find(".message_content");
|
const content_holder = row.find(".message_content");
|
||||||
content_holder.empty().append(widget_elem);
|
content_holder.empty().append(widget_elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.activate = function (in_opts) {
|
export function activate(in_opts) {
|
||||||
const widget_type = in_opts.widget_type;
|
const widget_type = in_opts.widget_type;
|
||||||
const extra_data = in_opts.extra_data;
|
const extra_data = in_opts.extra_data;
|
||||||
const events = in_opts.events;
|
const events = in_opts.events;
|
||||||
@@ -76,18 +73,18 @@ exports.activate = function (in_opts) {
|
|||||||
if (events.length > 0) {
|
if (events.length > 0) {
|
||||||
widget_elem.handle_events(events);
|
widget_elem.handle_events(events);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.set_widgets_for_list = function () {
|
export function set_widgets_for_list() {
|
||||||
for (const [idx, widget_elem] of widget_contents) {
|
for (const [idx, widget_elem] of widget_contents) {
|
||||||
if (current_msg_list.get(idx) !== undefined) {
|
if (current_msg_list.get(idx) !== undefined) {
|
||||||
const row = current_msg_list.get_row(idx);
|
const row = current_msg_list.get_row(idx);
|
||||||
set_widget_in_message(row, widget_elem);
|
set_widget_in_message(row, widget_elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.handle_event = function (widget_event) {
|
export function handle_event(widget_event) {
|
||||||
const widget_elem = widget_contents.get(widget_event.message_id);
|
const widget_elem = widget_contents.get(widget_event.message_id);
|
||||||
|
|
||||||
if (!widget_elem) {
|
if (!widget_elem) {
|
||||||
@@ -100,6 +97,4 @@ exports.handle_event = function (widget_event) {
|
|||||||
const events = [widget_event];
|
const events = [widget_event];
|
||||||
|
|
||||||
widget_elem.handle_events(events);
|
widget_elem.handle_events(events);
|
||||||
};
|
}
|
||||||
|
|
||||||
window.widgetize = exports;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user