Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/lightbox.js to ES6 module.
Anders Kaseorg76bfa78beb1c
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 871ad25f66f..a8ff0a858bf 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -156,7 +156,6 @@"info_overlay": false,"input_pill": false,"jQuery": false,- "lightbox": false,"list_util": false,"localStorage": false,"location": false,diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex 39f5102abb4..4bd1901ce32 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -74,7 +74,8 @@ const hashchange = set_global("hashchange", {in_recent_topics_hash: () => false,});set_global("info_overlay", {});-const lightbox = set_global("lightbox", {});+const lightbox = {__esModule: true};+rewiremock("../../static/js/lightbox").with(lightbox);const list_util = set_global("list_util", {});const message_edit = {__esModule: true};rewiremock("../../static/js/message_edit").with(message_edit);diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.jsindex 61fc202fce3..2cfd1de1d6d 100644--- a/frontend_tests/node_tests/ui_init.js+++ b/frontend_tests/node_tests/ui_init.js@@ -110,7 +110,6 @@ rewiremock.enable();const util = zrequire("util");zrequire("hash_util");-zrequire("lightbox");zrequire("overlays");zrequire("message_view_header");zrequire("presence");diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex dcb64c980e1..b9c047f919e 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -26,7 +26,6 @@ import "../narrow";import "../reload";import "../compose_actions";import "../subs";-import "../lightbox";import "../ui_report";import "../message_scroll";import "../info_overlay";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 8131a9cdd1a..892bb316931 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -32,7 +32,6 @@ declare let hotspots: any;declare let i18n: any;declare let info_overlay: any;declare let input_pill: any;-declare let lightbox: any;declare let list_util: any;declare let message_events: any;declare let message_fetch: any;diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex e5bd2d928a1..1190e653e93 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -9,6 +9,7 @@ const condense = require("./condense");const copy_and_paste = require("./copy_and_paste");const drafts = require("./drafts");const feedback_widget = require("./feedback_widget");+const lightbox = require("./lightbox");const message_edit = require("./message_edit");const muting_ui = require("./muting_ui");const topic_zoom = require("./topic_zoom");diff --git a/static/js/lightbox.js b/static/js/lightbox.jsindex bf4cbf85eff..3b2ccd3f46e 100644--- a/static/js/lightbox.js+++ b/static/js/lightbox.js@@ -1,15 +1,13 @@-"use strict";--const {LightboxCanvas} = require("./lightbox_canvas");-const people = require("./people");-const rows = require("./rows");+import {LightboxCanvas} from "./lightbox_canvas";+import * as people from "./people";+import * as rows from "./rows";let is_open = false;// the asset map is a map of all retrieved images and YouTube videos that are// memoized instead of being looked up multiple times.const asset_map = new Map();-exports.render_lightbox_list_images = function (preview_source) {+export function render_lightbox_list_images(preview_source) {if (!is_open) {const images = Array.prototype.slice.call($(".focused_table .message_inline_image img"));const $image_list = $("#lightbox_overlay .image-list").html("");@@ -29,13 +27,13 @@ exports.render_lightbox_list_images = function (preview_source) {// while we still have its original DOM element handy, so// that navigating within the list only needs the `src`// attribute used to construct the node object above.- exports.parse_image_data(img);+ parse_image_data(img);}}-};+}function display_image(payload) {- exports.render_lightbox_list_images(payload.preview);+ render_lightbox_list_images(payload.preview);$(".player-container").hide();$(".image-actions, .image-description, .download, .lightbox-canvas-trigger").show();@@ -63,7 +61,7 @@ function display_image(payload) {}function display_video(payload) {- exports.render_lightbox_list_images(payload.preview);+ render_lightbox_list_images(payload.preview);$("#lightbox_overlay .image-preview, .image-description, .download, .lightbox-canvas-trigger",@@ -97,7 +95,7 @@ function display_video(payload) {$(".image-actions .open").attr("href", payload.url);}-exports.open = function ($image) {+export function open($image) {// if the asset_map already contains the metadata required to display the// asset, just recall that metadata.let $preview_src = $image.attr("src");@@ -118,7 +116,7 @@ exports.open = function ($image) {payload = asset_map.get($preview_src);}if (payload === undefined) {- payload = exports.parse_image_data($image);+ payload = parse_image_data($image);}}@@ -146,9 +144,9 @@ exports.open = function ($image) {popovers.hide_all();is_open = true;-};+}-exports.show_from_selected_message = function () {+export function show_from_selected_message() {const $message_selected = $(".selected_message");let $message = $message_selected;let $image = $message.find(".message_inline_image img");@@ -187,12 +185,12 @@ exports.show_from_selected_message = function () {}if ($image.length !== 0) {- exports.open($image);+ open($image);}-};+}// retrieve the metadata from the DOM and store into the asset_map.-exports.parse_image_data = function (image) {+export function parse_image_data(image) {const $image = $(image);const $preview_src = $image.attr("src");@@ -256,25 +254,25 @@ exports.parse_image_data = function (image) {asset_map.set($preview_src, payload);return payload;-};+}-exports.prev = function () {+export function prev() {$(".image-list .image.selected").prev().trigger("click");-};+}-exports.next = function () {+export function next() {$(".image-list .image.selected").next().trigger("click");-};+}// this is a block of events that are required for the lightbox to work.-exports.initialize = function () {+export function initialize() {$("#main_div, #preview_content").on("click", ".message_inline_image a", function (e) {// prevent the link from opening in a new page.e.preventDefault();// prevent the message compose dialog from happening.e.stopPropagation();const $img = $(this).find("img");- exports.open($img);+ open($img);});$("#lightbox_overlay .download").on("click", function () {@@ -287,7 +285,7 @@ exports.initialize = function () {`.message_row img[src='${CSS.escape($(this).attr("data-src"))}']`,);- exports.open($original_image);+ open($original_image);$(".image-list .image.selected").removeClass("selected");$(this).addClass("selected");@@ -317,9 +315,9 @@ exports.initialize = function () {const direction = $(this).attr("data-direction");if (direction === "next") {- exports.next();+ next();} else if (direction === "prev") {- exports.prev();+ prev();}});@@ -330,12 +328,12 @@ exports.initialize = function () {$(this).addClass("enabled");// the `lightbox.open` function will see the enabled class and// enable the `LightboxCanvas` class.- exports.open($img);+ open($img);} else {$img = $($("#lightbox_overlay").find(".image-preview canvas")[0].image);$(this).removeClass("enabled");- exports.open($img);+ open($img);}});@@ -355,6 +353,4 @@ exports.initialize = function () {overlays.close_overlay("lightbox");}});-};--window.lightbox = exports;+}diff --git a/static/js/ui_init.js b/static/js/ui_init.jsindex a909258eb2d..2fe4822d262 100644--- a/static/js/ui_init.js+++ b/static/js/ui_init.js@@ -17,6 +17,7 @@ const drafts = require("./drafts");const echo = require("./echo");const emojisets = require("./emojisets");const invite = require("./invite");+const lightbox = require("./lightbox");const markdown = require("./markdown");const markdown_config = require("./markdown_config");const message_edit = require("./message_edit");