-- Hyperscript behaviors shared by more than one view (behavior ladder -- rung 2). Apply one with `install ` in a `_` attribute; one-off -- behavior stays inline. Loaded by every layout (Web.Layout.Common), -- before _hyperscript itself, which reads this file when it starts. -- -- This file must hold at least one feature (a comment-only file fails to -- parse), and a parse error here stops all hyperscript on every page. -- Close each handler with `end` and then the behavior with its own `end`: -- with one `end` the next behavior is parsed into this one and only -- exists once this one has been installed somewhere. -- A button that closes its dialog, which stays in the page to open again. behavior CloseDialog on click close the closest end end -- A button that removes its dialog from the page (one-off dialogs swapped -- into #dialogs). behavior RemoveDialog on click remove the closest end end -- ARIA tabs, on a . A click on one of its own tabs (not those of -- a ui-tabs nested in a panel) selects it and shows the panel it controls -- (aria-controls); its other panels get hidden. behavior Tabs on click set tab to the closest <[role=tab]/> to event.target if no tab or tab.closest('ui-tabs') is not me exit end for other in <[role=tab]/> in me if other.closest('ui-tabs') is me set @aria-selected of other to 'false' add @hidden to #{other.getAttribute('aria-controls')} end end set @aria-selected of tab to 'true' remove @hidden from #{tab.getAttribute('aria-controls')} -- Scrolled down a panel (the tabs stuck at the top of a dialog), a tab, -- the same one too, shows its panel from the top. if my.getBoundingClientRect().top < tab.parentElement.getBoundingClientRect().top call me.scrollIntoView({block: 'start'}) end end end -- The navbar's
menu (on narrow screens): closes on a click -- outside it, on a link in it (an in-page anchor loads no new page) and -- when the browser restores the page from its back/forward cache. From md -- up its nav always shows, open or not. behavior NavMenu on click from elsewhere close me end on click if the closest to event.target close me end end on pageshow from window close me end end -- A podcast's player (an