refactor: extract the gallery modal into a shared lightbox service - #2059
refactor: extract the gallery modal into a shared lightbox service#2059joelabreo227 wants to merge 1 commit into
Conversation
GoDAM has two video lightboxes. The gallery block built the first one (April) inside its own view.js with no public entry point, so when godam-for-woo needed the same thing six weeks later it wrote a second, independent one. This adds the door that was missing. The service is a registered script handle (godam-lightbox-script) exposing window.GodamLightbox, so any surface that can enqueue a script can drive the same modal, including other plugins. Rendering is behind a renderer seam: the iframe renderer (the gallery's approach, and the default) ships here; in-DOM Video.js playback is the second renderer the seam exists for and lands with the godam-for-woo migration, shaped by that plugin's real requirements rather than guessed at now. The gallery keeps its playlist and its tile-preview side effects and calls the service for everything else. It passes its original class names as aliases, so the rendered DOM is unchanged for CSS and for the QA selectors that target those names. The modal styles move to a shared stylesheet declared against both the canonical and the legacy class names; retiring the legacy half is a follow-up to coordinate with QA. flushIframeAnalytics is carried over intact. Sending heatmap payloads from an iframe that is about to be torn down loses them, so the parent pulls them out and POSTs them itself first. Two tests now pin the flush-before-teardown ordering, which is the thing a rewrite would break silently. Adds 34 unit tests. The gallery modal previously had none: the QA suite defines selectors for it but no spec consumes them. Refs rtCamp/godam-plugin-wp#25 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
rtBot
left a comment
There was a problem hiding this comment.
Code analysis identified issues
action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.
phpcs scanning turned up:
Powered by rtCamp's GitHub Actions Library
|
|
||
| if ( file_exists( $lightbox_path ) ) { | ||
| $lightbox_assets = file_exists( $lightbox_asset_path ) | ||
| ? include $lightbox_asset_path |
There was a problem hiding this comment.
$lightbox_asset_path). Probably needs manual inspection (WordPressVIPMinimum.Files.IncludingFile.UsingVariable).
|
CI status, so nobody has to dig:
|
Deliverables 1 and 2 of rtCamp/godam-plugin-wp#25. No new user-facing feature: this is the foundation the "Show in lightbox" setting sits on, landed on its own so the risky part gets reviewed by itself.
Draft until @KMchaudhary has looked at it.
Why
GoDAM has two video lightboxes:
assets/src/blocks/godam-gallery-v2/view.jsassets/src/js/shared/godam-woo-video-modal.jswindow.GodamGalleryV2 = { init }window.GodamWooVideoModalThe second was written six weeks after the first. The likely reason is not an architectural disagreement: the gallery's modal was a private function inside a block's bundle, so another plugin had no way to call it. Adding a third lightbox for the Video block would have made the same mistake twice.
This PR adds the entry point that was missing, and moves the gallery onto it.
What changed
New:
assets/src/js/godam-lightbox/— the service, published as thegodam-lightbox-scripthandle exposingwindow.GodamLightbox. A handle rather than a bundled import, specifically sogodam-for-woocan consume it later without vendoring anything.The service owns the modal DOM, focus management, keyboard handling, and the media lifecycle. Callers own their playlist and their own side effects. Rendering sits behind a renderer seam:
createIframeRenderer()ships here. It is the gallery's existing approach and the intended default: nothing loads until the lightbox opens, and player layers, ads and skins work because the iframe is a real render of the player template.godam-for-wooalready has a working in-DOM modal, and that renderer should land with its migration, shaped by its real requirements (WooCommerce cart context, swipe navigation, addon panels), not guessed at now.Gallery migration.
view.jsdrops 118 lines of modal code and calls the service. It passes its original class names asaliases, so the rendered DOM is byte-identical for CSS and for the QA selectors. Modal styles move toassets/src/css/godam-lightbox.scss, declared against both the canonicalgodam-lightboxnames and the legacygodam-gallery-v2-modalnames.flushIframeAnalyticscarried over intact. This is the piece most likely to be lost in a rewrite. Heatmap payloads sent from an iframe that is about to be torn down get cancelled by the browser, so the parent pulls them out and POSTs them itself first. Two tests now pin the flush-before-teardown ordering.Tests
34 new unit tests (
assets/src/js/godam-lightbox/service.test.js). Full suite: 130 passing.Worth knowing before review: the gallery modal had no automated coverage at all.
godam-plugin-automationdefinesgalleryV2.modalselectors, but no spec consumes them, so the ticket's assumption that the existing suite proves no behaviour change does not hold for the modal. These unit tests are the first safety net under this behaviour. A QA spec driving the modal end to end is still worth having, and I have raised that on the ticket.Things to look at closely
Three paths load the gallery view script, and only one goes through
block.json. The Elementor widget (class-godam-gallery.php) and the[godam_video_gallery]shortcode enqueuegodam-gallery-v2-view-scriptdirectly, so they would have loaded aview.jswith nowindow.GodamLightbox. Both now enqueue the lightbox explicitly. I chose explicit lists because that is what this codebase already does everywhere; the alternative is mutating the registered handle'sdepsso future callers cannot forget. Happy to switch if you prefer that.Modal DOM is now built on first open, not on gallery construction. Previously every page with a gallery got the overlay and dialog nodes on load whether or not anyone opened a video. This is a real (small) behaviour change. It is better for the Video block case, and nothing asserts pre-open existence, but it is a change.
Two galleries on one page. Opening gallery B while A's modal is open now fires A's close path, so A's tile previews resume correctly. Previously the shared iframe was silently repointed and A was left thinking it was still open. Unreachable in practice, because the overlay covers the page and body scroll is locked, but the semantics did change.
document.bodynow also gets the canonicalgodam-lightbox-openclass alongside the legacy one. Additive; both are styled identically.Not verified locally
PHPCS did not run. Neither
composernor aphpCLI is available on the machine I built this on, sovendor/bin/phpcscould not be installed and the pre-commit hook'slint:phptask could not execute. I committed with--no-verifyfor that reason and nothing else.phpcs_on_pull_request.ymlcovers it here, so please treat the CI result as the gate on the four PHP files.wp-scripts lint-jsandlint-styleboth pass clean; the 5 remaining lint errors ingodam-gallery-v2/edit.jsandindex.jsare pre-existing onmainand untouched.No browser verification. I have not clicked through a real gallery in a browser. The unit tests cover the service's logic, not the rendered result, and the CSS move in particular deserves a visual check on a live gallery in grid, carousel and list layouts, plus mobile width.
Follow-ups this sets up
showInLightboxon the Video block, is now a small change: a newcreateIframeRenderercall withblockSource: 'video-block-lightbox'and no aliases.godam-gallery-v2-modalclass names, coordinated with QA soselectors/godam.jschanges in the same window.godam-for-woomigration.Refs rtCamp/godam-plugin-wp#25
🤖 Generated with Claude Code