-
Notifications
You must be signed in to change notification settings - Fork 97
/
sitewide.js
80 lines (63 loc) · 2.42 KB
/
sitewide.js
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
(function($){
if (!self.document) {
// We're in a service worker! Oh man, we’re living in the future! 🌈🦄
if (location.hostname === "localhost") {
// We're testing locally, use local URLs for Mavo
self.addEventListener("fetch", function(evt) {
var url = evt.request.url;
if (url.indexOf("get.mavo.io/mavo.") > -1 || url.indexOf("dev.mavo.io/dist/mavo.") > -1) {
var newURL = url.replace(/.+?(get|dev)\.mavo\.io\/(dist\/)?/, "http://localhost:8000/dist/") + "?" + Date.now();
newURL = newURL.replace(".es5.js", ".js")
var response = fetch(new Request(newURL), evt.request)
.then(r => r.status < 400? r : Promise.reject())
.catch(err => fetch(evt.request)); // if that fails, return original request
evt.respondWith(response);
}
});
}
return;
}
var src = document.currentScript ? document.currentScript.src : "sitewide.js";
if ("serviceWorker" in navigator && location.hostname == "localhost") {
// Register this script as a service worker
addEventListener("load", function() {
navigator.serviceWorker.register(src);
});
}
if (parent && parent !== window && new URL(location).searchParams.get("full") === null || new URL(location).searchParams.get("lite") !== null) {
document.documentElement.classList.add("lite")
}
// Resize iframes to fit
$$(".example-container > iframe").forEach(iframe => {
$.events(iframe, "DOMFrameContentLoaded load", () => {
var root = iframe.contentDocument.documentElement;
$.style(root, {
"font-size": "85%",
"box-sizing": "border-box"
});
//iframe.style.height = root.offsetHeight - 29 + "px";
var height = 0;
Mavo.observeResize(root, e => {
if (height != root.offsetHeight) {
iframe.style.height = root.offsetHeight + "px";
height = root.offsetHeight
}
});
});
});
$$("pre > code a[aria-label]").forEach(a => a.target = "_blank");
// Add notice to advanced sections
$.events(document, "DOMContentLoaded mv-load", function(evt) {
$$("section.advanced").forEach(section => {
var heading = $("h1, h2", section);
if (!heading.nextElementSibling.matches("p.notice.warning")) {
var thing = section.getAttribute("data-required") || "JavaScript";
$.create("p", {
className: "notice warning",
textContent: `This section requires an understanding of ${thing}. It is aimed at advanced users and plugin developers. You do not need to understand ${thing} to use Mavo!`,
after: heading
});
}
});
})
})(self.Bliss)