-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcosmoz-viewinfo-mixin.js
More file actions
76 lines (71 loc) · 1.45 KB
/
Copy pathcosmoz-viewinfo-mixin.js
File metadata and controls
76 lines (71 loc) · 1.45 KB
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
72
73
74
75
76
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin';
const VIEW_INFO_INSTANCES = [],
SHARED_VIEW_INFO = {
desktop: false,
effects: 10,
height: 0,
landscape: false,
mobile: false,
portrait: true,
tablet: false,
width: 0
},
/**
* Mixin to inherit the viewInfo property with device and viewport info.
*
* @polymer
* @mixinFunction
*/
viewInfoAware = dedupingMixin(base =>
class extends base {
static get properties() {
return {
/**
* viewInfo object
* {
* desktop: Boolean,
* effects: Number (1-10),
* height: Number,
* landscape: Boolean,
* mobile: Boolean,
* portrait: Boolean,
* tablet: Boolean,
* width: Number
* }
*/
viewInfo: {
type: Object,
notify: true
}
};
}
/**
* Add to view info instances and set the shared view info to the view info.
*
* @returns {void}
*/
connectedCallback() {
super.connectedCallback();
VIEW_INFO_INSTANCES.push(this);
// Needed to make template views trigger on load and not only on resize
this.viewInfo = SHARED_VIEW_INFO;
}
/**
* Remove from view instances.
*
* @returns {void}
*/
disconnectedCallback() {
super.disconnectedCallback();
const i = VIEW_INFO_INSTANCES.indexOf(this);
if (i >= 0) {
VIEW_INFO_INSTANCES.splice(i, 1);
}
}
}
);
export {
VIEW_INFO_INSTANCES,
SHARED_VIEW_INFO,
viewInfoAware
};