vUX / ModalDisplayer / v4.1.0
Mark up a trigger, hide your content, and a single delegated listener does the rest. A trigger inside an open dialog opens another on top of it.
Every setting below is a property on .config. Effect changes apply immediately;
the overlay settings are snapshotted when a modal opens, so they take effect from the next open.
Off means a click on the overlay no longer closes it.
Sign in → Forgot password → Terms is three layers deep. Each layer gets its own overlay, its own width and its own scroll container. Esc, an overlay click and a close button all pop only the topmost layer.
modal.depth
A page-level button cannot dismiss a stack: the overlay blocks the page, which is the
whole point of a modal. So closeAll() lives inside the deeper
dialogs, where it is actually reachable.
config.modalWidthsAttribute lets a single trigger override the responsive widths
for the modal it opens, without leaking into the next one. And the stack is shared by
all instances, because the state it protects (the body freeze) belongs to the document.
Same modal, three triggers, three widths. A trigger without the attribute falls back to the defaults.
“Help”, inside Profile settings, is opened by a different ModalDisplayer with its own trigger class and effect, yet it layers correctly and one Esc still pops exactly one layer.
A tall modal scrolls inside its own overlay while the page behind stays exactly where it was.
Every .config setter validates, and initialize() refuses an incomplete
setup. Each button below performs the call and prints what was thrown.
Scroll down, then open a modal. The page is held with overflow:hidden rather than by
taking the body out of flow, so it keeps both its scroll position and its layout.
Triggers in here stack a new layer on top of this one.
Opened from inside the sign-in modal: the one underneath stays open and intact.
Three layers deep. Esc pops one at a time, in reverse order.
An independent modal, opened straight from the page.
This confirm sits above the profile modal that opened it.
Opened by a different ModalDisplayer with its own effect, yet it stacks correctly
and one Esc still pops exactly one layer.
This scrolls inside its own overlay. The page behind stays exactly where it was.