Files
basecoat/src/js/sidebar.js
T

25 lines
788 B
JavaScript
Raw Normal View History

2025-05-02 18:27:45 +08:00
window.basecoat = window.basecoat || {};
window.basecoat.registerSidebar= function(Alpine) {
if (Alpine.components && Alpine.components.sidebar) return;
2025-05-04 15:58:10 +08:00
Alpine.data('sidebar', (initialOpen = true, initialMobileOpen = false) => ({
open: window.innerWidth >= 768
? initialOpen
: initialMobileOpen,
2025-05-02 18:27:45 +08:00
init() {
2025-05-04 15:58:10 +08:00
this.$nextTick(() => {
this.$el.removeAttribute('data-uninitialized');
});
2025-05-02 18:27:45 +08:00
},
$main: {
2025-05-04 15:58:10 +08:00
'@sidebar:open.window'(e) { this.open = true },
'@sidebar:close.window'(e) { this.open = false },
'@sidebar:toggle.window'(e) { this.open = !this.open },
2025-05-02 22:43:40 +08:00
'@click'(e) { if (e.target === this.$el) this.open = false },
2025-05-02 18:27:45 +08:00
':aria-hidden'() { return !this.open },
2025-05-04 15:58:10 +08:00
':inert'() { return !this.open }
2025-05-02 18:27:45 +08:00
},
}));
};