-
Notifications
You must be signed in to change notification settings - Fork 1
/
mwc-layout.html
113 lines (87 loc) · 2.56 KB
/
mwc-layout.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<dom-module id="mwc-layout">
<template>
<style>
:host {
display: none!important;
}
:host([active]) {
display: block!important;
}
</style>
<content class="mwc-layout" select="*"></content>
</template>
<script>
// HTMLImports.whenReady(function() {
Polymer({
activeChange: function(newValue, oldValue) {
if (newValue === false && oldValue === true) {
var region = Object.keys(this.opt);
for (var A = 0; A < region.length; A++) {
var element = this.querySelectorAll('*[region="' + region[A] + '"]');
for (Z = 0; Z < element.length; Z++) {
element[Z].innerHTML = "";
}
}
}
},
is: "mwc-layout",
properties: {
active: {
notify: true,
observer: "activeChange",
reflectToAttribute: true,
type: Boolean,
value: false
},
opt: {
type: Object
}
},
render: function(opt) {
var region = Object.keys(opt);
for (var A = 0; A < region.length; A++) {
if (typeof(opt[region[A]]) === "object") {
var element = this.querySelectorAll('*[region="' + region[A] + '"]');
for (Z = 0; Z < element.length; Z++) {
element[Z].innerHTML = "";
Polymer.dom(element[Z]).appendChild(opt[region[A]]);
}
} else {
if (document.createElement(opt[region[A]]).constructor !== HTMLElement) {
var element = this.querySelectorAll('*[region="' + region[A] + '"]');
for (Z = 0; Z < element.length; Z++) {
element[Z].innerHTML = "";
Polymer.dom(element[Z]).appendChild(document.createElement(opt[region[A]]));
}
} else {
console.log(opt[region[A]] + " not registered");
}
}
}
this.opt = opt;
}
});
// });
</script>
</dom-module>
<script>
var PolymerLayout = function() {
this.currentLayout = null;
};
// layout[String]
// opt[Object] one-level deep
// forceRender[Boolean]
PolymerLayout.prototype.render = function(layout, opt, forceRender) {
if (document.querySelector('mwc-layout[id="' + layout + '"]')) {
if (this.currentLayout != layout || forceRender) {
if (this.currentLayout) {
document.querySelector('mwc-layout[id="' + this.currentLayout + '"]').active = false
}
document.querySelector('mwc-layout[id="' + layout + '"]').render(Object.prototype.toString.call(opt) == "[object Object]" ? opt : {});
document.querySelector('mwc-layout[id="' + layout + '"]').active = true;
this.currentLayout = layout;
}
}
};
mwcLayout = new PolymerLayout();
</script>