Files
ds2-core/src/js/scaffolding.js

80 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-07-12 22:19:12 -04:00
// core and prism
import * as core from './core/_core.js';
2024-06-13 00:00:00 -04:00
import * as Prism from "../../node_modules/prismjs/prism";
2024-07-14 16:18:52 -04:00
import "../../node_modules/prismjs/plugins/line-numbers/prism-line-numbers";
import "../../node_modules/prismjs/plugins/toolbar/prism-toolbar";
2024-06-13 00:00:00 -04:00
import '../../node_modules/prismjs/components/prism-json';
import '../../node_modules/prismjs/components/prism-pug';
2024-07-11 21:05:34 -04:00
import '../../node_modules/prismjs/components/prism-sass';
2024-06-13 00:00:00 -04:00
2024-07-12 22:19:12 -04:00
// import pattern stuff.
2024-07-14 16:18:52 -04:00
import * as stickynote from "../pg/patterns/core/sticky-note/_sticky-note.js";
import * as swtch from "../pg/patterns/core/switch/_switch.js";
import * as tabs from "../pg/patterns/core/tabs/_tabs.js";
2024-06-13 00:00:00 -04:00
2024-07-12 22:19:12 -04:00
// init core
core.init({
success: (a) => {
tabs.init(a);
swtch.init(a);
stickynote.init(a);
},
notFound: (a, path) => {
a.innerHTML = `${a.innerHTML}<div class='notification-box error'><p>This pattern appears to be missing.<br><small>(${path} returned http status 404)</small></p></div>`;
}
});
2024-06-13 00:00:00 -04:00
2024-07-16 03:44:48 -04:00
2024-07-14 16:18:52 -04:00
// deprecated switch handler
2024-07-16 03:44:48 -04:00
const flipInfoSwitch = (e, s = e.currentTarget) => {
switch(s.getAttribute("id")) {
case "deprecated" :
core.cookie.set("show-deprecated", s.getAttribute("aria-checked"), 30, "/");
document.querySelector("main").querySelectorAll("article[data-status=deprecated]").forEach((a) => {
a.classList[( s.getAttribute("aria-checked") == "true" ? "add" : "remove" )]("show-deprecated");
});
break;
case "breakpoints" :
console.log("here")
core.cookie.set("show-breakpoints", s.getAttribute("aria-checked"), 30, "/");
document.querySelector("html").classList[( s.getAttribute("aria-checked") == "true" ? "add" : "remove" )]("show-breakpoints");
break;
}
2024-07-14 16:18:52 -04:00
}
// create a pure JS mouse click event
const click = new MouseEvent('click', {
view: window,
bubbles: false,
cancelable: true
});
// get the switch, initialize it and add the handler
2024-07-16 03:44:48 -04:00
let switches = document.querySelector(".info-switches");
swtch.init(switches);
2024-07-14 16:18:52 -04:00
let deprecated = document.querySelector("#deprecated");
2024-07-16 03:44:48 -04:00
let breakpoints = document.querySelector("#breakpoints");
deprecated.onclick = flipInfoSwitch;
deprecated.keypress = flipInfoSwitch;
breakpoints.onclick = flipInfoSwitch;
breakpoints.keypress = flipInfoSwitch;
2024-07-14 16:18:52 -04:00
// check a cookie to get the switch's state
if (core.cookie.get("show-deprecated") == "true") {
deprecated.dispatchEvent(click);
}
2024-07-16 03:44:48 -04:00
if (core.cookie.get("show-breakpoints") == "true") {
breakpoints.dispatchEvent(click);
}
2024-07-12 22:19:12 -04:00
2024-07-14 16:18:52 -04:00
// just for fun... We'll show deprecated if they match the path
// document.querySelector(`#${core.url.p.replace(/\//g, "-")}`).classList.add("show-deprecated");