From 1ed694a80e5474e6ba9324d240a6dacbcd2108d1 Mon Sep 17 00:00:00 2001 From: gablaxy <32848524+gablaxy@users.noreply.github.com> Date: Thu, 16 Mar 2023 08:36:32 +0100 Subject: [PATCH] Add files via upload --- webring.js | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ webring.json | 12 +++++++++ 2 files changed, 81 insertions(+) create mode 100644 webring.js create mode 100644 webring.json 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