Files
bulma/docs/_javascript/index.js

133 lines
3.7 KiB
JavaScript
Raw Normal View History

2024-01-11 03:58:20 +00:00
document.addEventListener("DOMContentLoaded", () => {
2017-10-10 17:48:01 +01:00
// Intro
2024-01-11 03:58:20 +00:00
const introVideo = document.getElementById("introVideo");
const introIframe = document.getElementById("introIframe");
const npmClipboard = new Clipboard("#npmCopy");
2017-10-10 17:48:01 +01:00
if (window.Vimeo) {
const introPlayer = new Vimeo.Player(introIframe);
2024-01-11 03:58:20 +00:00
introPlayer.ready().then(function () {
introVideo.classList.add("has-loaded");
});
}
2017-10-10 17:48:01 +01:00
2024-01-11 03:58:20 +00:00
npmClipboard.on("success", function (e) {
e.trigger.innerText = "copied!";
e.trigger.classList.add("is-success");
2017-10-10 17:48:01 +01:00
setTimeout(() => {
2024-01-11 03:58:20 +00:00
e.trigger.innerText = "copy";
e.trigger.classList.remove("is-success");
2017-10-10 17:48:01 +01:00
}, 500);
e.clearSelection();
});
2024-01-11 03:58:20 +00:00
npmClipboard.on("error", function (e) {
e.trigger.innerText = "error!";
e.trigger.classList.add("is-error");
2017-10-10 17:48:01 +01:00
setTimeout(() => {
2024-01-11 03:58:20 +00:00
e.trigger.innerText = "copy";
e.trigger.classList.remove("is-error");
2017-10-10 17:48:01 +01:00
}, 500);
});
// Grid
2024-01-11 03:58:20 +00:00
const $grid = document.getElementById("grid");
const $columns = Array.prototype.slice.call(
document.querySelectorAll("#grid > .column"),
0
);
const $markup = document.querySelector("#markup code");
const $message = document.getElementById("message");
const $add = document.getElementById("add");
const $remove = document.getElementById("remove");
2017-07-01 18:30:39 +01:00
let showing = 5;
function showColumns() {
if (showing === 13) {
2024-01-11 03:58:20 +00:00
$message.style.display = "block";
2017-07-01 18:30:39 +01:00
} else {
2024-01-11 03:58:20 +00:00
$message.style.display = "none";
2017-07-01 18:30:39 +01:00
}
2018-04-10 12:26:37 +01:00
showing = Math.min(Math.max(parseInt(showing), 1), 12);
2017-07-01 18:30:39 +01:00
2024-01-11 03:58:20 +00:00
$columns.forEach(($el) => {
$el.style.display = "none";
2017-07-01 18:30:39 +01:00
});
2024-01-11 03:58:20 +00:00
$columns.slice(0, showing).forEach(($el) => {
$el.style.display = "block";
2017-07-01 18:30:39 +01:00
});
2024-01-11 03:58:20 +00:00
$markup.innerHTML =
'<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;columns&quot;</span><span class="nt">&gt;</span>';
$markup.insertAdjacentHTML("beforeend", "\n");
for (let i = 0; i < showing; i++) {
$markup.insertAdjacentHTML(
"beforeend",
' <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;column&quot;</span><span class="nt">&gt;</span>'
);
$markup.insertAdjacentHTML("beforeend", i + 1);
$markup.insertAdjacentHTML(
"beforeend",
'<span class="nt">&lt;/div&gt;</span>'
);
$markup.insertAdjacentHTML("beforeend", "\n");
2017-07-01 18:30:39 +01:00
}
2024-01-11 03:58:20 +00:00
$markup.insertAdjacentHTML(
"beforeend",
'<span class="nt">&lt;/div&gt;</span>'
);
2017-07-01 18:30:39 +01:00
}
2024-01-11 03:58:20 +00:00
$add.addEventListener("click", () => {
2017-07-01 18:30:39 +01:00
showing++;
showColumns();
});
2024-01-11 03:58:20 +00:00
$remove.addEventListener("click", () => {
2017-07-01 18:30:39 +01:00
showing--;
showColumns();
});
2024-01-11 03:58:20 +00:00
// Amis
const $amis = document.getElementById("amis");
2024-01-19 13:39:17 +00:00
const $pied = document.getElementById("pied");
2024-01-11 03:58:20 +00:00
2024-01-11 21:17:22 +00:00
if ($amis) {
fetch("https://jgthms.com/amis/new.json")
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then((response) => {
response.forEach((item) => {
const el = document.createElement("a");
el.className = "bd-sponsor-item bd-partner-sponsor";
2024-01-19 13:39:17 +00:00
el.href = item.url;
2024-01-11 21:17:22 +00:00
el.target = "_blank";
el.title = item.title || item.id;
const extension = item.svg ? ".svg" : ".png";
const img = document.createElement("img");
img.src = `https://jgthms.com/amis/images/${item.id}${extension}`;
el.appendChild(img);
$amis.appendChild(el);
2024-01-19 13:39:17 +00:00
if (item.pied && $pied) {
el.className = "bd-sponsor-item bd-footer-sponsor";
$pied.appendChild(el);
}
2024-01-11 21:17:22 +00:00
});
2024-01-11 03:58:20 +00:00
});
2024-01-11 12:57:09 +00:00
}
2017-07-01 18:30:39 +01:00
});