Constructor
new Modal()
- Source:
Example
const myModal = new Modal();
const triggerButton = document.querySelector('trigger');
myModal.optionalClass = "modal--myModal";
myModal.content = '<p>Some sample content!</p>';
myModal.focusOnClose = triggerButton;
triggerButton.addEventListener('click', () => {
myModal.open();
});
Members
(static) hash
Get current url hash
- Source:
closeButtonContent
Sets the content of the close button, useful for localizing.
Setter. Usage: modalInstance.closeButtonContent = "<String of HTML!>"
- Source:
content
Sets the content of the modal.
Setter. Usage: modalInstance.content = MyHTMLElement
- Source:
focusOnClose
Gets the element that will be focused when the modal closes
- Source:
focusOnClose
Sets the element that will be focused when the modal closes.
Setter. Usage: modalInstance.focusOnClose = myElement
- Source:
onClose
Get the function that is called when the modal closes
- Source:
onClose
Sets the function that is called when the modal closes.
Setter. Usage: modalInstance.onClose = myFunction
- Source:
onCloseStart
Get the function that is called just before the modal closes
- Source:
onCloseStart
Sets the function that is called just before the modal closes.
If this is set, when modalInstance.close()is called it will run the set function with a callback. It will then wait for that callback to be run before completing the close function and calling onClose. Setter. Usage:
modalInstance.onClose = (cb) => {
// do some animation
cb();
}
modalInstance.close(); `
- Source:
onOpen
Gets the function that is called when the modal opens
- Source:
onOpen
Sets the function that is called when the modal opens.
Setter. Usage: modalInstance.onOpen = myFunction
- Source:
optionalClass
Sets an optional class name on the modal for custom styling.
Setter. Usage: modalInstance.optionalClass = "modal--myclass"
- Source:
optionalClass
Gets the optional class name
- Source:
Methods
close()
Closes modal, removes content and optional class, and shifts user focus back to triggering element, if specified.
- Source:
focusFirstElement()
Shifts focus to the first element inside the content
- Source:
focusLastElement()
Shifts focus to the last element inside the content
- Source:
open()
Opens modal, adds content and optional CSS class
- Source: