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
@@ -1,9 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const narrow_state = require("./narrow_state");
|
||||
const poll_widget = require("./poll_widget");
|
||||
const todo_widget = require("./todo_widget");
|
||||
const zform = require("./zform");
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as poll_widget from "./poll_widget";
|
||||
import * as todo_widget from "./todo_widget";
|
||||
import * as zform from "./zform";
|
||||
|
||||
const widgets = new Map([
|
||||
["poll", poll_widget],
|
||||
@@ -11,15 +9,14 @@ const widgets = new Map([
|
||||
["zform", zform],
|
||||
]);
|
||||
|
||||
const widget_contents = new Map();
|
||||
exports.widget_contents = widget_contents;
|
||||
export const widget_contents = new Map();
|
||||
|
||||
function set_widget_in_message(row, widget_elem) {
|
||||
const content_holder = row.find(".message_content");
|
||||
content_holder.empty().append(widget_elem);
|
||||
}
|
||||
|
||||
exports.activate = function (in_opts) {
|
||||
export function activate(in_opts) {
|
||||
const widget_type = in_opts.widget_type;
|
||||
const extra_data = in_opts.extra_data;
|
||||
const events = in_opts.events;
|
||||
@@ -76,18 +73,18 @@ exports.activate = function (in_opts) {
|
||||
if (events.length > 0) {
|
||||
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) {
|
||||
if (current_msg_list.get(idx) !== undefined) {
|
||||
const row = current_msg_list.get_row(idx);
|
||||
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);
|
||||
|
||||
if (!widget_elem) {
|
||||
@@ -100,6 +97,4 @@ exports.handle_event = function (widget_event) {
|
||||
const events = [widget_event];
|
||||
|
||||
widget_elem.handle_events(events);
|
||||
};
|
||||
|
||||
window.widgetize = exports;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user