This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreen.js
69 lines (62 loc) · 1.65 KB
/
Screen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var isPlask = require('is-plask');
var plask = require('plask-wrap')
/**
* Singleton for retrieving information about available screens / displays
*/
var Screen = {
/**
* @return {Number} number of screens
*/
getNumScreens: function() {
if (isPlask) {
return plask.Window.screensInfo().length;
}
else {
return 1;
}
return this._screens;
},
/**
*
* @param {Number} screenId - id of the screen we query about
* @return {Number} - width of the given screen in px
*/
getWidth: function(screenId) {
screenId = screenId || 0;
if (isPlask) {
return plask.Window.screensInfo()[screenId].width;
}
else {
return window.innerWidth;
}
},
/**
*
* @param {Number} screenId - id of the screen we query about
* @return {Number} - height of the given screen in px
*/
getHeight: function(screenId) {
screenId = screenId || 0;
if (isPlask) {
return plask.Window.screensInfo()[screenId].height;
}
else {
return window.innerHeight;
}
},
/**
*
* @param {Number} screenId - id of the screen we query about
* @return {Number} - device pixel ratio of the given screen (e.g. 2 for retina)
*/
getDevicePixelRatio: function(screenId) {
screenId = screenId || 0;
if (isPlask) {
return plask.Window.screensInfo()[screenId].highdpi;
}
else {
return window.devicePixelRatio;
}
}
};
module.exports = Screen;