Skip to content

Commit 98d0ae6

Browse files
committed
Moved iOS GetInnerHeight to its own function
1 parent 83752c9 commit 98d0ae6

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/dom/GetInnerHeight.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var GetInnerHeight = function (iOS)
8+
{
9+
// Based on code by @tylerjpeterson
10+
11+
if (!iOS)
12+
{
13+
return window.innerHeight;
14+
}
15+
16+
var axis = Math.abs(window.orientation);
17+
18+
var size = { w: 0, h: 0 };
19+
20+
var ruler = document.createElement('div');
21+
22+
ruler.setAttribute('style', 'position: fixed; height: 100vh; width: 0; top: 0');
23+
24+
document.documentElement.appendChild(ruler);
25+
26+
size.w = (axis === 90) ? ruler.offsetHeight : window.innerWidth;
27+
size.h = (axis === 90) ? window.innerWidth : ruler.offsetHeight;
28+
29+
document.documentElement.removeChild(ruler);
30+
31+
ruler = null;
32+
33+
if (Math.abs(window.orientation) !== 90)
34+
{
35+
return size.h;
36+
}
37+
else
38+
{
39+
return size.w;
40+
}
41+
};
42+
43+
module.exports = GetInnerHeight;

0 commit comments

Comments
 (0)