commit 1ed694a80e5474e6ba9324d240a6dacbcd2108d1
Author: gablaxy <32848524+gablaxy@users.noreply.github.com>
Date: Thu Mar 16 08:36:32 2023 +0100
Add files via upload
diff --git a/webring.js b/webring.js
new file mode 100644
index 0000000..56d5c8d
--- /dev/null
+++ b/webring.js
@@ -0,0 +1,69 @@
+const JSON_WEBRING = "https://gablaxy.github.io/webring.json";
+
+const template = document.createElement("template");
+template.innerHTML = `
+
+
+
+
+
+
+
+`;
+
+class Webring extends HTMLElement {
+ connectedCallback() {
+
+ this.attachShadow({ mode: "open" });
+
+ this.shadowRoot.appendChild(template.content.cloneNode(true));
+
+ const currentSite = this.getAttribute("site");
+ // ou sinon on peut aller chercher le paramètre site dans la déclaration du widget
+
+ fetch(JSON_WEBRING)
+ .then((response) => response.json())
+ .then((sites) => {
+ // Va chercher les infos du site actuel dans le json
+ const matchedSiteIndex = sites.findIndex(
+ (site) => site.url === currentSite
+ )
+
+ // stocke les index des sites avant et après dans le json
+ let previousSiteIndex = matchedSiteIndex - 1;
+ if(previousSiteIndex < 0)previousSiteIndex = sites.length - 1;
+
+ let nextSiteIndex = matchedSiteIndex + 1;
+ if(nextSiteIndex >= sites.length)nextSiteIndex = 0;
+
+
+ const content = `
+ < avant
+ /
+ ${sites[matchedSiteIndex].name}
+ /
+ après >
+ `;
+
+ this.shadowRoot
+ .querySelector("#webring-inner")
+ .insertAdjacentHTML("afterbegin", content);
+ });
+ }
+}
+
+window.customElements.define("webring-iutechno", Webring);
\ No newline at end of file
diff --git a/webring.json b/webring.json
new file mode 100644
index 0000000..c4bab32
--- /dev/null
+++ b/webring.json
@@ -0,0 +1,12 @@
+[
+ {
+ "name": "gablaxy",
+ "url": "https://gabinlavazais.fr"
+ },{
+ "name": "HUB",
+ "url": "https://gablaxy.github.io"
+ },{
+ "name": "github",
+ "url": "https://test.com"
+ }
+]
\ No newline at end of file