A platform for community discussion. Free, open, simple.
FEATURE: add btn to toggle lightbox image info (#35762)
David Battersby157066421400
diff --git a/app/assets/stylesheets/common/base/lightbox.scss b/app/assets/stylesheets/common/base/lightbox.scssindex 3255bc8366b..a4bf77000a6 100644--- a/app/assets/stylesheets/common/base/lightbox.scss+++ b/app/assets/stylesheets/common/base/lightbox.scss@@ -132,27 +132,46 @@left: 0;bottom: var(--safe-area-inset-bottom);width: 100%;- padding: 0.5em;text-align: center;position: absolute;.pswp__caption-title {left: 50%;+ bottom: 0;color: #fff;line-height: 1.25em;position: relative;max-width: 800px;padding: 0 1em 0.25em;transform: translateX(-50%);+ transition: transform 0.4s ease;}.pswp__caption-details {+ position: relative;+ left: 50%;+ bottom: 0;+ opacity: 0;+ transform: translate(-50%, 100%);color: var(--secondary-high);font-size: var(--font-down-1);+ transition:+ transform 0.4s ease,+ opacity 0.4s ease;}}+.pswp--caption-expanded .pswp__caption-title {+ transform: translate(-50%, -5px);+}++.pswp--caption-expanded .pswp__caption-details {+ transform: translate(-50%, -5px);+ opacity: 1;+}+.pswp__button--download-image svg,-.pswp__button--original-image svg {+.pswp__button--original-image svg,+.pswp__button--image-info svg {padding: 0.4em;}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 9c5c3d2b9cb..c4f044d0f5a 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4883,6 +4883,7 @@ en:lightbox:download: "Download"open: "Original image"+ image_info: "Image information"previous: "Previous (Left arrow key)"next: "Next (Right arrow key)"counter: "%curr% of %total%"diff --git a/frontend/discourse/app/lib/lightbox.js b/frontend/discourse/app/lib/lightbox.jsindex c1ccc13d3ec..f11524b170f 100644--- a/frontend/discourse/app/lib/lightbox.js+++ b/frontend/discourse/app/lib/lightbox.js@@ -131,6 +131,18 @@ export default async function lightbox(elem, siteSettings) {});},});++ lightboxEl.pswp.ui.registerElement({+ name: "image-info",+ order: 9,+ isButton: true,+ tagName: "a",+ title: i18n("lightbox.image_info"),+ html: renderIcon("string", "circle-info", { class: "pswp__icn" }),+ onClick: () => {+ lightboxEl.pswp.element.classList.toggle("pswp--caption-expanded");+ },+ });});lightboxEl.addFilter("domItemData", (data, el) => {diff --git a/spec/system/lightbox_spec.rb b/spec/system/lightbox_spec.rbindex b8d5bfea7af..2f6e1c67839 100644--- a/spec/system/lightbox_spec.rb+++ b/spec/system/lightbox_spec.rb@@ -32,12 +32,30 @@ describe "Lightbox | Photoswipe", type: :system doexpect(lightbox).to have_no_counterexpect(lightbox).to have_caption_title("first image")- expect(lightbox).to have_caption_details("2400×3600 1.21 KB")+ expect(lightbox).to have_no_caption_detailsexpect(lightbox).to have_no_next_buttonexpect(lightbox).to have_no_prev_buttonexpect(lightbox).to have_download_buttonexpect(lightbox).to have_original_image_button+ expect(lightbox).to have_image_info_button+ end++ it "can toggle image info" do+ topic_page.visit_topic(topic)++ find("#post_1 a.lightbox").click++ expect(lightbox).to be_visible+ expect(lightbox).to have_no_caption_details++ lightbox.image_info_button.click++ expect(lightbox).to have_caption_details("2400×3600 1.21 KB")++ lightbox.image_info_button.click++ expect(lightbox).to have_no_caption_detailsendend@@ -60,12 +78,13 @@ describe "Lightbox | Photoswipe", type: :system doexpect(lightbox).to have_counter("2 / 2")expect(lightbox).to have_caption_title("second image")- expect(lightbox).to have_caption_details("2000×1000 1.21 KB")+ expect(lightbox).to have_no_caption_detailsexpect(lightbox).to have_next_buttonexpect(lightbox).to have_prev_buttonexpect(lightbox).to have_download_buttonexpect(lightbox).to have_original_image_button+ expect(lightbox).to have_image_info_buttonendend@@ -79,7 +98,7 @@ describe "Lightbox | Photoswipe", type: :system dopost.update(cooked: cpp.html)end- it "tap image to toggle UI" do+ it "toggles UI by tapping image" dotopic_page.visit_topic(topic)find("#post_1 a.lightbox").click@@ -93,7 +112,7 @@ describe "Lightbox | Photoswipe", type: :system doexpect(lightbox).to have_ui_visibleend- it "tap backdrop to close lightbox" do+ it "closes lightbox by tapping backdrop" dotopic_page.visit_topic(topic)find("#post_1 a.lightbox").click@@ -103,5 +122,22 @@ describe "Lightbox | Photoswipe", type: :system doexpect(lightbox).to be_hiddenend++ it "toggles image info by clicking button" do+ topic_page.visit_topic(topic)++ find("#post_1 a.lightbox").click++ expect(lightbox).to be_visible+ expect(lightbox).to have_no_caption_details++ lightbox.image_info_button.click++ expect(lightbox).to have_caption_details("400×300 1.21 KB")++ lightbox.image_info_button.click++ expect(lightbox).to have_no_caption_details+ endendenddiff --git a/spec/system/page_objects/components/photoswipe.rb b/spec/system/page_objects/components/photoswipe.rbindex b2429e16c3f..e15b3a80cb1 100644--- a/spec/system/page_objects/components/photoswipe.rb+++ b/spec/system/page_objects/components/photoswipe.rb@@ -12,6 +12,7 @@ module PageObjectsPREV_BTN = ".pswp__button--arrow--prev"DOWNLOAD_BTN = ".pswp__button--download-image"ORIGINAL_IMAGE_BTN = ".pswp__button--original-image"+ IMAGE_INFO_BTN = ".pswp__button--image-info"COUNTER = ".pswp__counter"CAPTION = ".pswp__caption"CAPTION_TITLE = ".pswp__caption-title"@@ -38,6 +39,10 @@ module PageObjectscomponent.find(PREV_BTN)end+ def image_info_button+ component.find(IMAGE_INFO_BTN)+ end+def close_buttoncomponent.find(CLOSE_BTN)end@@ -62,6 +67,10 @@ module PageObjectscomponent.has_no_css?(CAPTION)end+ def has_no_caption_details?+ component.has_no_css?(CAPTION_DETAILS)+ end+def has_next_button?component.has_css?(NEXT_BTN)end@@ -94,6 +103,10 @@ module PageObjectscomponent.has_no_css?(ORIGINAL_IMAGE_BTN)end+ def has_image_info_button?+ component.has_css?(IMAGE_INFO_BTN)+ end+def has_ui_visible?page.has_css?(UI_VISIBLE)end