|
@@ -69,36 +69,39 @@
|
69
|
69
|
</template>
|
70
|
70
|
|
71
|
71
|
<script>
|
72
|
|
-(function(window, document) {
|
73
|
|
- var elemName = 'card-front';
|
74
|
|
- var thatDoc = document;
|
75
|
|
- var thisDoc = (thatDoc.currentScript || thatDoc._currentScript).ownerDocument;
|
76
|
|
- var proto = Object.create(HTMLElement.prototype, {
|
77
|
|
- createdCallback: {
|
78
|
|
- value: function() {
|
79
|
|
- var template = thisDoc.getElementById(elemName);
|
80
|
|
- var clone = thatDoc.importNode(template.content, true);
|
81
|
|
- this.createShadowRoot().appendChild(clone);
|
82
|
|
- }
|
83
|
|
- },
|
84
|
|
- attachedCallback: {
|
85
|
|
- value: function () {
|
86
|
|
- var root = this.shadowRoot;
|
87
|
|
- var color = "black";
|
88
|
|
- for (var i = 0; i < this.attributes.length; i++) {
|
89
|
|
- var attribute = this.attributes[i];
|
90
|
|
- switch (attribute.name) {
|
91
|
|
- case "color": color = attribute.value;
|
92
|
|
- }
|
|
72
|
+ (function (window, document) {
|
|
73
|
+ var elemName = 'card-front';
|
|
74
|
+ var mainDoc = document;
|
|
75
|
+ var importDoc = document.currentScript.ownerDocument;
|
|
76
|
+
|
|
77
|
+ var proto = Object.create(HTMLElement.prototype);
|
|
78
|
+ Object.defineProperty(proto, "color", {
|
|
79
|
+ get: function () {
|
|
80
|
+ return "";
|
|
81
|
+ },
|
|
82
|
+ set: function (value) {
|
|
83
|
+ var root = this.shadowRoot;
|
|
84
|
+ var style = root.getElementById("card").style;
|
|
85
|
+ style.color = value;
|
|
86
|
+ style.backgroundColor = value;
|
|
87
|
+ style.borderColor = value;
|
93
|
88
|
}
|
|
89
|
+ });
|
|
90
|
+ proto.createdCallback = function () {
|
|
91
|
+ var template = importDoc.getElementById(elemName);
|
|
92
|
+ var clone = mainDoc.importNode(template.content, true);
|
|
93
|
+ var root = this.createShadowRoot();
|
|
94
|
+ root.appendChild(clone);
|
94
|
95
|
|
95
|
|
- var cardStyle = root.getElementById("card").style;
|
96
|
|
- cardStyle.color = color;
|
97
|
|
- cardStyle.backgroundColor = color;
|
98
|
|
- cardStyle.borderColor = color;
|
|
96
|
+ this.color = this.getAttribute('color') || "black";
|
|
97
|
+ }
|
|
98
|
+ proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
|
99
|
+ switch (name) {
|
|
100
|
+ case "color": this.color = newValue;
|
|
101
|
+ }
|
99
|
102
|
}
|
100
|
|
- }
|
101
|
|
- });
|
102
|
|
- thatDoc.registerElement(elemName, {prototype: proto});
|
103
|
|
-})(window, document);
|
|
103
|
+
|
|
104
|
+ mainDoc.registerElement(elemName, { prototype: proto });
|
|
105
|
+
|
|
106
|
+ })(window, document);
|
104
|
107
|
</script>
|