A platform for community discussion. Free, open, simple.
UX: only show info btn when lightbox has image details (#35863)
David Battersbyf88dde48a2eb
diff --git a/frontend/discourse/app/lib/lightbox.js b/frontend/discourse/app/lib/lightbox.jsindex b58b562e318..bbe59fecd37 100644--- a/frontend/discourse/app/lib/lightbox.js+++ b/frontend/discourse/app/lib/lightbox.js@@ -143,6 +143,11 @@ export default async function lightbox(elem, siteSettings) {tagName: "a",title: i18n("lightbox.image_info"),html: renderIcon("string", "circle-info", { class: "pswp__icn" }),+ onInit: (el, pswp) => {+ pswp.on("change", () => {+ el.style.display = pswp.currSlide.data.details ? "block" : "none";+ });+ },onClick: () => {lightboxEl.pswp.element.classList.toggle("pswp--caption-expanded");},@@ -171,8 +176,9 @@ export default async function lightbox(elem, siteSettings) {"data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20width%3D%271%27%20height%3D%271%27/%3E";}+ const imgInfo = el.querySelector(".informations")?.textContent || "";+if (!width || !height) {- const imgInfo = el.querySelector(".informations")?.textContent || "";const dimensions = imgInfo.trim().split(" ")[0];[width, height] = dimensions.split(/x|×/).map(Number);}@@ -182,6 +188,7 @@ export default async function lightbox(elem, siteSettings) {data.src = data.src || el.getAttribute("data-large-src");data.title = el.title || el.alt;+ data.details = imgInfo;data.w = data.width = width;data.h = data.height = height;diff --git a/spec/system/lightbox_spec.rb b/spec/system/lightbox_spec.rbindex 2f6e1c67839..444f7ed4c56 100644--- a/spec/system/lightbox_spec.rb+++ b/spec/system/lightbox_spec.rb@@ -41,6 +41,15 @@ describe "Lightbox | Photoswipe", type: :system doexpect(lightbox).to have_image_info_buttonend+ it "does not show image info button when no image details are available" do+ post.update(cooked: post.cooked.gsub(%r{<span class="informations">[^<]*</span>}, ""))+ topic_page.visit_topic(topic)++ find("#post_1 a.lightbox").click++ expect(lightbox).to have_no_image_info_button+ end+it "can toggle image info" dotopic_page.visit_topic(topic)diff --git a/spec/system/page_objects/components/photoswipe.rb b/spec/system/page_objects/components/photoswipe.rbindex e15b3a80cb1..4762e11cedc 100644--- a/spec/system/page_objects/components/photoswipe.rb+++ b/spec/system/page_objects/components/photoswipe.rb@@ -107,6 +107,10 @@ module PageObjectscomponent.has_css?(IMAGE_INFO_BTN)end+ def has_no_image_info_button?+ component.has_no_css?(IMAGE_INFO_BTN)+ end+def has_ui_visible?page.has_css?(UI_VISIBLE)end