-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
71 lines (65 loc) · 1.58 KB
/
index.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
70
71
import Breakdancer from './breakdancer';
import get from 'propget';
/**
* Small fallback for when the `window` global is not accessible in a given
* environment. This allows the module to still be used in a regular `node`
* environment.
*
* @type {Object} Window reference or inner{height|width} polyfill.
* @private
*/
const win = typeof window !== 'undefined' ? window : {
innerWidth: 1280,
innerHeight: 768
};
/**
* Breakdancer is a simple breakpoint utility.
*
* @constructor
* @param {Object} specification Different breakpoints we need to know.
* @param {Object} windows Option window object reference.
* @public
*/
export default class WebDancer extends Breakdancer {
constructor(specification, windows) {
super(specification);
this.window = windows || win;
this.breakpoint = this.currently();
}
/**
* Return the current view port.
*
* @returns {Object} viewport
* @public
*/
viewport() {
return {
height: this.height(),
width: this.width()
};
}
/**
* Lookup the view port width.
*
* @returns {Number} Current width.
* @public
*/
width() {
return get(this.window, 'innerWidth')
|| get(this.window, 'document.documentElement.clientWidth')
|| get(this.window, 'document.body.clientWidth')
|| 0;
}
/**
* Lookup the view port height.
*
* @returns {Number} Current height.
* @public
*/
height() {
return get(this.window, 'innerHeight')
|| get(this.window, 'document.documentElement.clientHeight')
|| get(this.window, 'document.body.clientHeight')
|| 0;
}
}