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">
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>
0 commit comments