Runway 1.1.0
This commit is contained in:
1 parent
ce217fc952
commit
07d5bd7e9a
223 files changed
+21147
-255
No files matched your search
@@ -0,0 +1,10 @@
|
||||
/* Runway demo — guestbook. Plain, so it sits in any site's design. */
|
||||
.rw-guestbook form { display: grid; gap: .4rem; max-width: 36rem; margin: 0 0 1.5rem; }
|
||||
.rw-guestbook input, .rw-guestbook textarea { font: inherit; padding: .4rem; }
|
||||
.rw-guestbook button { justify-self: start; padding: .4rem 1rem; font: inherit; cursor: pointer; }
|
||||
.rw-guestbook-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
|
||||
.rw-guestbook-notice { padding: .5rem .75rem; border-left: 3px solid currentColor; }
|
||||
.rw-guestbook-list { list-style: none; padding: 0; margin: 0; }
|
||||
.rw-guestbook-list li { padding: .6rem 0; border-top: 1px solid rgba(127, 127, 127, .25); }
|
||||
.rw-guestbook-list time { opacity: .7; font-size: .875em; }
|
||||
.rw-guestbook-list p { margin: .25rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
@@ -0,0 +1,65 @@
|
||||
// Runway demo — guestbook list. Fills each .rw-guestbook-list from its data-src endpoint (never cached), a page at a
|
||||
// time. Entries are inserted as text, never as HTML.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function item(entry, lang) {
|
||||
var li = document.createElement("li");
|
||||
var who = document.createElement("strong");
|
||||
who.textContent = entry.name;
|
||||
var when = document.createElement("time");
|
||||
when.dateTime = entry.at;
|
||||
when.textContent = new Date(entry.at).toLocaleString(lang || undefined);
|
||||
var text = document.createElement("p");
|
||||
text.textContent = entry.message;
|
||||
li.appendChild(who);
|
||||
li.appendChild(document.createTextNode(" "));
|
||||
li.appendChild(when);
|
||||
li.appendChild(text);
|
||||
return li;
|
||||
}
|
||||
|
||||
function note(list, message) {
|
||||
var li = document.createElement("li");
|
||||
li.className = "rw-guestbook-empty";
|
||||
li.textContent = message;
|
||||
list.appendChild(li);
|
||||
}
|
||||
|
||||
function load(list, page) {
|
||||
var url = list.dataset.src + "?page=" + page;
|
||||
fetch(url, { credentials: "same-origin", cache: "no-store" })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
var old = list.querySelector(".rw-guestbook-more");
|
||||
if (old) { old.remove(); }
|
||||
if (!data.available) { note(list, list.dataset.unavailable); return; }
|
||||
if (page === 0 && data.entries.length === 0) { note(list, list.dataset.empty); return; }
|
||||
data.entries.forEach(function (e) { list.appendChild(item(e, list.dataset.lang)); });
|
||||
if (data.more) {
|
||||
var li = document.createElement("li");
|
||||
li.className = "rw-guestbook-more";
|
||||
var button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.textContent = list.dataset.more;
|
||||
button.addEventListener("click", function () { load(list, page + 1); });
|
||||
li.appendChild(button);
|
||||
list.appendChild(li);
|
||||
}
|
||||
})
|
||||
.catch(function () { note(list, list.dataset.unavailable); });
|
||||
}
|
||||
|
||||
function start() {
|
||||
document.querySelectorAll(".rw-guestbook-list:not([data-loaded])").forEach(function (list) {
|
||||
list.dataset.loaded = "1";
|
||||
load(list, 0);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user