Skip to content

Commit

Permalink
Verified with WonderCMS 3.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
joho1968 committed Nov 8, 2023
1 parent f613cdd commit dc9fbb5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 66 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ chosen not to modify anything.

## Changelog

### 1.2.2 (2023-11-08)
* Added support for `getSiteLanguage()` introduced in WonderCMS 3.4.3, this is used for the `<html>` tag output.
* Some `<script>` and `<style>` tags have been moved to the `<body>` section of the page.
* Better CSS to disable Bootstrap animations/transitions for the navbar

### 1.2.1 (2023-08-02)
* Minor fixes/cleanup for search functionality
* Fixes for "navbar" in Dark Mode
Expand Down
144 changes: 80 additions & 64 deletions theme.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php global $Wcms; ?>
<!DOCTYPE html>
<html lang="en" data-bs-theme="auto">
<?php
if ( method_exists( $Wcms, 'getSiteLanguage' ) ) {
// WonderCMS 3.4.3+
echo '<html lang="' . htmlentities( $Wcms->getSiteLanguage() ) . '" data-bs-theme="auto">';
} else {
// WonderCMS < 3.4.3
echo '<html lang="en" data-bs-theme="auto">';
}
?>

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down Expand Up @@ -29,69 +38,17 @@

</head>

<script>
(() => {
'use strict'

// Set theme to the user's preferred color scheme
function updateBootstrapTheme() {
const colorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ?
"dark" :
"light";
document.querySelector("html").setAttribute("data-bs-theme", colorMode);
}
// Submit search form to ourselves
function wcmsBS5search() {
let e = document.getElementById("searchtext");
if (e && ! e.value.length ) {
e.focus();
} else {
e = document.getElementById("searchform");
if (e) {
e.submit();
}
}
}
function wcmsBS5setup() {
// Update theme when the preferred scheme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateBootstrapTheme);
// Setup button click handler for search form
let searchButton = document.getElementById("searchbutton");
if (searchButton) {
searchButton.addEventListener("click", wcmsBS5search);
}
// Setup search field handler for ENTER key
let e = document.getElementById("searchtext");
if (e) {
if (searchButton) {
e.addEventListener("keydown", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
searchButton.click();
}
});
}
}
}

if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
wcmsBS5setup();
} else {
document.addEventListener("DOMContentLoaded", wcmsBS5setup);
<body>
<!-- Disable Bootstrap's "animation" on "collapsing" for the navbar -->
<style>
.collapsing {
transition-delay: 0s !important;
transition-duration: 0s !important;
transition: none !important;
display: none !important;
}
})()
</script>

<!-- Disable Bootstrap's "animation" on "collapsing" for the navbar -->
<style>
#bs5navBar.collapsing {
transition-property: none !important;
transition-duration: 0s !important;
transition-delay: 0s !important;
}
</style>
</style>

<body>
<script>
<?php
/**
Expand Down Expand Up @@ -210,7 +167,6 @@ function pageWalk( $item, $key, $slug ) {
error_log('Final result-------------------------------------');
error_log(print_r($GLOBALS['searchpages'] , true));
*/

foreach( $GLOBALS['searchpages'] as $page ) {
if ( mb_stristr( $page['title'], $searchString ) !== false ) {
$matchingContent[] = array(
Expand All @@ -236,7 +192,11 @@ function pageWalk( $item, $key, $slug ) {
}

/**
* See if the SimpleBlog plugin is present, in which case we need to search there too
* See if the SimpleBlog plugin is present, in which case we need to search there too.
*
* TODO: This could possibly be improved or be done differently if WonderCMS 3.4.3+ is
* installed since it has a installedPlugins() function. I'll leave this as it
* is for now though.
*/
$simpleBlogData = $Wcms->dataPath . '/simpleblog.json';
if ( file_exists( $Wcms->rootDir . '/plugins/simple-blog/simple-blog.php' ) ) {
Expand Down Expand Up @@ -428,6 +388,62 @@ function pageWalk( $item, $key, $slug ) {
echo $Wcms->js();
?>
</div>


<script>
(() => {
'use strict'

// Set theme to the user's preferred color scheme
function updateBootstrapTheme() {
const colorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ?
"dark" :
"light";
document.querySelector("html").setAttribute("data-bs-theme", colorMode);
}
// Submit search form to ourselves
function wcmsBS5search() {
let e = document.getElementById("searchtext");
if (e && ! e.value.length ) {
e.focus();
} else {
e = document.getElementById("searchform");
if (e) {
e.submit();
}
}
}
function wcmsBS5setup() {
// Update theme when the preferred scheme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateBootstrapTheme);
// Setup button click handler for search form
let searchButton = document.getElementById("searchbutton");
if (searchButton) {
searchButton.addEventListener("click", wcmsBS5search);
}
// Setup search field handler for ENTER key
let e = document.getElementById("searchtext");
if (e) {
if (searchButton) {
e.addEventListener("keydown", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
searchButton.click();
}
});
}
}
}

if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
wcmsBS5setup();
} else {
document.addEventListener("DOMContentLoaded", wcmsBS5setup);
}
})()
</script>


</body>

</html>
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2
2 changes: 1 addition & 1 deletion wcms-modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repo": "https://github.com/joho1968/wcms-bs5/tree/master",
"zip": "https://github.com/joho1968/wcms-bs5/archive/master.zip",
"summary": "Simple WonderCMS Bootstrap 5 theme.",
"version": "1.2.1",
"version": "1.2.2",
"image": "https://raw.githubusercontent.com/joho1968/wcms-bs5/master/preview.jpg"
}
}
Expand Down

0 comments on commit dc9fbb5

Please sign in to comment.