-
Notifications
You must be signed in to change notification settings - Fork 1
/
mwc_layout.html
86 lines (66 loc) · 1.9 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
<dom-module id="mwc-layout">
<template>
<style>
:host {
display: none!important;
}
:host([active]) {
display: block!important;
}
</style>
<content class="mwc-layout" select="*"></content>
</template>
</dom-module>
<script>
document.addEventListener("WebComponentsReady", 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>