Created
March 29, 2024 17:58
-
-
Save isao/e058d4bc113e13508e89d5e58d160ede to your computer and use it in GitHub Desktop.
Revisions
-
ceving revised this gist
Mar 27, 2024 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ Use the module. <script type="module" src="copyright-year.js"></script> ``` Use the Web Component with the attribute [`is`][1] ```html <span>© <span is="copyright-year">2023</span> Web Component Super Hero</span> @@ -40,3 +40,5 @@ or as a dedicated element. ```html <span>© <copyright-year>2023</copyright-year> Web Component Super Hero</span> ``` [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is -
ceving revised this gist
Mar 27, 2024 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,8 +29,14 @@ Use the module. <script type="module" src="copyright-year.js"></script> ``` Use the Web Component with the attribute `id` ```html <span>© <span is="copyright-year">2023</span> Web Component Super Hero</span> ``` or as a dedicated element. ```html <span>© <copyright-year>2023</copyright-year> Web Component Super Hero</span> ``` -
ceving created this gist
Mar 27, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ # Web Component for Copyright Years This Web Components keeps the year in your copyright notice up-to-date. ```javascript export { CopyrightYearElement } const name = "copyright-year"; class CopyrightYearElement extends HTMLSpanElement { constructor() { super(); } connectedCallback() { const year = new Date().getFullYear(); const shadow = this.attachShadow({ mode: "open" }); const span = document.createElement("span"); span.appendChild(document.createTextNode(`${this.textContent} - ${year}`)); shadow.appendChild(span); } } customElements.define(name, CopyrightYearElement, {extends: 'span'}); ``` Use the module. ```html <script type="module" src="copyright-year.js"></script> ``` Use the Web Component. ```html <span>© <span is="copyright-year">2023</span> Web Component Super Hero</span> ```