PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.5.2
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.5.2
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Frontend / Templates / footer_script.php

footer_script.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.5.2, at src/Frontend/Templates/footer_script.php

208 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use ThemeAtelier\Darkify\Includes\DarkifyUtils;
4
5 // don't call the file directly.
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9
10 $options = get_option('darkify');
11 $enable_dark_mode_switch = isset($options["enable_dark_mode_switch"]) ? $options["enable_dark_mode_switch"] : true;
12 $hide_on_desktop = isset($options["hide_on_desktop"]) ? $options["hide_on_desktop"] : '';
13 $hide_on_mobile = isset($options["hide_on_mobile"]) ? $options["hide_on_mobile"] : '';
14 $enable_admin_panel_dark_mode = isset($options["enable_admin_panel_dark_mode"]) ? $options["enable_admin_panel_dark_mode"] : '';
15 $block_editor_dark_mode = isset($options['block_editor_dark_mode']) ? $options['block_editor_dark_mode'] : false;
16 $hide_dark_mode_on_mobile = isset($hide_on_mobile["hide_dark_mode_on_mobile"]) ? $hide_on_mobile["hide_dark_mode_on_mobile"] : 0;
17 $type_of_hide_by = isset($hide_on_mobile["type_of_hide_by"]) ? $hide_on_mobile["type_of_hide_by"] : 0;
18
19 $normal_custom_css = isset($options["normal_custom_css"]) ? $options["normal_custom_css"] : "";
20 $custom_css = isset($options["custom_css"]) ? $options["custom_css"] : "";
21 $admin_custom_css = isset($options['admin_custom_css']) ? $options['admin_custom_css'] : "";
22
23 if (!is_admin()) {
24 if ($enable_dark_mode_switch) {
25 if (!$this->utils->is_hidden_by_user_agent($hide_on_desktop, $hide_dark_mode_on_mobile, $type_of_hide_by)) {
26 include_once DarkifyUtils::darkify_locate_template('views/switch.php');
27 }
28 }
29 }
30 ?>
31
32 <style type="text/css" class="darkify_inline_css">
33 <?php echo wp_strip_all_tags(DarkifyUtils::parseAndProcessNormalCustomCSS($normal_custom_css)); ?>
34 </style>
35 <style type="text/css" class="darkify_inline_css">
36 <?php echo wp_strip_all_tags(DarkifyUtils::parseAndProcessCustomCSS($custom_css, false)); ?>
37 </style>
38
39 <?php if (!is_admin()) { ?>
40 <script type="text/javascript" class="darkify_inline_js">
41 document.addEventListener("DOMContentLoaded", function(event) {
42 darkify_init_alternative_dark_mode_switch();
43 });
44 </script>
45 <?php }
46
47 if (is_admin() && $block_editor_dark_mode) {
48 ?><style type="text/css" class="darkify_inline_css">
49 <?php echo esc_html(DarkifyUtils::parseAndProcessCustomCSS($admin_custom_css, 'yes')); ?>
50 </style>
51 <?php
52 /* Check if block editor is on, then add the dark mode button there */
53 if ($enable_admin_panel_dark_mode) {
54 if (class_exists('WP_Block_Type_Registry')) {
55
56 if (get_current_screen() && 'post' === get_current_screen()->base && ('post' === get_current_screen()->post_type || 'page' === get_current_screen()->post_type)) { ?>
57 <script type="text/javascript" class="darkify_inline_js">
58 (function checkForWP() {
59 if (
60 typeof wp === 'undefined' ||
61 typeof wp.domReady === 'undefined' ||
62 typeof wp.plugins === 'undefined' ||
63 typeof wp.element === 'undefined'
64 ) {
65 return setTimeout(checkForWP, 200);
66 }
67
68 wp.domReady(function() {
69
70 function injectDarkify() {
71 // Target the LEFT side toolbar
72 const target =
73 document.querySelector('.editor-header__toolbar') ||
74 document.querySelector('.edit-post-header-toolbar') ||
75 document.querySelector('.editor-document-tools');
76
77 if (!target) return false;
78 if (target.querySelector('.darkify-dropdown')) return true;
79
80 const themes = [{
81 value: 'set1',
82 label: 'Carbon Mist',
83 cls: 'carbon_mist'
84 },
85 {
86 value: 'set3',
87 label: 'Midnight Reverie',
88 cls: 'midnight_reverie'
89 },
90 {
91 value: 'set9',
92 label: 'Verdant Depths',
93 cls: 'verdant_depths'
94 },
95 {
96 value: 'set6',
97 label: 'Celestial Tide',
98 cls: 'celestial_tide'
99 },
100 {
101 value: 'set10',
102 label: 'Emberwood',
103 cls: 'emberwood'
104 },
105 {
106 value: 'set2',
107 label: 'Glacier Drift (Pro)',
108 cls: 'glacier_drift'
109 },
110 {
111 value: 'set4',
112 label: 'Indigo Veil (Pro)',
113 cls: 'indigo_veil'
114 },
115 {
116 value: 'set5',
117 label: 'Duskmire (Pro)',
118 cls: 'duskmire'
119 },
120 {
121 value: 'set7',
122 label: 'Tidal Frost (Pro)',
123 cls: 'tidal_frost'
124 },
125 {
126 value: 'set8',
127 label: 'Blue Bastion (Pro)',
128 cls: 'blue_bastion'
129 },
130 {
131 value: 'set11',
132 label: 'Crimson Veil (Pro)',
133 cls: 'crimson_veil'
134 },
135 ];
136
137 // Dark mode toggle button
138 const button = document.createElement('button');
139 button.className = 'darkify_block_editor_switch darkify_ignore';
140 button.innerHTML = '<div class="icon"></div>';
141 button.onclick = function() {
142 darkify_switch_trigger();
143 };
144
145 // Dropdown wrapper
146 const wrapper = document.createElement('div');
147 wrapper.className = 'darkify-dropdown';
148 wrapper.style.cssText = 'position:relative;display:inline-flex;align-items:center;';
149
150 const selected = document.createElement('div');
151 selected.className = 'darkify-selected';
152
153 const list = document.createElement('div');
154 list.className = 'darkify-options';
155
156 themes.forEach(t => {
157 const item = document.createElement('div');
158 item.className = 'darkify-option';
159 item.innerHTML = `<span class="theme_color ${t.cls}"></span> ${t.label}`;
160 item.onclick = () => {
161 selected.innerHTML = item.innerHTML;
162 localStorage.darkify_selected_theme = t.value;
163 darkify_theme_select(t.value);
164 list.classList.remove('show');
165 };
166 list.appendChild(item);
167 });
168
169 // Load saved theme
170 const savedVal = localStorage.darkify_selected_theme || 'set1';
171 const savedTheme = themes.find(t => t.value === savedVal) || themes[0];
172 selected.innerHTML = `<span class="theme_color ${savedTheme.cls}"></span> ${savedTheme.label}`;
173
174 selected.onclick = (e) => {
175 e.stopPropagation();
176 list.classList.toggle('show');
177 };
178
179 document.addEventListener('click', function(e) {
180 if (!wrapper.contains(e.target)) list.classList.remove('show');
181 });
182
183 wrapper.appendChild(selected);
184 wrapper.appendChild(list);
185
186 // Append to END of left toolbar
187 target.appendChild(button);
188 target.appendChild(wrapper);
189
190 return true;
191 }
192
193 if (!injectDarkify()) {
194 const interval = setInterval(function() {
195 if (injectDarkify()) clearInterval(interval);
196 }, 300);
197 setTimeout(function() {
198 clearInterval(interval);
199 }, 10000);
200 }
201 });
202 })();
203 </script>
204 <?php }
205 }
206 }
207 }
208