Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpg-card.html 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <link href='http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
  2. <template id="rpg-card">
  3. <style type='text/css'>
  4. :host {
  5. /* Border */
  6. padding: 6px;
  7. border-radius: 4px;
  8. box-sizing: border-box;
  9. /* Flex display of children */
  10. position: relative;
  11. display: flex;
  12. flex-direction: column;
  13. /* Font */
  14. font-family: 'Noto Sans', 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
  15. font-size: 8pt;
  16. }
  17. ::content > card-title:first-child {
  18. margin-top: -2px;
  19. margin-bottom: 4px;
  20. }
  21. ::content > card-title:last-child {
  22. margin-top: 4px;
  23. margin-bottom: -2px;
  24. }
  25. </style>
  26. <style type='text/css' id="color-style">
  27. </style>
  28. <style type='text/css' id="card-size">
  29. :host{width: 2.5in;height: 3.5in;}
  30. </style>
  31. <content></content>
  32. </template>
  33. <script>
  34. (function (window, document) {
  35. var elemName = 'rpg-card';
  36. var mainDoc = document;
  37. var importDoc = document.currentScript.ownerDocument;
  38. var proto = Object.create(HTMLDivElement.prototype);
  39. Object.defineProperty(proto, "color", {
  40. get: function () {
  41. return "";
  42. },
  43. set: function (value) {
  44. var root = this.shadowRoot;
  45. var style = root.getElementById("color-style");
  46. style.innerHTML = "\
  47. :host {\
  48. color: "+value+";\
  49. background-color: " + value + ";\
  50. border-color: " + value + ";\
  51. }\
  52. ::content card-rule /deep/ svg {\
  53. fill: " + value + ";\
  54. }\
  55. ::content card-boxes /deep/ svg rect {\
  56. stroke: " + value + ";\
  57. }\
  58. ::content card-icon {\
  59. background-color: " + value + ";\
  60. }\
  61. ::content card-back /deep/ #outer {\
  62. background: radial-gradient(ellipse at center, white 20%, " + value + " 120%);\
  63. }\
  64. ";
  65. }
  66. });
  67. Object.defineProperty(proto, "size", {
  68. get: function () {
  69. return "";
  70. },
  71. set: function (value) {
  72. var root = this.shadowRoot;
  73. var style = root.getElementById("card-size");
  74. switch (value) {
  75. case "full": style.innerHTML = ":host{width:100%;height:100%;}"; break;
  76. case "25x35": style.innerHTML = ":host{width: 2.5in;height: 3.5in;}"; break;
  77. case "225x35": style.innerHTML = ":host{width: 2.25in;height: 3.5in;}"; break;
  78. case "25x50": style.innerHTML = ":host{width: 2.5in;height: 5.0in;}"; break;
  79. case "35x50": style.innerHTML = ":host{width: 3.5in;height: 5.0in;}"; break;
  80. case "75x50": style.innerHTML = ":host{width: 7.5in;height: 5.0in;}"; break;
  81. }
  82. }
  83. });
  84. proto.createdCallback = function () {
  85. var template = importDoc.getElementById(elemName);
  86. var clone = mainDoc.importNode(template.content, true);
  87. var root = this.createShadowRoot();
  88. root.appendChild(clone);
  89. this.color = this.getAttribute('color') || "black";
  90. this.size = this.getAttribute('size') || "25x35";
  91. }
  92. proto.attributeChangedCallback = function (name, oldValue, newValue) {
  93. switch (name) {
  94. case "color": this.color = newValue; break;
  95. case "size": this.size = newValue; break;
  96. }
  97. }
  98. mainDoc.registerElement(elemName, { prototype: proto });
  99. })(window, document);
  100. </script>