aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-02-14 07:56:53 +0000
committerpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-02-14 07:56:53 +0000
commit77ce52c4e9032fdc90dda58ac0c59521dca4db97 (patch)
treedc5646107262e53269c8ef4b3c8e38c9a0f0e662 /scripts
parent0114f5240a9d4cf75e84ac23e955571a83a1fc98 (diff)
downloadpmwiki.svn-77ce52c4e9032fdc90dda58ac0c59521dca4db97.tar.bz2
Dark theme toggle: refactor into a separate script pub/pmwiki-darktoggle.js, inject at the top of $HTMLHeaderFmt.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@4643 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'scripts')
-rw-r--r--scripts/utils.php20
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/utils.php b/scripts/utils.php
index dc40ae11..ba95b24f 100644
--- a/scripts/utils.php
+++ b/scripts/utils.php
@@ -28,6 +28,7 @@ function PmUtilsJS() {
$EnableCopyCode, $EnableDarkThemeToggle, $EnableRedirectQuiet;
$utils = "$FarmD/pub/pmwiki-utils.js";
+ $dark = "$FarmD/pub/pmwiki-darktoggle.js";
$cc = IsEnabled($EnableCopyCode, 0)? PHSC(XL('Copy code'), ENT_QUOTES) : '';
@@ -50,12 +51,6 @@ function PmUtilsJS() {
'copycode' => $cc,
'toggle' => IsEnabled($ToggleNextSelector, 0),
'localtimes' => IsEnabled($EnableLocalTimes, 0),
- 'darktheme' => array(
- 'enable'=> IsEnabled($EnableDarkThemeToggle, 0),
- 'label'=> XL('Toggle theme'),
- 'currently'=> XL('Currently:'),
- 'modes'=> array( XL('Light'), XL('Dark'), XL('Auto'), ),
- ),
'rediquiet' => IsEnabled($EnableRedirectQuiet, 0),
);
$enabled = $PmTOC['Enable'];
@@ -81,6 +76,19 @@ function PmUtilsJS() {
data-label=\"$[Highlight]\" data-mode='$EnablePmSyntax'
data-custom=\"$cs\"></script>");
}
+
+ // Dark theme toggle, needs to be very early
+ $enabled = IsEnabled($EnableDarkThemeToggle, 0);
+ if ($enabled && file_exists($dark)) {
+ $config = array(
+ 'enable' => $enabled,
+ 'label'=> XL('Dark theme: '),
+ 'modes'=> array( XL('Light'), XL('Dark'), XL('Auto'), ),
+ );
+ $json = pm_json_encode($config);
+ array_unshift($HTMLHeaderFmt, "<script src='\$FarmPubDirUrl/pmwiki-darktoggle.js'
+ data-config='$json'></script>");
+ }
}
PmUtilsJS();