Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template id="card-icon">
  2. <style>
  3. #icon-container {
  4. height: 100%;
  5. background-color: inherit;
  6. }
  7. svg {
  8. height: 100%;
  9. }
  10. svg path {
  11. fill: rgb(255, 255, 255);
  12. }
  13. </style>
  14. <div id="icon-container">
  15. </div>
  16. </template>
  17. <script>
  18. (function(window, document) {
  19. var elemName = 'card-icon';
  20. var mainDoc = document;
  21. var importDoc = document.currentScript.ownerDocument;
  22. var proto = Object.create(HTMLDivElement.prototype);
  23. proto.loadSvg = function (src, callback) {
  24. var isLocal = window.location.protocol === 'file:';
  25. var httpRequest = new XMLHttpRequest();
  26. httpRequest.onreadystatechange = function () {
  27. if (httpRequest.readyState === 4) {
  28. if (httpRequest.status === 404 || httpRequest.responseXML === null) {
  29. throw new Error("Error loading SVG");
  30. }
  31. if (httpRequest.status === 200 || (isLocal && httpRequest.status === 0)) {
  32. if (httpRequest.responseXML instanceof Document) {
  33. callback(httpRequest.responseXML.children[0]);
  34. }
  35. }
  36. }
  37. }
  38. httpRequest.open('GET', src);
  39. if (httpRequest.overrideMimeType) httpRequest.overrideMimeType('text/xml');
  40. httpRequest.send();
  41. }
  42. Object.defineProperty(proto, "src", {
  43. get: function() {
  44. return "";
  45. },
  46. set: function (value) {
  47. this.setAttribute('src', value);
  48. var root = this.shadowRoot;
  49. var container = root.getElementById("icon-container");
  50. while (container.firstChild) {
  51. container.removeChild(container.firstChild);
  52. }
  53. this.loadSvg(value, function (svg) {
  54. container.appendChild(svg);
  55. // game-icons.net specific modifications
  56. var firstPath = root.querySelector("svg path");
  57. svg.removeChild(firstPath);
  58. var secondPath = root.querySelector("svg path");
  59. secondPath.style.fill = "";
  60. });
  61. }
  62. });
  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. this.src = this.getAttribute('src') || "";
  69. }
  70. proto.attributeChangedCallback = function (name, oldValue, newValue) {
  71. switch (name) {
  72. case "src": this.src = newValue; break;
  73. }
  74. }
  75. mainDoc.registerElement(elemName, { prototype: proto });
  76. })(window, document);
  77. </script>