bulma/docs/lib/index.js

122 lines
3.6 KiB
JavaScript
Raw Normal View History

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