Fixed bugs and updated structure

This commit is contained in:
2024-07-14 16:18:52 -04:00
parent 51c2c569b8
commit 9c15304340
60 changed files with 4120 additions and 1405 deletions

View File

@@ -1,16 +1,25 @@
const getDate = function(){
var d = new Date();
return d.toLocaleDateString(lang, {day: "numeric", month: "long", year: "numeric"});
}
String.prototype.toTitleCase = function() {
return this.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
String.prototype.toSentenceCase = function() {
return this.charAt(0).toUpperCase() + this.substr(1).toLowerCase();
}
String.prototype.toContent = function() {
return this.replace(/-/g, " ");
}
String.prototype.toPath = function() {
return this.trim().replace(/ /g, "_").replace(/-/g, "_").replace(/[\/\W]/g, "").replace(/_/g, "-");
}
const font = {
size: 0
}
const copyColourFallback = (copyInfo, attr) => {
console.log("fallback")
@@ -50,13 +59,16 @@ const copyColourFallback = (copyInfo, attr) => {
const showMessage = (m, s) => {
s = s == undefined ? true : s;
console.log("Copy success (navigator.clipboard)");
$("body").prepend("<div id='copystatus' style='display: none;'><div class='"+(s ? "succeeded" : "failed")+"'>" + m + "</div></div>");
$("#copystatus > div").css("top", (window.scrollY + 100)+ "px");
$("#copystatus").fadeIn(1000, function(){
$(this).fadeOut( 1000, function() {
$(this).remove();
});
})
let status = document.createElement("div");
status.setAttribute("id", "copystatus");
// status.style.display = "none";
status.innerHTML = "<div class='"+(s ? "succeeded" : "failed")+"'>" + m + "</div>";
document.querySelector("body").prepend(status)
status.querySelector("div").style.top = (window.scrollY + 100)+ "px";
setTimeout( () => {
status.remove();
}, 1000);
}
const oneClickSelect = (e, t = e.currentTarget) => {
@@ -126,9 +138,7 @@ module.exports = {
},
},
colour: {
// showMessage: (m, s) => {
// showMessage(m, s);
// },
copy: (w, t) => {
let c = t.parentNode.getAttribute("data-" + (w=="var" ? "token" : w));
c = w == "var" ? `var(${c})` : c;
@@ -143,36 +153,44 @@ module.exports = {
copyColourFallback(c, w);
}
},
positionTooltip: () => {
$("color-pill > span").each(function(){
if ((Number($("p").css('font-size').replace("px","")) * 10) > $(this).offset().left) {
$(this).children("div.tooltip-tc").attr("tip-position", "right");
} else {
$(this).children("div.tooltip-tc").attr("tip-position", "bottom");
}
document.querySelectorAll("color-pill > span").forEach((ps) => {
ps.querySelectorAll("div.tooltip-tc").forEach((tip) => {
if ( (font.size * 10) > ps.offsetLeft ) {
tip.setAttribute("tip-position", "right");
} else {
tip.setAttribute("tip-position", "bottom");
}
});
})
}
},
init: (args = {}) => {
const url = getURLVars();
font.size = parseFloat(getComputedStyle(document.documentElement).fontSize.replace("px",""));
if (url.p !== undefined) {
document.querySelectorAll("main article:not([data-path^='" + url.p + "'])").forEach((a) => {
a.remove();
});
if (url.p == -1) {
document.querySelector("title").innerHTML = `${url.p.toContent().toTitleCase()} | ${$("title").attr("data-site")}`;
document.querySelector("title").innerHTML = `${url.p.toContent().toTitleCase()} | ${ document.querySelector("title").getAttribute("data-site") }`;
} else {
document.querySelector("title").innerHTML = `${url.p.substring(url.p.lastIndexOf("/")+1).toContent().toTitleCase()} | ${$("title").attr("data-site")}`
document.querySelector("title").innerHTML = `${url.p.substring(url.p.lastIndexOf("/")+1).toContent().toTitleCase()} | ${ document.querySelector("title").getAttribute("data-site") }`
}
}
if (typeof args.page == "function") args.page(a);
if (typeof args.beforeArticleLoad == "function") args.beforeArticleLoad(a);
document.querySelectorAll("article").forEach((a) => {
if ( a.getAttribute("data-template") != "none" ) {
let path = "patterns/" + (a.getAttribute("data-core") == "true" ? "core/" : "") + a.getAttribute("data-path") + "/index.html";
let path = a.getAttribute("data-path");
path = "patterns/" +
(a.getAttribute("data-core") == "true" ?
"core/" + path.substring(path.lastIndexOf("/") + 1) :
a.getAttribute("data-path"))
+ "/index.html";
const ASYNC = true;
let ajx = new XMLHttpRequest();
ajx.onreadystatechange = () => {
@@ -194,6 +212,7 @@ module.exports = {
})
break;
}
a.querySelectorAll("code").forEach((c)=> {
c.classList.add("line-numbers");
c.innerHTML = c.innerHTML.replace(/</g, "&lt;");
@@ -234,17 +253,23 @@ module.exports = {
break;
case 404:
if (typeof args.notFound == "function") args.notFound(a, path);
break;
default:
console.log("uncaught http error", { status: ajx.status, path: a.getAttribute("data-path") });
}
if (typeof args.done == "function") args.done(a);
}
};
ajx.open("GET", path, ASYNC);
ajx.send();
}
})
if (typeof args.afterArticleLoad == "function") args.afterArticleLoad(a);
}
};

View File

@@ -1,16 +1,16 @@
// core and prism
import * as core from './core/_core.js';
import * as Prism from "../../node_modules/prismjs/prism";
import "../../node_modules/prismjs/plugins/line-numbers/prism-line-numbers";
import "../../node_modules/prismjs/plugins/toolbar/prism-toolbar";
import '../../node_modules/prismjs/components/prism-json';
import '../../node_modules/prismjs/components/prism-pug';
import '../../node_modules/prismjs/components/prism-sass';
import "../../node_modules/prismjs/plugins/toolbar/prism-toolbar";
import "../../node_modules/prismjs/plugins/line-numbers/prism-line-numbers";
// import pattern stuff.
import * as swtch from "../pg/patterns/core/components/switch/_switch.js";
import * as stickynote from "../pg/patterns/core/components/sticky-note/_sticky-note.js";
import * as tabs from "../pg/patterns/core/layouts/tabs/_tabs.js";
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";
// init core
core.init({
@@ -24,30 +24,33 @@ core.init({
}
});
jQuery(document).ready(function($){
// show deprecated switch
function flipDeprecated() {
setTimeout(function(){
if ($("#deprecated").attr("aria-checked") == "false") {
$(".status-deprecated").closest("article").addClass("status-deprecated");
core.cookie.set("show-deprecated", false, 30, "/");
} else {
$("article.status-deprecated").removeClass("status-deprecated");
core.cookie.set("show-deprecated", true, 30, "/");
}
}, 50);
}
$("#deprecated").on("click", flipDeprecated).on("keypress", flipDeprecated);
setTimeout( function() {
if (core.cookie.get("show-deprecated") == "true") {
$("#deprecated").attr("aria-checked", "true");
flipDeprecated();
}
}, 200);
console.log("hide deprecated", { "type": (typeof core.cookie.get("show-deprecated")), "value": core.cookie.get("show-deprecated") });
// /hide deprecated switch
})
// deprecated switch handler
const flipDeprecated = (e, s = e.currentTarget) => {
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")
});
}
// import("../pg/patterns/layouts/main-navigation/_main-navigation.js");
// 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
let deprecated = document.querySelector("#deprecated");
swtch.init(deprecated.parentNode)
deprecated.onclick = flipDeprecated;
deprecated.keypress = flipDeprecated;
// check a cookie to get the switch's state
if (core.cookie.get("show-deprecated") == "true") {
deprecated.dispatchEvent(click);
}
// just for fun... We'll show deprecated if they match the path
// document.querySelector(`#${core.url.p.replace(/\//g, "-")}`).classList.add("show-deprecated");