1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Traits; |
4
|
|
|
|
5
|
|
|
trait HasAssets |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var array |
9
|
|
|
*/ |
10
|
|
|
public static $script = []; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
public static $style = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
public static $css = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
public static $js = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
public static $headerJs = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public static $manifest = 'vendor/laravel-admin/minify-manifest.json'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
public static $manifestData = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
public static $min = [ |
46
|
|
|
'js' => 'vendor/laravel-admin/laravel-admin.min.js', |
47
|
|
|
'css' => 'vendor/laravel-admin/laravel-admin.min.css', |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public static $baseCss = [ |
54
|
|
|
'vendor/laravel-admin/AdminLTE/bootstrap/css/bootstrap.min.css', |
55
|
|
|
'vendor/laravel-admin/font-awesome/css/font-awesome.min.css', |
56
|
|
|
'vendor/laravel-admin/laravel-admin/laravel-admin.css', |
57
|
|
|
'vendor/laravel-admin/nprogress/nprogress.css', |
58
|
|
|
'vendor/laravel-admin/sweetalert2/dist/sweetalert2.css', |
59
|
|
|
'vendor/laravel-admin/nestable/nestable.css', |
60
|
|
|
'vendor/laravel-admin/toastr/build/toastr.min.css', |
61
|
|
|
'vendor/laravel-admin/bootstrap3-editable/css/bootstrap-editable.css', |
62
|
|
|
'vendor/laravel-admin/google-fonts/fonts.css', |
63
|
|
|
'vendor/laravel-admin/AdminLTE/dist/css/AdminLTE.min.css', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var array |
68
|
|
|
*/ |
69
|
|
|
public static $baseJs = [ |
70
|
|
|
'vendor/laravel-admin/AdminLTE/bootstrap/js/bootstrap.min.js', |
71
|
|
|
'vendor/laravel-admin/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js', |
72
|
|
|
'vendor/laravel-admin/AdminLTE/dist/js/app.min.js', |
73
|
|
|
'vendor/laravel-admin/jquery-pjax/jquery.pjax.js', |
74
|
|
|
'vendor/laravel-admin/nprogress/nprogress.js', |
75
|
|
|
'vendor/laravel-admin/nestable/jquery.nestable.js', |
76
|
|
|
'vendor/laravel-admin/toastr/build/toastr.min.js', |
77
|
|
|
'vendor/laravel-admin/bootstrap3-editable/js/bootstrap-editable.min.js', |
78
|
|
|
'vendor/laravel-admin/sweetalert2/dist/sweetalert2.min.js', |
79
|
|
|
'vendor/laravel-admin/laravel-admin/laravel-admin.js', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
public static $jQuery = 'vendor/laravel-admin/AdminLTE/plugins/jQuery/jQuery-2.1.4.min.js'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Add css or get all css. |
89
|
|
|
* |
90
|
|
|
* @param null $css |
91
|
|
|
* |
92
|
|
|
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public static function css($css = null) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
if (!is_null($css)) { |
97
|
|
|
return self::$css = array_merge(self::$css, (array) $css); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (!$css = static::getMinifiedCss()) { |
101
|
|
|
$css = array_merge(static::$css, static::baseCss()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$css = array_filter(array_unique($css)); |
105
|
|
|
|
106
|
|
|
return view('admin::partials.css', compact('css')); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param null $css |
111
|
|
|
* |
112
|
|
|
* @return array|null |
113
|
|
|
*/ |
114
|
|
|
public static function baseCss($css = null) |
115
|
|
|
{ |
116
|
|
|
if (!is_null($css)) { |
117
|
|
|
return static::$baseCss = $css; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$skin = config('admin.skin', 'skin-blue-light'); |
121
|
|
|
|
122
|
|
|
array_unshift(static::$baseCss, "vendor/laravel-admin/AdminLTE/dist/css/skins/{$skin}.min.css"); |
123
|
|
|
|
124
|
|
|
return static::$baseCss; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Add js or get all js. |
129
|
|
|
* |
130
|
|
|
* @param null $js |
131
|
|
|
* |
132
|
|
|
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
133
|
|
|
*/ |
134
|
|
View Code Duplication |
public static function js($js = null) |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
if (!is_null($js)) { |
137
|
|
|
return self::$js = array_merge(self::$js, (array) $js); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if (!$js = static::getMinifiedJs()) { |
141
|
|
|
$js = array_merge(static::baseJs(), static::$js); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$js = array_filter(array_unique($js)); |
145
|
|
|
|
146
|
|
|
return view('admin::partials.js', compact('js')); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Add js or get all js. |
151
|
|
|
* |
152
|
|
|
* @param null $js |
153
|
|
|
* |
154
|
|
|
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
155
|
|
|
*/ |
156
|
|
|
public static function headerJs($js = null) |
157
|
|
|
{ |
158
|
|
|
if (!is_null($js)) { |
159
|
|
|
return self::$headerJs = array_merge(self::$headerJs, (array) $js); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return view('admin::partials.js', ['js' => array_unique(static::$headerJs)]); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param null $js |
167
|
|
|
* |
168
|
|
|
* @return array|null |
169
|
|
|
*/ |
170
|
|
|
public static function baseJs($js = null) |
171
|
|
|
{ |
172
|
|
|
if (!is_null($js)) { |
173
|
|
|
return static::$baseJs = $js; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return static::$baseJs; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $script |
181
|
|
|
* |
182
|
|
|
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
183
|
|
|
*/ |
184
|
|
View Code Duplication |
public static function script($script = '') |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
if (!empty($script)) { |
187
|
|
|
return self::$script = array_merge(self::$script, (array) $script); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return view('admin::partials.script', ['script' => array_unique(self::$script)]); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param string $style |
195
|
|
|
* |
196
|
|
|
* @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View |
197
|
|
|
*/ |
198
|
|
View Code Duplication |
public static function style($style = '') |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
if (!empty($style)) { |
201
|
|
|
return self::$style = array_merge(self::$style, (array) $style); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return view('admin::partials.style', ['style' => array_unique(self::$style)]); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string $key |
209
|
|
|
* |
210
|
|
|
* @return mixed |
211
|
|
|
*/ |
212
|
|
|
protected static function getManifestData($key) |
213
|
|
|
{ |
214
|
|
|
if (!empty(static::$manifestData)) { |
215
|
|
|
return static::$manifestData[$key]; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
static::$manifestData = json_decode( |
219
|
|
|
file_get_contents(public_path(static::$manifest)), true |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
return static::$manifestData[$key]; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return bool|mixed |
227
|
|
|
*/ |
228
|
|
View Code Duplication |
protected static function getMinifiedCss() |
|
|
|
|
229
|
|
|
{ |
230
|
|
|
if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) { |
231
|
|
|
return false; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
return static::getManifestData('css'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return bool|mixed |
239
|
|
|
*/ |
240
|
|
View Code Duplication |
protected static function getMinifiedJs() |
|
|
|
|
241
|
|
|
{ |
242
|
|
|
if (!config('admin.minify_assets') || !file_exists(public_path(static::$manifest))) { |
243
|
|
|
return false; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
return static::getManifestData('js'); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return string |
251
|
|
|
*/ |
252
|
|
|
public function jQuery() |
253
|
|
|
{ |
254
|
|
|
return admin_asset(static::$jQuery); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.