Files
MokoCassiopeia/media/templates/site/moko-cassiopeia/js/template.js
Jonathan Miller bee7796645 02.00
**Major Release** — introduces the long-awaited **Dark Mode Toggle**, streamlining accessibility and usability enhancements.

##Added

* **Dark Mode Toggle**

	* Frontend toggle switch included in template.
	* JavaScript handles switching between light/dark modes.
	* Dark mode CSS rules applied across template styles.
	* Automatic persistence of user choice (via localStorage).

* **Header Parameters Update**

	* Added **logo parameter support** in template settings.
	* Updated metadata & copyright header.

* **Expanded TOC (Table of Contents)**

	* Automatic TOC injection when enabled.
	* User selects placement via article > options > layout (`toc-left` or `toc-right`).

##Improved

* Cleaned up `index.php` by removing **skip-to-content** duplicate calls.
* Consolidated JavaScript asset loading (ensuring dark-mode script is loaded correctly from external JS file).
* Streamlined CSS for **toggle switch**, ensuring it inherits Bootstrap/Cassiopeia defaults.
* General accessibility refinements in typography and color contrast.

##Fixed

* Fixed missing **logo param** in header output.
* Corrected stylesheet inconsistencies between Bootstrap 5 helpers and template overrides.
* Patched redundant calls in script includes.
2025-08-30 18:41:15 -05:00

118 lines
3.2 KiB
JavaScript

/* =========================================================================
* Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
*
* This file is part of a Moko Consulting project.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/ .
* =========================================================================
* FILE INFORMATION
* DEFGROUP: Joomla
* INGROUP: Moko-Cassiopeia
* PATH: media/templates/site/moko-cassiopeia/js/template.js
* VERSION: 02.00
* BRIEF: Core JavaScript utilities and behaviors for Moko-Cassiopeia template
* =========================================================================
*/
(function (win, doc) {
"use strict";
/**
* Utility: smooth scroll to top
*/
function backToTop() {
win.scrollTo({ top: 0, behavior: "smooth" });
}
/**
* Utility: toggle body class on scroll for sticky header styling
*/
function handleScroll() {
if (win.scrollY > 50) {
doc.body.classList.add("scrolled");
} else {
doc.body.classList.remove("scrolled");
}
}
/**
* Initialize Bootstrap TOC if #toc element exists.
* Requires bootstrap-toc.min.js to be loaded.
*/
function initTOC() {
if (typeof win.Toc === "function" && doc.querySelector("#toc")) {
win.Toc.init({
$nav: $("#toc"),
$scope: $("main")
});
}
}
/**
* Initialize offcanvas drawer buttons for left/right drawers.
* Uses Bootstrap's offcanvas component.
*/
function initDrawers() {
var leftBtn = doc.querySelector(".drawer-toggle-left");
var rightBtn = doc.querySelector(".drawer-toggle-right");
if (leftBtn) {
leftBtn.addEventListener("click", function () {
var target = doc.querySelector(leftBtn.getAttribute("data-bs-target"));
if (target) new bootstrap.Offcanvas(target).show();
});
}
if (rightBtn) {
rightBtn.addEventListener("click", function () {
var target = doc.querySelector(rightBtn.getAttribute("data-bs-target"));
if (target) new bootstrap.Offcanvas(target).show();
});
}
}
/**
* Initialize back-to-top link if present
*/
function initBackTop() {
var backTop = doc.getElementById("back-top");
if (backTop) {
backTop.addEventListener("click", function (e) {
e.preventDefault();
backToTop();
});
}
}
/**
* Run all template JS initializations
*/
function init() {
// Sticky header behavior
handleScroll();
win.addEventListener("scroll", handleScroll);
// Init features
initTOC();
initDrawers();
initBackTop();
}
if (doc.readyState === "loading") {
doc.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})(window, document);