1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte\Helpers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\View; |
6
|
|
|
|
7
|
|
|
class LayoutHelper |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Set of tokens related to screen sizes. |
11
|
|
|
* |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected static $screenSizes = ['xs', 'sm', 'md', 'lg', 'xl']; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Check if layout topnav is enabled. |
18
|
|
|
* |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
10 |
|
public static function isLayoutTopnavEnabled() |
22
|
|
|
{ |
23
|
10 |
|
return config('adminlte.layout_topnav') || View::getSection('layout_topnav'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Check if layout boxed is enabled. |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
10 |
|
public static function isLayoutBoxedEnabled() |
32
|
|
|
{ |
33
|
10 |
|
return config('adminlte.layout_boxed') || View::getSection('layout_boxed'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Make and return the set of classes related to the body tag. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
10 |
|
public static function makeBodyClasses() |
42
|
|
|
{ |
43
|
10 |
|
$classes = []; |
44
|
|
|
|
45
|
10 |
|
$classes = array_merge($classes, self::makeLayoutClasses()); |
46
|
10 |
|
$classes = array_merge($classes, self::makeSidebarClasses()); |
47
|
10 |
|
$classes = array_merge($classes, self::makeRightSidebarClasses()); |
48
|
10 |
|
$classes = array_merge($classes, self::makeCustomBodyClasses()); |
49
|
|
|
|
50
|
10 |
|
return trim(implode(' ', $classes)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Make and return the set of data attributes related to the body tag. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
1 |
|
public static function makeBodyData() |
59
|
|
|
{ |
60
|
1 |
|
$data = []; |
61
|
|
|
|
62
|
|
|
// Add data related to the "sidebar_scrollbar_theme" configuration. |
63
|
|
|
|
64
|
1 |
|
$sb_theme_cfg = config('adminlte.sidebar_scrollbar_theme', 'os-theme-light'); |
65
|
|
|
|
66
|
1 |
|
if ($sb_theme_cfg != 'os-theme-light') { |
67
|
1 |
|
$data[] = 'data-scrollbar-theme='.$sb_theme_cfg; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// Add data related to the "sidebar_scrollbar_auto_hide" configuration. |
71
|
|
|
|
72
|
1 |
|
$sb_auto_hide = config('adminlte.sidebar_scrollbar_auto_hide', 'l'); |
73
|
|
|
|
74
|
1 |
|
if ($sb_auto_hide != 'l') { |
75
|
1 |
|
$data[] = 'data-scrollbar-auto-hide='.$sb_auto_hide; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
return trim(implode(' ', $data)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Make and return the set of classes related to the layout configuration. |
83
|
|
|
* |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
10 |
|
private static function makeLayoutClasses() |
87
|
|
|
{ |
88
|
10 |
|
$classes = []; |
89
|
|
|
|
90
|
|
|
// Add classes related to the "layout_topnav" configuration. |
91
|
|
|
|
92
|
10 |
|
if (self::isLayoutTopnavEnabled()) { |
93
|
2 |
|
$classes[] = 'layout-top-nav'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Add classes related to the "layout_boxed" configuration. |
97
|
|
|
|
98
|
10 |
|
if (self::isLayoutBoxedEnabled()) { |
99
|
3 |
|
$classes[] = 'layout-boxed'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
// Add classes related to fixed sidebar layout configuration. The fixed |
103
|
|
|
// sidebar is not compatible with layout topnav. |
104
|
|
|
|
105
|
10 |
|
if (! self::isLayoutTopnavEnabled() && config('adminlte.layout_fixed_sidebar')) { |
106
|
1 |
|
$classes[] = 'layout-fixed'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// Add classes related to fixed navbar/footer configuration. The fixed |
110
|
|
|
// navbar/footer is not compatible with layout boxed. |
111
|
|
|
|
112
|
10 |
|
if (! self::isLayoutBoxedEnabled()) { |
113
|
10 |
|
$classes = array_merge($classes, self::makeFixedResponsiveClasses('navbar')); |
114
|
10 |
|
$classes = array_merge($classes, self::makeFixedResponsiveClasses('footer')); |
115
|
|
|
} |
116
|
|
|
|
117
|
10 |
|
return $classes; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Make the set of classes related to a fixed responsive configuration. |
122
|
|
|
* |
123
|
|
|
* @param string $section (navbar or footer) |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
10 |
|
private static function makeFixedResponsiveClasses($section) |
127
|
|
|
{ |
128
|
10 |
|
$classes = []; |
129
|
10 |
|
$cfg = config('adminlte.layout_fixed_'.$section); |
130
|
|
|
|
131
|
10 |
|
if ($cfg === true) { |
132
|
2 |
|
$cfg = ['xs' => true]; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// At this point the config should be an array. |
136
|
|
|
|
137
|
10 |
|
if (! is_array($cfg)) { |
138
|
10 |
|
return $classes; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// Make the set of responsive classes in relation to the config. |
142
|
|
|
|
143
|
2 |
|
foreach ($cfg as $size => $enabled) { |
144
|
2 |
|
if (in_array($size, self::$screenSizes)) { |
145
|
2 |
|
$size = ($size === 'xs') ? $section : "{$size}-{$section}"; |
146
|
2 |
|
$fixed = $enabled ? 'fixed' : 'not-fixed'; |
147
|
2 |
|
$classes[] = "layout-{$size}-{$fixed}"; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
2 |
|
return $classes; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Make the set of classes related to the left sidebar configuration. |
156
|
|
|
* |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
10 |
|
private static function makeSidebarClasses() |
160
|
|
|
{ |
161
|
10 |
|
$classes = []; |
162
|
|
|
|
163
|
|
|
// Add classes related to the "sidebar_mini" configuration. |
164
|
|
|
|
165
|
10 |
|
if (config('adminlte.sidebar_mini', true) === true) { |
166
|
10 |
|
$classes[] = 'sidebar-mini'; |
167
|
1 |
|
} elseif (config('adminlte.sidebar_mini', true) == 'md') { |
168
|
1 |
|
$classes[] = 'sidebar-mini sidebar-mini-md'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Add classes related to the "sidebar_collapse" configuration. |
172
|
|
|
|
173
|
10 |
|
if (config('adminlte.sidebar_collapse') || View::getSection('sidebar_collapse')) { |
174
|
1 |
|
$classes[] = 'sidebar-collapse'; |
175
|
|
|
} |
176
|
|
|
|
177
|
10 |
|
return $classes; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Make the set of classes related to the right sidebar configuration. |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
10 |
|
private static function makeRightSidebarClasses() |
186
|
|
|
{ |
187
|
10 |
|
$classes = []; |
188
|
|
|
|
189
|
|
|
// Add classes related to the "right_sidebar" configuration. |
190
|
|
|
|
191
|
10 |
|
if (config('adminlte.right_sidebar') && config('adminlte.right_sidebar_push')) { |
192
|
1 |
|
$classes[] = 'control-sidebar-push'; |
193
|
|
|
} |
194
|
|
|
|
195
|
10 |
|
return $classes; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Make the set of classes related to custom body classes configuration. |
200
|
|
|
* |
201
|
|
|
* @return array |
202
|
|
|
*/ |
203
|
10 |
|
private static function makeCustomBodyClasses() |
204
|
|
|
{ |
205
|
10 |
|
$classes = []; |
206
|
10 |
|
$cfg = config('adminlte.classes_body', ''); |
207
|
|
|
|
208
|
10 |
|
if (is_string($cfg) && $cfg) { |
209
|
1 |
|
$classes[] = $cfg; |
210
|
|
|
} |
211
|
|
|
|
212
|
10 |
|
return $classes; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|