浏览代码

messing around

crobi 10 年前
父节点
当前提交
8c630cc157
共有 2 个文件被更改,包括 35 次插入32 次删除
  1. 32
    29
      generator/components/card-front.html
  2. 3
    3
      generator/components/card-title.html

+ 32
- 29
generator/components/card-front.html 查看文件

@@ -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>

+ 3
- 3
generator/components/card-title.html 查看文件

@@ -64,7 +64,7 @@
64 64
                 if (value > 16) value = 16;
65 65
                 if (value < 10) value = 10;
66 66
                 var root = this.shadowRoot;
67
-                root.querySelector("#title").className = "title-" + value;
67
+                root.getElementById("title").className = "title-" + value;
68 68
             }
69 69
         });
70 70
         proto.createdCallback = function () {
@@ -75,9 +75,9 @@
75 75
 
76 76
             this.size = this.getAttribute('size') || 13;
77 77
         }
78
-        proto.attributeChangedCallback = function (name, value) {
78
+        proto.attributeChangedCallback = function (name, oldValue, newValue) {
79 79
             switch (name) {
80
-                case "size": this.size = value;
80
+                case "size": this.size = newValue;
81 81
             }
82 82
         }
83 83
 

正在加载...
取消
保存