fix(viewport): Auto update viewport tag

This commit is contained in:
Adam Bradley
2014-05-02 10:12:48 -05:00
parent 2094d83c77
commit 5f8e9040bd
7 changed files with 583 additions and 67 deletions

View File

@@ -90,6 +90,8 @@
if(this.isWebView()) {
this.platforms.push('webview');
this.platforms.push('cordova');
} else {
this.platforms.push('browser');
}
if(this.isIPad()) this.platforms.push('ipad');
@@ -129,7 +131,10 @@
* @returns {boolean} Whether we are running on iPad.
*/
isIPad: function() {
return this.ua.toLowerCase().indexOf('ipad') >= 0;
if( /iPad/i.test(window.navigator.platform) ) {
return true;
}
return /iPad/i.test(this.ua);
},
/**
* @ngdoc method
@@ -170,7 +175,7 @@
} else if(this.ua.indexOf('iPhone') > -1 || this.ua.indexOf('iPad') > -1 || this.ua.indexOf('iPod') > -1) {
platformName = 'ios';
} else {
platformName = '';
platformName = window.navigator.platform && window.navigator.platform.toLowerCase().split(' ')[0] || '';
}
},

View File

@@ -2,6 +2,14 @@
var viewportTag;
var viewportProperties = {};
ionic.viewport = {
orientation: function() {
// 0 = Portrait
// 90 = Landscape
// not using window.orientation because each device has a different implementation
return (window.innerWidth > window.innerHeight ? 90 : 0);
}
};
function viewportLoadTag() {
var x;
@@ -20,38 +28,96 @@ function viewportLoadTag() {
keyValue = props[x].split('=');
if(keyValue.length == 2) viewportProperties[ keyValue[0] ] = keyValue[1];
}
viewportInitWebView();
viewportUpdate();
}
}
function viewportInitWebView() {
function viewportUpdate() {
// unit tests in viewport.unit.js
var initWidth = viewportProperties.width;
var initHeight = viewportProperties.height;
var p = ionic.Platform;
var version = p.version();
var DEVICE_WIDTH = 'device-width';
var DEVICE_HEIGHT = 'device-height';
var orientation = ionic.viewport.orientation();
if( ionic.Platform.isWebView() ) {
viewportProperties.height = 'device-height';
// Most times we're removing the height and adding the width
// So this is the default to start with, then modify per platform/version/oreintation
delete viewportProperties.height;
viewportProperties.width = DEVICE_WIDTH;
} else if( ionic.Platform.isIOS() && viewportProperties.height ) {
// if its not a webview, and a viewport height was set, just removing
// the height value doesn't trigger the change, but setting to 0 does the trick
viewportProperties.height = '0';
if( p.isIPad() ) {
// iPad
if( version > 7 ) {
// iPad >= 7.1
// https://issues.apache.org/jira/browse/CB-4323
delete viewportProperties.width;
} else {
// iPad <= 7.0
if( p.isWebView() ) {
// iPad <= 7.0 WebView
if( orientation == 90 ) {
// iPad <= 7.0 WebView Landscape
viewportProperties.height = '0';
} else if(version == 7) {
// iPad <= 7.0 WebView Portait
viewportProperties.height = DEVICE_HEIGHT;
}
} else {
// iPad <= 6.1 Browser
if(version < 7) {
viewportProperties.height = '0';
}
}
}
} else if( p.isIOS() ) {
// iPhone
if( p.isWebView() ) {
// iPhone WebView
if(version > 7) {
// iPhone >= 7.1 WebView
delete viewportProperties.width;
} else if(version < 7) {
// iPhone <= 6.1 WebView
// if height was set it needs to get removed with this hack for <= 6.1
if( initHeight ) viewportProperties.height = '0';
}
} else {
// iPhone Browser
if (version < 7) {
// iPhone <= 6.1 Browser
// if height was set it needs to get removed with this hack for <= 6.1
if( initHeight ) viewportProperties.height = '0';
}
}
} else if( viewportProperties.height ) {
delete viewportProperties.height;
}
// only update the viewport tag if there was a change
if(initHeight !== viewportProperties.height) viewportUpdate();
console.debug(viewportTag.content)
if(initWidth !== viewportProperties.width || initHeight !== viewportProperties.height) {
viewportTagUpdate();
}
}
function viewportUpdate(updates) {
if(!viewportTag) return;
function viewportTagUpdate(updates) {
ionic.Utils.extend(viewportProperties, updates);
var key, props = [];
for(key in viewportProperties) {
if(viewportProperties[key]) props.push(key + '=' + viewportProperties[key]);
if( viewportProperties[key] ) props.push(key + '=' + viewportProperties[key]);
}
viewportTag.content = props.join(', ');
@@ -59,4 +125,8 @@ function viewportUpdate(updates) {
ionic.DomUtil.ready(function() {
viewportLoadTag();
window.addEventListener("orientationchange", function(){
setTimeout(viewportUpdate, 1000);
}, false);
});

View File

@@ -26,7 +26,7 @@
top: $bar-height + $ios7-statusbar-height;
}
.has-header,
.has-header,
.bar-subheader {
top: $bar-height + $ios7-statusbar-height;
}
@@ -45,3 +45,9 @@
margin-bottom: 20px;
}
}
@media (orientation:landscape) {
.platform-ios7.platform-browser.platform-ipad {
position: fixed; // required for iPad 7 Safari
}
}

View File

@@ -258,6 +258,42 @@
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
<label class="item item-input">
<textarea placeholder="Description"></textarea>
</label>
</div>
<div class="padding">

View File

@@ -5,6 +5,9 @@ describe('Ionic Platform Service', function() {
beforeEach(inject(function($window, $ionicPlatform, $rootScope) {
window = $window;
window.navigator = {
platform: ''
};
ionic.Platform.ua = '';
ionicPlatform = $ionicPlatform;
rootScope = $rootScope;
@@ -84,6 +87,39 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.version()).toEqual(7.0);
});
it('should not be iPad from none iPad user agent', function() {
ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';
ionic.Platform.setPlatform(undefined);
ionic.Platform.setVersion(undefined);
expect(ionic.Platform.isIPad()).toEqual(false);
});
it('should be iPad from user agent', function() {
ionic.Platform.ua = 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';
ionic.Platform.setPlatform(undefined);
ionic.Platform.setVersion(undefined);
expect(ionic.Platform.isIPad()).toEqual(true);
});
it('should be iPad from iPad in window.navigator.platform and webview, but iPhone in user agent', function() {
window.cordova = {};
ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
window.navigator = {
platform: 'iPad Simulator'
};
ionic.Platform.setPlatform(undefined);
ionic.Platform.setVersion(undefined);
expect(ionic.Platform.isIPad()).toEqual(true);
});
it('should not be iPad from no in window.navigator.platform, and iPhone in user agent', function() {
ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
window.navigator = {};
ionic.Platform.setPlatform(undefined);
ionic.Platform.setVersion(undefined);
expect(ionic.Platform.isIPad()).toEqual(false);
});
it('is iOS', function() {
ionic.Platform.setPlatform('iOS');
expect(ionic.Platform.isIOS()).toEqual(true);
@@ -104,6 +140,7 @@ describe('Ionic Platform Service', function() {
});
it('is WebView', function() {
window.cordova = undefined;
expect(ionic.Platform.isWebView()).toEqual(false);
window.cordova = {};
expect(ionic.Platform.isWebView()).toEqual(true);
@@ -155,7 +192,7 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.platforms[1]).toEqual('cordova');
});
it('should not set any platform', function() {
it('should not set if its not a webview but only a browser', function() {
window.cordova = null;
window.PhoneGap = null;
window.phonegap = null;
@@ -164,7 +201,7 @@ describe('Ionic Platform Service', function() {
ionic.Platform._checkPlatforms()
expect(ionic.Platform.platforms.length).toEqual(0);
expect(ionic.Platform.platforms[0]).toEqual('browser');
});
it('sets grade a from iOS7', function() {

View File

@@ -29,6 +29,9 @@
-iOS 6.1 Cordova no viewport height, keyboard is over webview
-iOS 6.1 Safari no viewport height, keyboard is over webview
http://cordova.apache.org/docs/en/3.3.0/guide_platforms_ios_upgrading.md.html#Upgrading%20iOS
https://issues.apache.org/jira/browse/CB-4323
*/
@@ -42,6 +45,9 @@ describe('Ionic Viewport', function() {
_activeElement = null; // the element which has focus
window.cordova = undefined;
window.device = undefined;
window.navigator = {};
window.innerWidth = 1;
window.innerHeight = 2;
ionic.Platform.ua = '';
ionic.Platform.platforms = null;
ionic.Platform.setPlatform('');
@@ -59,79 +65,434 @@ describe('Ionic Viewport', function() {
if(vportTag) vportTag.parentNode.removeChild(vportTag);
});
it('Should have height=device-height for iOS 7+ on webview', function(){
// iOS 7.1, iPad, WebView
it('Should remove width and height from viewport for iOS >= 7.1, iPad, WebView', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.1');
window.cordova = {};
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no');
});
// iOS 7.1, iPad, Browser
it('Should remove width and height from viewport for iOS >= 7.1, iPad, Browser', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.1');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no');
});
// iOS 7.0, iPad, WebView
it('Should keep width and height in viewport for iOS 7.0, iPad, WebView, Portrait', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
window.cordova = {};
window.innerWidth = 1;
window.innerHeight = 2;
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');
});
it('Should add width and height to viewport for iOS 7.0, iPad, WebView, Portrait', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
window.cordova = {};
window.innerWidth = 1;
window.innerHeight = 2;
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');
});
it('Should add width and height=0 to viewport for iOS 7.0, iPad, WebView, Landscape', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
window.cordova = {};
window.innerWidth = 2;
window.innerHeight = 1;
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
it('Should keep width reset height to 0 in viewport for iOS 7.0, iPad, WebView, Landscape', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
window.cordova = {};
window.innerWidth = 2;
window.innerHeight = 1;
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
// iOS 7.0, iPad, Browser
it('Should keep width, but remove height from viewport for iOS 7.0, iPad, Browser', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should add width, but not add height to viewport for iOS 7.0, iPad, Browser', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('7.0');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
// iOS 6.1, iPad, WebView
it('Should keep width, but remove height from viewport for iOS 6.1, iPad, WebView, Portrait', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
window.cordova = {};
window.innerWidth = 1;
window.innerHeight = 2;
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should add width, but not add height to viewport for iOS 6.1, iPad, WebView, Portrait', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
window.cordova = {};
window.innerWidth = 1;
window.innerHeight = 2;
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should keep width, but replace height with 0 in viewport for iOS 6.1, iPad, WebView, Landscape', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
window.cordova = {};
window.innerWidth = 2;
window.innerHeight = 1;
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
it('Should add width and add height=0 to viewport for iOS 6.1, iPad, WebView, Landscape', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
window.cordova = {};
window.innerWidth = 2;
window.innerHeight = 1;
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
// iOS 6.1, iPad, Browser
it('Should keep width, and set height=0 for viewport for iOS 6.1, iPad, Browser, Portrait', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
it('Should add width, and add height=0 to viewport for iOS 6.1, iPad, Browser', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.ua = 'ipad';
ionic.Platform.setVersion('6.1');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
// iOS 7.1, iPhone, WebView
it('Should remove width and height from viewport for iOS 7.1, iPhone, WebView', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.setVersion('7.1');
window.cordova = {};
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no');
});
it('Should do nothing width and height already in viewport for iOS 7.1, iPhone, WebView', function(){
ionic.Platform.setPlatform('ios');
ionic.Platform.setVersion('7.1');
window.cordova = {};
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no');
});
// iOS 7.1, iPhone, Browser
it('Should keep width, but remove height from viewport for iOS >= 7.1, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.1');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should add width, but not height to viewport for iOS >= 7.1, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.1');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
// iOS 7.0, iPhone, WebView
it('Should keep width, but not height in viewport for iOS 7.0, iPhone, WebView', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.0');
expect( ionic.Platform.isAndroid() ).toEqual(false);
expect( ionic.Platform.isIOS() ).toEqual(true);
//so isWebView() is true
window.cordova = {};
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( viewportProperties.height ).toEqual('device-height');
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should not have height=device-height for iOS 7+ on browser', function(){
it('Should add width, but not height to viewport for iOS 7.0, iPhone, WebView', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.0');
expect( ionic.Platform.isAndroid() ).toEqual(false);
expect( ionic.Platform.isIOS() ).toEqual(true);
viewportLoadTag();
expect( viewportProperties.height ).not.toEqual('device-height');
});
it('Should have height=device-height for Android on webview', function(){
ionic.Platform.setPlatform('Android');
expect( ionic.Platform.isAndroid() ).toEqual(true);
expect( ionic.Platform.isIOS() ).toEqual(false);
//so isWebView() is true
window.cordova = {};
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( viewportProperties.height ).toEqual('device-height');
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should not have height=device-height for Android on browser', function(){
ionic.Platform.setPlatform('Android');
expect( ionic.Platform.isAndroid() ).toEqual(true);
expect( ionic.Platform.isIOS() ).toEqual(false);
// iOS 7.0, iPhone, Browser
it('Should keep width but remove height from viewport for iOS 7.0, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.0');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( viewportProperties.height ).not.toEqual('device-height');
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should not re-add height=device-height for webview if its already there', function(){
ionic.Platform.setPlatform('ios');
it('Should add width but not height to viewport for iOS 7.0, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.0');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
// iOS 6.1, iPhone, WebView
it('Should add width but not height to viewport for iOS 6.1, iPhone, WebView', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.1');
window.cordova = {};
var originalViewport = ' initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height ';
vportTag.setAttribute('content', originalViewport);
vportTag.content = 'user-scalable=no';
viewportLoadTag();
// if it was changed the spaces would have been removed
expect( vportTag.content ).toEqual(originalViewport);
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should not update the viewport if its not a webview and height=device-height wasnt already in', function(){
ionic.Platform.setPlatform('ios');
var originalViewport = ' initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width ';
vportTag.setAttribute('content', originalViewport);
it('Should keep width but replace height=device-height with height=0 in viewport for iOS 6.1, iPhone, WebView', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.1');
window.cordova = {};
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
// if it was changed the spaces would have been removed
expect( vportTag.content ).toEqual(originalViewport);
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
it('Should set height=0 if browser and height=device-height was already in', function(){
ionic.Platform.setPlatform('ios');
var originalViewport = 'initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=device-height';
vportTag.setAttribute('content', originalViewport);
// iOS 6.1, iPhone, Browser
it('Should add width but not height to viewport for iOS 6.1, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.1');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
// if it was changed the spaces would have been removed
expect( vportTag.content ).toEqual('initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, height=0');
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should keep width but remove height from viewport for iOS 6.1, iPhone, Browser', function(){
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('6.1');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');
});
// Android 4.4, WebView
it('Should add width, but not height to viewport for Android 4.4, WebView', function(){
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4');
window.cordova = {};
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should keep width, but remove height from viewport for Android 4.4, WebView', function(){
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4');
window.cordova = {};
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
// Android 4.4, Browser
it('Should add width, but not height to viewport for Android 4.4, Browser', function(){
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4');
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should keep width, but remove height from viewport for Android 4.4, Browser', function(){
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
// Standard Browser
it('Should add width, but not height to viewport for Standard Browser', function(){
ionic.Platform.ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';
vportTag.content = 'user-scalable=no';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should keep width, but remove height from viewport for Standard Browser', function(){
ionic.Platform.setPlatform('android');
ionic.Platform.setVersion('4.4');
vportTag.content = 'user-scalable=no, width=device-width, height=device-height';
viewportLoadTag();
expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');
});
it('Should get portrait (0) orientation', function(){
window.innerWidth = 768;
window.innerHeight = 1024;
expect( ionic.viewport.orientation() ).toEqual(0);
window.innerWidth = 500;
window.innerHeight = 500;
expect( ionic.viewport.orientation() ).toEqual(0);
});
it('Should get landscape (90) orientation', function(){
window.innerWidth = 1024;
window.innerHeight = 768;
expect( ionic.viewport.orientation() ).toEqual(90);
});
});

View File

@@ -37,19 +37,20 @@ describe('Scroll View', function() {
it('Should resize when the keyboard is showing', function() {
var element = document.createElement('textarea');
ionic.Platform.setPlatform('ios');
s.appendChild(element);
document.body.appendChild(sc);
var sv = new ionic.views.Scroll({
el: sc,
});
var scHeight = 500;
sc.style.height = scHeight + "px";
sc.style.display = "block";
var keyboardHeight = 200;
details = {
details = {
contentHeight: 260,
elementBottom: 400,
elementTop: 300,