Platform isPortrait/isLandscape

This commit is contained in:
Adam Bradley
2015-07-21 21:58:34 -05:00
parent 996fae5b6c
commit cc9ff757b0
2 changed files with 25 additions and 10 deletions

View File

@@ -165,10 +165,11 @@ function initApp(window, document, config) {
// Platform is a global singleton
Platform.url(window.location.href);
Platform.userAgent(window.navigator.userAgent);
Platform.width(window.innerWidth);
Platform.height(window.innerHeight);
Platform.load(config);
// on resize be sure to clear out existing window dimensions
window.addEventListener('resize', Platform.resetDimensions);
return app;
}

View File

@@ -106,18 +106,32 @@ export class PlatformCtrl {
return this._ua;
}
width(val) {
if (arguments.length) {
this._w = val;
width() {
if (!this._w) {
this._w = window.innerWidth;
this._h = window.innerHeight;
}
return this._w || 0;
return this._w;
}
height(val) {
if (arguments.length) {
this._h = val;
height() {
if (!this._h) {
this._w = window.innerWidth;
this._h = window.innerHeight;
}
return this._h || 0;
return this._h;
}
isPortrait() {
return this.width() < this.height();
}
isLandscape() {
return !this.isPortrait();
}
resetDimensions() {
this._w = this._h = 0;
}