-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminDevModeColors.module
More file actions
171 lines (148 loc) · 5.24 KB
/
AdminDevModeColors.module
File metadata and controls
171 lines (148 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Admin Dev Mode Colors
*
* ProcessWire CMS module
*
* Changes the top bar color and injects a configurable string next to / instead of
* the PW logo on development machines.
*
* The colors and text can be set in the module's configuration.
*
* You can enable development mode in two ways:
* - in the module's configuration
* - by setting $config->devMode to a truthy value in site/config.php
*
* Currently supported admin themes:
* - AdminThemeDefault
* - AdminThemeReno
* - AdminThemeUikit
*
* This module is released under the MIT license
*
* The module includes the touch ready color picker from
* https://github.com/tovic/color-picker licences under the same
* terms
*
**/
class AdminDevModeColors extends WireData implements Module, ConfigurableModule {
public static function getModuleInfo() {
return [
"title" => "Admin DEV Mode Colors",
"summary" => "Enable distinct color scheme for development installs of PW",
"version" => "0.0.5",
"autoload" => true
];
}
public function init() {
$this->addHookAfter("AdminTheme::getExtraMarkup", $this, "getColorMarkup");
$this->wire('modules')->loadModuleFileAssets($this);
$this->config->styles->add($this->getUrlFor("color-picker", "css"));
$this->config->scripts->add($this->getUrlFor("color-picker", "js"));
}
protected function getUrlFor($name, $ext) {
$min = $this->config->debug ? "" : ".min";
$fn = $name . $min. "." . $ext;
$path = $this->config->paths->{$this->className()} . $fn;
if(! file_exists($path)) return;
$ts = date('YmdHis', filemtime($path));
$url = $this->config->urls->{$this->className()} . $fn . "?" . $ts;
return $url;
}
public function getColorMarkup(HookEvent $event) {
$parts = $event->return;
if($this->config->devMode || $this->devMode) {
$parts["head"] .= $this->getStyle();
}
$event->return = $parts;
}
protected function getStyle() {
$bgcolor = $this->bgColor;
if(!empty($this->config->devModeBgColor)) $bgcolor = $this->config->devModeBgColor;
if(! $bgcolor) $bgcolor = 'rgb(153, 12, 94)';
$fgcolor = $this->fgColor;
if(!empty($this->config->devModeFgColor)) $fgcolor = $this->config->devModeFgColor;
if(! $fgcolor) $fgcolor = 'rgb(255, 255, 255)';
$devstring = $this->devString;
if(!empty($this->config->devModeDevString)) $devstring = $this->config->devModeDevString;
if(! $devstring) $devstring = "DEV";
$style = "<style>
/* Top bar coloring */
#masthead, #branding, #pw-masthead, #pw-masthead-mobile, body.AdminThemeReno a.main-nav-toggle { background-color: $bgcolor !important; }
body.AdminThemeReno #masthead #topnav > li > a { color: rgb(201, 207, 222) !imoprtant; }
/* Admin theme default */
body.AdminThemeDefault #logo:before,
body.AdminThemeDefault li.collapse-topnav-menu:after {
content: '$devstring';
color: $fgcolor;
font-size: 2em;
font-weight: bold;
vertical-align: top;
margin-right: 1em;
}
body.AdminThemeDefault #logo img {
display: none;
}
/* Admin theme Reno */
body.AdminThemeReno #logo:after {
content: '$devstring';
color: $fgcolor;
vertical-align: middle;
font-size: 2em !important;
letter-spacing: 0.05em;
margin-right: 5em;
}
body.AdminThemeReno #branding #logo img { display: none; }
body.AdminThemeReno #branding #logo img.sm {
display: inline;
margin: 0;
}
body.AdminThemeReno #branding #logo {
margin-top: 0.2em;
}
/* Admin theme Uikit */
div.uk-navbar-right > ul > li:first-child > a:before,
#pw-masthead-mobile a:after {
content: '$devstring';
margin-right: 5em;
font-size: 2em;
font-weight: bold;
color: $fgcolor;
vertical-align: middle;
}
</style>" . PHP_EOL;
return $style;
}
public static function getModuleConfigInputfields($data) {
$inputfields = new InputfieldWrapper();
$f = wire('modules')->get('InputfieldCheckbox');
$f->attr('id+name', 'devMode');
$f->attr('value', 1);
if(isset($data["devMode"]) && $data["devMode"]) $f->attr('checked', 'checked');
$f->label = wire()->_("Enable DEV mode");
$f->description = wire()->_("Check this box to enable DEV mode colors");
$f->notice = wire()->_('You can also set $config->devMode = true in site/ready.php instead');
$inputfields->append($f);
$f = wire('modules')->get('InputfieldText');
$f->attr('id+name', 'bgColor');
$f->attr('value', isset($data["bgColor"]) ? $data["bgColor"] : 'rgb(153, 12, 94)');
$f->addClass('colorpicker');
$f->label = wire()->_("Background Color");
$f->description = wire()->_("Background color for masthead (top bar)");
$inputfields->append($f);
$f = wire('modules')->get('InputfieldText');
$f->attr('id+name', 'fgColor');
$f->attr('value', isset($data["fgColor"]) ? $data["fgColor"] : 'rgb(255, 255, 255)');
$f->addClass('colorpicker');
$f->label = wire()->_("Foreground Color");
$f->description = wire()->_("Foreground color for dev text (top bar)");
$inputfields->append($f);
$f = wire('modules')->get('InputfieldText');
$f->attr('id+name', 'devString');
$f->attr('value', isset($data["devString"]) ? $data["devString"] : 'DEV');
$f->label = wire()->_("Inject Text");
$f->description = wire()->_("Text to inject into the top bar to distinguish this as a dev system");
$inputfields->append($f);
return $inputfields;
}
}