Skip to content

Commit dc9fbb5

Browse files
committed
Verified with WonderCMS 3.4.3
1 parent f613cdd commit dc9fbb5

File tree

4 files changed

+87
-66
lines changed

4 files changed

+87
-66
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ chosen not to modify anything.
3838

3939
## Changelog
4040

41+
### 1.2.2 (2023-11-08)
42+
* Added support for `getSiteLanguage()` introduced in WonderCMS 3.4.3, this is used for the `<html>` tag output.
43+
* Some `<script>` and `<style>` tags have been moved to the `<body>` section of the page.
44+
* Better CSS to disable Bootstrap animations/transitions for the navbar
45+
4146
### 1.2.1 (2023-08-02)
4247
* Minor fixes/cleanup for search functionality
4348
* Fixes for "navbar" in Dark Mode

theme.php

Lines changed: 80 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?php global $Wcms; ?>
22
<!DOCTYPE html>
3-
<html lang="en" data-bs-theme="auto">
3+
<?php
4+
if ( method_exists( $Wcms, 'getSiteLanguage' ) ) {
5+
// WonderCMS 3.4.3+
6+
echo '<html lang="' . htmlentities( $Wcms->getSiteLanguage() ) . '" data-bs-theme="auto">';
7+
} else {
8+
// WonderCMS < 3.4.3
9+
echo '<html lang="en" data-bs-theme="auto">';
10+
}
11+
?>
12+
413
<head>
514
<meta charset="UTF-8">
615
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -29,69 +38,17 @@
2938

3039
</head>
3140

32-
<script>
33-
(() => {
34-
'use strict'
35-
36-
// Set theme to the user's preferred color scheme
37-
function updateBootstrapTheme() {
38-
const colorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ?
39-
"dark" :
40-
"light";
41-
document.querySelector("html").setAttribute("data-bs-theme", colorMode);
42-
}
43-
// Submit search form to ourselves
44-
function wcmsBS5search() {
45-
let e = document.getElementById("searchtext");
46-
if (e && ! e.value.length ) {
47-
e.focus();
48-
} else {
49-
e = document.getElementById("searchform");
50-
if (e) {
51-
e.submit();
52-
}
53-
}
54-
}
55-
function wcmsBS5setup() {
56-
// Update theme when the preferred scheme changes
57-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateBootstrapTheme);
58-
// Setup button click handler for search form
59-
let searchButton = document.getElementById("searchbutton");
60-
if (searchButton) {
61-
searchButton.addEventListener("click", wcmsBS5search);
62-
}
63-
// Setup search field handler for ENTER key
64-
let e = document.getElementById("searchtext");
65-
if (e) {
66-
if (searchButton) {
67-
e.addEventListener("keydown", function(event) {
68-
if (event.keyCode === 13) {
69-
event.preventDefault();
70-
searchButton.click();
71-
}
72-
});
73-
}
74-
}
75-
}
76-
77-
if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
78-
wcmsBS5setup();
79-
} else {
80-
document.addEventListener("DOMContentLoaded", wcmsBS5setup);
41+
<body>
42+
<!-- Disable Bootstrap's "animation" on "collapsing" for the navbar -->
43+
<style>
44+
.collapsing {
45+
transition-delay: 0s !important;
46+
transition-duration: 0s !important;
47+
transition: none !important;
48+
display: none !important;
8149
}
82-
})()
83-
</script>
84-
85-
<!-- Disable Bootstrap's "animation" on "collapsing" for the navbar -->
86-
<style>
87-
#bs5navBar.collapsing {
88-
transition-property: none !important;
89-
transition-duration: 0s !important;
90-
transition-delay: 0s !important;
91-
}
92-
</style>
50+
</style>
9351

94-
<body>
9552
<script>
9653
<?php
9754
/**
@@ -210,7 +167,6 @@ function pageWalk( $item, $key, $slug ) {
210167
error_log('Final result-------------------------------------');
211168
error_log(print_r($GLOBALS['searchpages'] , true));
212169
*/
213-
214170
foreach( $GLOBALS['searchpages'] as $page ) {
215171
if ( mb_stristr( $page['title'], $searchString ) !== false ) {
216172
$matchingContent[] = array(
@@ -236,7 +192,11 @@ function pageWalk( $item, $key, $slug ) {
236192
}
237193

238194
/**
239-
* See if the SimpleBlog plugin is present, in which case we need to search there too
195+
* See if the SimpleBlog plugin is present, in which case we need to search there too.
196+
*
197+
* TODO: This could possibly be improved or be done differently if WonderCMS 3.4.3+ is
198+
* installed since it has a installedPlugins() function. I'll leave this as it
199+
* is for now though.
240200
*/
241201
$simpleBlogData = $Wcms->dataPath . '/simpleblog.json';
242202
if ( file_exists( $Wcms->rootDir . '/plugins/simple-blog/simple-blog.php' ) ) {
@@ -428,6 +388,62 @@ function pageWalk( $item, $key, $slug ) {
428388
echo $Wcms->js();
429389
?>
430390
</div>
391+
392+
393+
<script>
394+
(() => {
395+
'use strict'
396+
397+
// Set theme to the user's preferred color scheme
398+
function updateBootstrapTheme() {
399+
const colorMode = window.matchMedia("(prefers-color-scheme: dark)").matches ?
400+
"dark" :
401+
"light";
402+
document.querySelector("html").setAttribute("data-bs-theme", colorMode);
403+
}
404+
// Submit search form to ourselves
405+
function wcmsBS5search() {
406+
let e = document.getElementById("searchtext");
407+
if (e && ! e.value.length ) {
408+
e.focus();
409+
} else {
410+
e = document.getElementById("searchform");
411+
if (e) {
412+
e.submit();
413+
}
414+
}
415+
}
416+
function wcmsBS5setup() {
417+
// Update theme when the preferred scheme changes
418+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', updateBootstrapTheme);
419+
// Setup button click handler for search form
420+
let searchButton = document.getElementById("searchbutton");
421+
if (searchButton) {
422+
searchButton.addEventListener("click", wcmsBS5search);
423+
}
424+
// Setup search field handler for ENTER key
425+
let e = document.getElementById("searchtext");
426+
if (e) {
427+
if (searchButton) {
428+
e.addEventListener("keydown", function(event) {
429+
if (event.keyCode === 13) {
430+
event.preventDefault();
431+
searchButton.click();
432+
}
433+
});
434+
}
435+
}
436+
}
437+
438+
if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
439+
wcmsBS5setup();
440+
} else {
441+
document.addEventListener("DOMContentLoaded", wcmsBS5setup);
442+
}
443+
})()
444+
</script>
445+
446+
431447
</body>
432448

433449
</html>

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.1
1+
1.2.2

wcms-modules.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"repo": "https://github.com/joho1968/wcms-bs5/tree/master",
77
"zip": "https://github.com/joho1968/wcms-bs5/archive/master.zip",
88
"summary": "Simple WonderCMS Bootstrap 5 theme.",
9-
"version": "1.2.1",
9+
"version": "1.2.2",
1010
"image": "https://raw.githubusercontent.com/joho1968/wcms-bs5/master/preview.jpg"
1111
}
1212
}

0 commit comments

Comments
 (0)