-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminThemePalette.module
102 lines (79 loc) · 3.33 KB
/
AdminThemePalette.module
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
<?php
class AdminThemePalette extends AdminTheme implements Module, ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => 'Palette: Admin Theme',
'version' => 004,
'summary' => 'Beautiful, simple, sensible, customizable admin theme.',
'autoload' => 'template=admin'
);
}
public static function getModuleConfigInputfields(array $data) {
$modules = wire('modules');
$modules->addHookBefore('saveModuleConfigData', null, 'compileThemeLess');
// add color picker scripts / styles
wire('config')->scripts->append(wire('config')->urls->get("AdminThemePalette") ."scripts/jquery.minicolors.min.js");
wire('config')->styles->append(wire('config')->urls->get("AdminThemePalette")."scripts/jquery.minicolors.css");
$inputfields = new InputfieldWrapper();
// disable page dots feature
$field = wire('modules')->get('InputfieldCheckbox');
$field->label = "Disable Page Status Dots";
$field->attr('name', 'disable_dots');
if ($data['disable_dots']) $field->attr('checked', 'checked');
$field->set('columnWidth', 30);
$inputfields->add($field);
// theme color selection
// main
$field = wire('modules')->get('InputfieldText');
$field->label = "Main Color";
$field->notes = "Primarily applied to the background.";
$field->attr('name', 'theme_color_main');
$field->attr('value', isset($data['theme_color_main']) ? $data['theme_color_main'] : "");
$field->set('columnWidth', 40);
$inputfields->add($field);
// disable gravatar
$field = wire('modules')->get('InputfieldCheckbox');
$field->label = "Disable Gravatar";
$field->attr('name', 'disable_gravatar');
if ($data['disable_gravatar']) $field->attr('checked', 'checked');
$field->set('columnWidth', 30);
$inputfields->add($field);
// css override field (define custom css for easy small tweaks)
$field = wire('modules')->get('InputfieldTextarea');
$field->label = "Custom CSS (define custom css for easy small tweaks)";
$field->attr('name', 'custom_css');
$field->attr('value', isset($data['custom_css']) ? $data['custom_css'] : '');
$field->set('columnWidth', 100);
$inputfields->add($field);
return $inputfields;
}
public function ___install() {
$config = array(
'dropdown_depth' => 1
);
$this->modules->saveModuleConfigData($this, $config);
}
}
// hook getModuleConfigInputfields: thanks Pete!
// (http://processwire.com/talk/topic/1849-clearing-cache-on-module-save/)
function compileThemeLess(HookEvent $event) {
// get and init lessPHP
require "includes/lessphp/lessc.inc.php";
$less = new lessc;
$less->setFormatter("compressed");
// use input because values arent yet saved
$main_color = wire("input")->post->theme_color_main ? wire("input")->post->theme_color_main : "#444";
$accent_color = wire("input")->post->theme_color_accent ? wire("input")->post->theme_color_accent : "#e0814a";
// only compile if colors were changed
if ($main_color != wire("adminTheme")->theme_color_main || $accent_color != wire("adminTheme")->theme_color_accent ) {
$less->setVariables(array(
"main" => $main_color,
"accent" => $accent_color
));
$theme_css = $less->compileFile(
wire("config")->paths->AdminThemePalette."styles/theme.less",
wire("config")->paths->AdminThemePalette."styles/theme.css"
);
wire()->message('Palette: theme.css - compiled successfully');
}
}