js: Convert static/js/upload_widget.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 16:15:23 -08:00 committed by Tim Abbott
parent a7b2e5ba03
commit e64c7a9efe
9 changed files with 32 additions and 21 deletions

View File

@ -184,7 +184,6 @@
"ui_init": false,
"unread": false,
"unread_ops": false,
"upload_widget": false,
"widgetize": false,
"zxcvbn": false
}

View File

@ -2,11 +2,15 @@
const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace");
const rewiremock = require("rewiremock/node");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
const upload_widget = set_global("upload_widget", {});
const upload_widget = {__esModule: true};
rewiremock("../../static/js/upload_widget").with(upload_widget);
rewiremock.enable();
const settings_emoji = zrequire("settings_emoji");
run_test("build_emoji_upload_widget", () => {
@ -28,3 +32,4 @@ run_test("build_emoji_upload_widget", () => {
settings_emoji.build_emoji_upload_widget();
assert(build_widget_stub);
});
rewiremock.disable();

View File

@ -1,6 +1,7 @@
"use strict";
const channel = require("./channel");
const upload_widget = require("./upload_widget");
exports.build_bot_create_widget = function () {
// We have to do strange gyrations with the file input to clear it,

View File

@ -34,7 +34,6 @@ import "../message_events";
import "../server_events";
import "../zulip";
import "../templates";
import "../upload_widget";
import "../avatar";
import "../realm_icon";
import "../realm_logo";

View File

@ -54,7 +54,6 @@ declare let typing_events: any;
declare let ui: any;
declare let unread: any;
declare let unread_ops: any;
declare let upload_widget: any;
declare let widgetize: any;
interface JQuery {

View File

@ -1,6 +1,7 @@
"use strict";
const channel = require("./channel");
const upload_widget = require("./upload_widget");
exports.build_realm_icon_widget = function (upload_function) {
const get_file_input = function () {

View File

@ -2,6 +2,7 @@
const channel = require("./channel");
const settings_config = require("./settings_config");
const upload_widget = require("./upload_widget");
exports.build_realm_logo_widget = function (upload_function, is_night) {
let logo_section_id = "#realm-day-logo-upload-widget";

View File

@ -9,6 +9,7 @@ const ListWidget = require("./list_widget");
const loading = require("./loading");
const people = require("./people");
const ui_report = require("./ui_report");
const upload_widget = require("./upload_widget");
const meta = {
loaded: false,

View File

@ -1,5 +1,3 @@
"use strict";
const default_max_file_size = 5;
const supported_types = ["image/jpeg", "image/png", "image/gif", "image/tiff"];
@ -12,12 +10,17 @@ function is_image_format(file) {
return supported_types.includes(type);
}
exports.build_widget = function (
get_file_input, // function returns a jQuery file input object
file_name_field, // jQuery object to show file name
input_error, // jQuery object for error text
clear_button, // jQuery button to clear last upload choice
upload_button, // jQuery button to open file dialog
export function build_widget(
// function returns a jQuery file input object
get_file_input,
// jQuery object to show file name
file_name_field,
// jQuery object for error text
input_error,
// jQuery button to clear last upload choice
clear_button,
// jQuery button to open file dialog
upload_button,
preview_text = null,
preview_image = null,
max_file_upload_size,
@ -110,11 +113,15 @@ exports.build_widget = function (
// so you can release handlers.
close,
};
};
exports.build_direct_upload_widget = function (
get_file_input, // function returns a jQuery file input object
input_error, // jQuery object for error text
upload_button, // jQuery button to open file dialog
}
export function build_direct_upload_widget(
// function returns a jQuery file input object
get_file_input,
// jQuery object for error text
input_error,
// jQuery button to open file dialog
upload_button,
upload_function,
max_file_upload_size,
) {
@ -177,6 +184,4 @@ exports.build_direct_upload_widget = function (
get_file_input().trigger("click");
e.preventDefault();
});
};
window.upload_widget = exports;
}