|
@@ -0,0 +1,131 @@
|
|
1
|
+<template id="card-box">
|
|
2
|
+ <style>
|
|
3
|
+ :host {
|
|
4
|
+ display: inline-block;
|
|
5
|
+ vertical-align: top;
|
|
6
|
+ }
|
|
7
|
+ .box {
|
|
8
|
+ width: 100%;
|
|
9
|
+ height: 100%;
|
|
10
|
+ border: 2px solid;
|
|
11
|
+ box-sizing: border-box;
|
|
12
|
+ vertical-align: middle;
|
|
13
|
+ text-align: center;
|
|
14
|
+ display: flex;
|
|
15
|
+ justify-content: center;
|
|
16
|
+ align-content: center;
|
|
17
|
+ flex-direction: column;
|
|
18
|
+ }
|
|
19
|
+ #box2 {
|
|
20
|
+ display: flex;
|
|
21
|
+ justify-content: center;
|
|
22
|
+ align-content: center;
|
|
23
|
+ flex-direction: row;
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ </style>
|
|
27
|
+ <div class="box">
|
|
28
|
+ <div id="box2">
|
|
29
|
+ <content></content>
|
|
30
|
+ </div>
|
|
31
|
+ </div>
|
|
32
|
+</template>
|
|
33
|
+
|
|
34
|
+<template id="card-boxes">
|
|
35
|
+ <style>
|
|
36
|
+ :host {
|
|
37
|
+ width: 100%;
|
|
38
|
+ vertical-align: top;
|
|
39
|
+ }
|
|
40
|
+ ::content card-box + card-box {
|
|
41
|
+ padding-left: 2px;
|
|
42
|
+ }
|
|
43
|
+ </style>
|
|
44
|
+
|
|
45
|
+ <style id="box-size">
|
|
46
|
+ ::content card-box {
|
|
47
|
+ width:2.5em;
|
|
48
|
+ height:2.5em;
|
|
49
|
+ }
|
|
50
|
+ </style>
|
|
51
|
+
|
|
52
|
+ <content></content>
|
|
53
|
+
|
|
54
|
+</template>
|
|
55
|
+
|
|
56
|
+<script>
|
|
57
|
+ (function (window, document) {
|
|
58
|
+ var elemName = 'card-box';
|
|
59
|
+ var mainDoc = document;
|
|
60
|
+ var importDoc = document.currentScript.ownerDocument;
|
|
61
|
+
|
|
62
|
+ var proto = Object.create(HTMLElement.prototype);
|
|
63
|
+ proto.createdCallback = function () {
|
|
64
|
+ var template = importDoc.getElementById(elemName);
|
|
65
|
+ var clone = mainDoc.importNode(template.content, true);
|
|
66
|
+ var root = this.createShadowRoot();
|
|
67
|
+ root.appendChild(clone);
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ mainDoc.registerElement(elemName, { prototype: proto });
|
|
71
|
+
|
|
72
|
+ })(window, document);
|
|
73
|
+
|
|
74
|
+ (function(window, document) {
|
|
75
|
+ var elemName = 'card-boxes';
|
|
76
|
+ var mainDoc = document;
|
|
77
|
+ var importDoc = document.currentScript.ownerDocument;
|
|
78
|
+
|
|
79
|
+ function createBoxes(element, count) {
|
|
80
|
+ while (element.firstChild) {
|
|
81
|
+ element.removeChild(element.firstChild);
|
|
82
|
+ }
|
|
83
|
+ for (var i = 0; i < count; ++i) {
|
|
84
|
+ element.appendChild(document.createElement("card-box"));
|
|
85
|
+ }
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ var proto = Object.create(HTMLElement.prototype);
|
|
89
|
+ Object.defineProperty(proto, "size", {
|
|
90
|
+ get: function () {
|
|
91
|
+ return "";
|
|
92
|
+ },
|
|
93
|
+ set: function (value) {
|
|
94
|
+ var root = this.shadowRoot;
|
|
95
|
+ var style = root.getElementById("box-size");
|
|
96
|
+ style.innerHTML = "\
|
|
97
|
+ ::content card-box {\
|
|
98
|
+ width:" + value + "em;\
|
|
99
|
+ height:" + value + "em;\
|
|
100
|
+ }\
|
|
101
|
+ ";
|
|
102
|
+ }
|
|
103
|
+ });
|
|
104
|
+ Object.defineProperty(proto, "count", {
|
|
105
|
+ get: function () {
|
|
106
|
+ return "";
|
|
107
|
+ },
|
|
108
|
+ set: function (value) {
|
|
109
|
+ createBoxes(this, value);
|
|
110
|
+ }
|
|
111
|
+ });
|
|
112
|
+ proto.createdCallback = function () {
|
|
113
|
+ var template = importDoc.getElementById(elemName);
|
|
114
|
+ var clone = mainDoc.importNode(template.content, true);
|
|
115
|
+ var root = this.createShadowRoot();
|
|
116
|
+ root.appendChild(clone);
|
|
117
|
+
|
|
118
|
+ this.size = this.getAttribute('size') || "1";
|
|
119
|
+ this.count = this.getAttribute('count') || "1";
|
|
120
|
+ }
|
|
121
|
+ proto.attributeChangedCallback = function (name, oldValue, newValue) {
|
|
122
|
+ switch (name) {
|
|
123
|
+ case "size": this.size = newValue; break;
|
|
124
|
+ case "count": this.count = newValue; break;
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ mainDoc.registerElement(elemName, { prototype: proto });
|
|
129
|
+
|
|
130
|
+ })(window, document);
|
|
131
|
+</script>
|