Step 1 - Building the UI
The UI for this project can be anything, all that's required is a link to trigger the modal.
Step 2 - Building the modal
The custom modal will consist of 4 major parts: the Modal Wrapper div, which will be shown/hidden in the custom animations, the Modal Background div, which darkens the page & will trigger the closing of the modal on click, the Modal class itself, which styles the modal, & an empty div with the ID #ajax-container, which will house the content pulled in from the collection item page.
The Modal Wrapper needs to be set to position: fixed; & set to full screen & overflow: auto; so that the div will scroll if the content escapes the viewport. For this project we added a Modal Padding div to define the negative space around the modal. The Modal Background div is also set to position: fixed;& full screen. And the Modal class is set to position: relative; in order that it displays on top of the modal close trigger div.
We also placed a Modal Close Icon nested inside the Modal div. This must be before the #ajax-container div so that it's the first element tabbed into so it must have z-indexing set to display on top of the #ajax-container div. This element is a part of the modal itself, rather than the content, because importing an element with an interaction will break the interaction behavior.
Step 3 - Creating the modal animations
The animations are pretty straightforward... the Modal Wrapper div needs to be set to opacity: 0%; as an initial state, then animated to display: block; & opacity: 100%; on click. Then it just needs to be animated back to opacity: 0%; & display: none; on dismissal.
The trick to making the modal modular is to define the animations not on the element itself, but as individual classes that can be appended to any element to form a combo class. For this project, we're defining the launch animation on IX - Launch Modal & attaching it to the Movie Card element & we're defining the dismissal animation on IX - Dismiss Modal & attaching it to the Modal Background & Modal Close Icon elements. These IX classes will need to be created as base classes so that the animations can be attached to them independently, rather than to the combo class. And the launch animations will need to affect all instances of Modal Wrapper while the dismissal animations will only need to affect parent instances.
Step 4 - Creating the modal content
For this project, the modal content is simply a YouTube element inside a padding div. The important part is that it's wrapped in a div with a unique ID, which is nested inside a Hide All div.
Step 5 - Adding the attributes
An attribute will need to be added to each modal link that corresponds with the content it should display in the modal. For instance, if the content div is #modal-godzilla-minus-one, then it's corresponding link will need to have data-modal-content-id="modal-godzilla-minus-one" attributed.
Step 6 - Add the javascript
Paste the following Javascript at the end of the <body> of the page.
Step 7 - Enabling tabbing into the YouTube iframe
Since we want this modal to be fully keyboard navigable, we'll need to add this javascript to append tabindex="0" to the YouTube iframe.