2018-10-18 13:59:27 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-10-18 13:59:27 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2019-01-29 15:42:27 +00:00
|
|
|
var CONST = require('../scale/const');
|
2019-01-11 18:00:02 +00:00
|
|
|
|
2019-01-11 12:12:43 +00:00
|
|
|
var GetScreenOrientation = function (width, height)
|
2018-10-18 13:59:27 +00:00
|
|
|
{
|
|
|
|
var screen = window.screen;
|
2019-01-11 12:12:43 +00:00
|
|
|
var orientation = (screen) ? screen.orientation || screen.mozOrientation || screen.msOrientation : false;
|
2018-10-18 13:59:27 +00:00
|
|
|
|
|
|
|
if (orientation && typeof orientation.type === 'string')
|
|
|
|
{
|
|
|
|
// Screen Orientation API specification
|
|
|
|
return orientation.type;
|
|
|
|
}
|
|
|
|
else if (typeof orientation === 'string')
|
|
|
|
{
|
|
|
|
// moz / ms-orientation are strings
|
|
|
|
return orientation;
|
|
|
|
}
|
2019-01-29 15:42:27 +00:00
|
|
|
|
2019-01-11 12:12:43 +00:00
|
|
|
if (screen)
|
2018-10-18 13:59:27 +00:00
|
|
|
{
|
2019-01-11 18:00:02 +00:00
|
|
|
return (screen.height > screen.width) ? CONST.PORTRAIT : CONST.LANDSCAPE;
|
2018-10-18 13:59:27 +00:00
|
|
|
}
|
2019-01-11 12:12:43 +00:00
|
|
|
else if (typeof window.orientation === 'number')
|
2018-10-18 13:59:27 +00:00
|
|
|
{
|
|
|
|
// This may change by device based on "natural" orientation.
|
2019-01-11 18:00:02 +00:00
|
|
|
return (window.orientation === 0 || window.orientation === 180) ? CONST.PORTRAIT : CONST.LANDSCAPE;
|
2018-10-18 13:59:27 +00:00
|
|
|
}
|
|
|
|
else if (window.matchMedia)
|
|
|
|
{
|
|
|
|
if (window.matchMedia('(orientation: portrait)').matches)
|
|
|
|
{
|
2019-01-11 18:00:02 +00:00
|
|
|
return CONST.PORTRAIT;
|
2018-10-18 13:59:27 +00:00
|
|
|
}
|
|
|
|
else if (window.matchMedia('(orientation: landscape)').matches)
|
|
|
|
{
|
2019-01-11 18:00:02 +00:00
|
|
|
return CONST.LANDSCAPE;
|
2018-10-18 13:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 12:12:43 +00:00
|
|
|
|
2019-01-11 18:00:02 +00:00
|
|
|
return (height > width) ? CONST.PORTRAIT : CONST.LANDSCAPE;
|
2018-10-18 13:59:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetScreenOrientation;
|