Updates
This commit is contained in:
2024-07-11 21:05:34 -04:00
parent b5e421761f
commit 4a18341cf5
65 changed files with 3631 additions and 914 deletions

View File

@@ -1,28 +1,29 @@
import * as core from './_core.js';
import * as Prism from "../../node_modules/prismjs/prism";
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 * as cookie from './_cookies.js';
import * as get from "./_geturlvars.js";
import * as colours from "./_color-samples.js";
import * as swtch from "../pg/patterns/components/switch-core/_switch.js";
import * as stickynote from "../pg/patterns/components/sticky-note-core/_sticky-note.js";
import * as tabs from "../pg/patterns/layouts/tabs-core/_tabs.js";
// oneClickSelect.init();
const initComponents = (jQuery) => {
swtch.init();
tabs.tabs(jQuery);
tabs.init();
stickynote.init();
}
// selectable content
jQuery.fn.OneClickSelect = function () {
return jQuery(this).on('click', function () {
/* In here, "this" is the element */
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
@@ -38,41 +39,37 @@ jQuery.fn.OneClickSelect = function () {
});
};
String.prototype.toTitleCase = function() {
return this.replace(/\w\S*/g, function(txt) {
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, " ");
}
jQuery(document).ready(function($){
if (get.vars.p != undefined) {
console.log("category:", get.vars.p)
$("main article:not([data-path^='" + get.vars.p + "'])").remove();
if (core.url.p != undefined) {
console.log("category:", core.url.p)
$("main article:not([data-path^='" + core.url.p + "'])").remove();
if (get.vars.p == -1) {
$("title").html(`${get.vars.p.toContent().toTitleCase()} | ${$("title").attr("data-site")}`);
if (core.url.p == -1) {
$("title").html(`${core.url.p.toContent().toTitleCase()} | ${$("title").attr("data-site")}`);
} else {
$("title").html(`${get.vars.p.substring(get.vars.p.lastIndexOf("/")+1).toContent().toTitleCase()} | ${$("title").attr("data-site")}`);
$("title").html(`${core.url.p.substring(core.url.p.lastIndexOf("/")+1).toContent().toTitleCase()} | ${$("title").attr("data-site")}`);
}
console.log("get the 'directory'", (get.vars.p.indexOf("/") == -1 ? get.vars.p : get.vars.p.substring(0, get.vars.p.indexOf("/")) ));
$(".main-nav nav ul li a[href='./?p=" + (get.vars.p.indexOf("/") == -1 ? get.vars.p : get.vars.p.substring(0, get.vars.p.indexOf("/")) ) + "']").parent().addClass("active");
console.log("get the 'directory'", (core.url.p.indexOf("/") == -1 ? core.url.p : core.url.p.substring(0, core.url.p.indexOf("/")) ));
$(".main-nav nav ul li a[href='./?p=" + (core.url.p.indexOf("/") == -1 ? core.url.p : core.url.p.substring(0, core.url.p.indexOf("/")) ) + "']").parent().addClass("active");
} else {
$("header").addClass("show-feature");
$(".main-nav nav ul li a[href='./']").parent().addClass("active");
}
// window.onresize = () => {
// console.log("resize called")
// initComponents($);
// }
let articles = $("article").length;
$("article").each(function(k,v){
if ($(this).attr("data-template") != "none") {
let path = "patterns/" + $(this).attr("data-path") + ($(this).attr("data-core") == "true" ? "-core" : "") + "/index.html";
console.log(path)
$( "#" + $(this).attr("id") ).load(path, "", function(response, status, xhr){
if ( status == "error" ) {
$( "#" + $(this).attr("id") ).html(`<div class='notification-box error'><p>This pattern appears to be missing.<br><small>(${path} returned http status 404)</small></p></div>`);
@@ -81,7 +78,7 @@ jQuery(document).ready(function($){
if (articles == 0) {
$("article").each(function(){
try {
$(this).prepend(`<h1 class="status-${$(this).attr("data-status")}"><span>${$(this).attr("data-pattern").toContent().toSentenceCase()}</span></h1>`);
$(this).prepend(`<h1 class="status-${$(this).attr("data-status")}"><span>${($(this).attr("data-display-text") != undefined ? $(this).attr("data-display-text") : $(this).attr("data-pattern").toContent().toSentenceCase())}<div role="tooltip" inert tip-position="right">${$(this).attr("data-status").toContent().toSentenceCase()}</div></span></h1>`);
} catch (e) {
console.log("Problem creating heading", $(this).attr("data-pattern"));
$(this).prepend(`<div class='notification-box warning'><h1>Problem creating heading</h1><p>The content we found for this header was: ${$(this).attr("data-pattern")}. Check that the data-pattern attribute on the article is set properly. Also check that there is no article tag inside the article.</p></div>`);
@@ -105,9 +102,8 @@ jQuery(document).ready(function($){
initComponents($);
Prism.highlightAll();
colours.positionTooltip();
$( window ).on("resize", function(){colours.positionTooltip()});
core.colour.positionTooltip();
$( window ).on("resize", function(){core.colour.positionTooltip()});
$("name > span, color-pill > span").on("click", function(e){
e.preventDefault();
let w = "";
@@ -120,7 +116,7 @@ jQuery(document).ready(function($){
} else {
w = "hex";
}
colours.copy(w, $(this));
core.colour.copy(w, $(this));
});
}
})
@@ -135,24 +131,23 @@ jQuery(document).ready(function($){
setTimeout(function(){
if ($("#deprecated").attr("aria-checked") == "false") {
$(".status-deprecated").closest("article").addClass("status-deprecated");
cookie.set("hide-deprecated", false, 30, "/");
core.cookie.set("hide-deprecated", false, 30, "/");
} else {
$("article.status-deprecated").removeClass("status-deprecated");
cookie.set("hide-deprecated", true, 30, "/");
core.cookie.set("hide-deprecated", true, 30, "/");
}
}, 50);
}
$("#deprecated").on("click", flipDeprecated).on("keypress", flipDeprecated);
setTimeout( function() {
if (cookie.get("hide-deprecated") == "true") {
if (core.cookie.get("hide-deprecated") == "true") {
$("#deprecated").attr("aria-checked", "true");
flipDeprecated();
}
}, 200);
console.log("hide deprecated", { "type": (typeof cookie.get("hide-deprecated")), "value": cookie.get("hide-deprecated") });
console.log("hide deprecated", { "type": (typeof core.cookie.get("hide-deprecated")), "value": core.cookie.get("hide-deprecated") });
// /hide deprecated switch
})
// import("../pg/patterns/layouts/main-navigation/_main-navigation.js");
})