Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

card-boxes.html 3.7KB

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