Skip to content

Instantly share code, notes, and snippets.

@rquast
Created March 9, 2018 23:16
Show Gist options
  • Save rquast/8a5a3e4a557add6bd59b10b494efe962 to your computer and use it in GitHub Desktop.
Save rquast/8a5a3e4a557add6bd59b10b494efe962 to your computer and use it in GitHub Desktop.
import {PLATFORM} from 'aurelia-pal';
import {noView} from 'aurelia-framework';
@noView()
export class Resize {
desktop = true;
resizing = false;
constructor() {
if (typeof(document) !== 'undefined') {
this.desktop = document.documentElement.clientWidth > 768;
} else {
this.desktop = true;
}
PLATFORM.addEventListener('resize', this.resizeEvent);
}
resizeEvent = (e) => {
if (!this.resizing) {
PLATFORM.requestAnimationFrame(() => {
if (typeof(document) !== 'undefined') {
this.desktop = document.documentElement.clientWidth > 768;
} else {
this.desktop = true;
}
this.resizing = false;
});
this.resizing = true;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment