From cc9ff757b0fd901417b5f7ef793190ada876712b Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 21 Jul 2015 21:58:34 -0500 Subject: [PATCH] Platform isPortrait/isLandscape --- ionic/components/app/app.ts | 5 +++-- ionic/platform/platform.ts | 30 ++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index e950daa8fe..985c09254f 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -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; } diff --git a/ionic/platform/platform.ts b/ionic/platform/platform.ts index 8a2748cd67..21d7981ad9 100644 --- a/ionic/platform/platform.ts +++ b/ionic/platform/platform.ts @@ -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; }