Skip to content

Instantly share code, notes, and snippets.

@AlbertoDePena
Created May 3, 2018 20:06
Show Gist options
  • Save AlbertoDePena/0f087ddc8fbe39556be4610b42ec3e4b to your computer and use it in GitHub Desktop.
Save AlbertoDePena/0f087ddc8fbe39556be4610b42ec3e4b to your computer and use it in GitHub Desktop.
MDL - toggle drawer
import { autoinject, customAttribute } from 'aurelia-framework';
@autoinject()
@customAttribute('dp-toggle-drawer')
export class ToggleDrawerCustomAttribute {
private element: Element;
constructor(element: Element) {
this.element = element;
}
public attached(): void {
this.element.addEventListener('click', this.toggleDrawer);
}
public detached(): void {
this.element.removeEventListener('click', this.toggleDrawer);
}
private toggleDrawer(e: Event): void {
let layout = document.querySelector('.mdl-layout') as any;
let shouldToggle = layout.classList.contains('is-small-screen');
if (shouldToggle) {
layout.MaterialLayout.toggleDrawer();
}
e.stopPropagation();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment