Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

lightbox: Add tippy tooltip to lightbox title.

Austin Riba0943b3830020
diff --git a/static/js/lightbox.js b/static/js/lightbox.js
index 257a23e7e5e..c083587898d 100644
--- a/static/js/lightbox.js
+++ b/static/js/lightbox.js
@@ -210,9 +210,11 @@ function display_image(payload) {
img.src = payload.source;
$img_container.html(img).show();
+ const filename = payload.url?.split("/").pop();
$(".image-description .title")
.text(payload.title || "N/A")
- .prop("title", payload.title || "N/A");
+ .attr("aria-label", payload.title || "N/A")
+ .prop("data-filename", filename || "N/A");
$(".image-description .user").text(payload.user).prop("title", payload.user);
$(".image-actions .open, .image-actions .download").attr("href", payload.source);
@@ -411,7 +413,7 @@ export function parse_image_data(image) {
}
const payload = {
user: sender_full_name,
- title: $parent.attr("title"),
+ title: $parent.attr("aria-label") || $parent.attr("href"),
type,
preview: preview_src,
source,
diff --git a/static/js/tippyjs.js b/static/js/tippyjs.js
index 94bc8203e09..3d61d2e1f8b 100644
--- a/static/js/tippyjs.js
+++ b/static/js/tippyjs.js
@@ -267,4 +267,24 @@ export function initialize() {
instance.destroy();
},
});
+
+ delegate("body", {
+ target: ".image-info-wrapper > .image-description > .title",
+ appendTo: () => document.body,
+ onShow(instance) {
+ const title = $(instance.reference).attr("aria-label");
+ const filename = $(instance.reference).prop("data-filename");
+ const $markup = $("<span>").text(title);
+ if (title !== filename) {
+ // If the image title is the same as the filename, there's no reason
+ // to show this next line.
+ const second_line = $t({defaultMessage: "File name: {filename}"}, {filename});
+ $markup.append($("<br>"), $("<span>").text(second_line));
+ }
+ instance.setContent($markup[0]);
+ },
+ onHidden(instance) {
+ instance.destroy();
+ },
+ });
}