-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
83 lines (70 loc) · 2.37 KB
/
Copy pathconfig.js
File metadata and controls
83 lines (70 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* =========================================================================
Site configuration. Values used across the page in one place.
========================================================================= */
const SITE = {
/* Commercial product name. */
BRAND: "Oxpull",
/* Open source package name, as installed with pip. */
PACKAGE: "django-ox",
/* Where the waitlist form posts. */
FORM_ENDPOINT: "https://formspree.io/f/mvkpbwwn",
};
/* ====================== plumbing, no config below ====================== */
(function () {
"use strict";
function applyBrand() {
document.querySelectorAll("[data-brand]").forEach(function (el) {
el.textContent = SITE.BRAND;
});
document.querySelectorAll("[data-package]").forEach(function (el) {
el.textContent = SITE.PACKAGE;
});
document.title = document.title.split("[BRAND]").join(SITE.BRAND);
}
function wireForm() {
var form = document.getElementById("waitlist-form");
if (!form) return;
var button = form.querySelector("button[type=submit]");
var errorBox = document.getElementById("form-error");
/* Native fallback: with JS on but fetch failing, or JS off entirely
once the attribute is in the HTML, the form still posts here. */
if (SITE.FORM_ENDPOINT) form.setAttribute("action", SITE.FORM_ENDPOINT);
form.addEventListener("submit", function (ev) {
ev.preventDefault();
errorBox.hidden = true;
/* No endpoint configured: local preview mode. */
if (!SITE.FORM_ENDPOINT) {
window.location.href = "thanks.html";
return;
}
button.disabled = true;
button.textContent = "Joining…";
fetch(SITE.FORM_ENDPOINT, {
method: "POST",
body: new FormData(form),
headers: { Accept: "application/json" },
})
.then(function (res) {
if (res.ok) {
window.location.href = "thanks.html";
} else {
throw new Error("HTTP " + res.status);
}
})
.catch(function () {
button.disabled = false;
button.textContent = "Join the waitlist";
errorBox.hidden = false;
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function () {
applyBrand();
wireForm();
});
} else {
applyBrand();
wireForm();
}
})();