설명 없음
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.

card-icon.html 2.9KB

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