@@ -57,8 +57,8 @@ class Assets
57
57
/**
58
58
* Assets constructor.
59
59
*
60
- * @param Repository $config
61
- * @param HtmlBuilder $htmlBuilder
60
+ * @param Repository $config
61
+ * @param HtmlBuilder $htmlBuilder
62
62
*/
63
63
public function __construct (Repository $ config , HtmlBuilder $ htmlBuilder )
64
64
{
@@ -74,7 +74,7 @@ public function __construct(Repository $config, HtmlBuilder $htmlBuilder)
74
74
/**
75
75
* Add scripts to current module.
76
76
*
77
- * @param array $assets
77
+ * @param array $assets
78
78
* @return $this
79
79
*/
80
80
public function addScripts ($ assets )
@@ -87,7 +87,7 @@ public function addScripts($assets)
87
87
/**
88
88
* Add Css to current module.
89
89
*
90
- * @param string[] $assets
90
+ * @param string[] $assets
91
91
* @return $this
92
92
*/
93
93
public function addStyles ($ assets )
@@ -100,14 +100,14 @@ public function addStyles($assets)
100
100
/**
101
101
* Add styles directly.
102
102
*
103
- * @param array|string $assets
103
+ * @param array|string $assets
104
104
* @return $this
105
105
*/
106
106
public function addStylesDirectly ($ assets )
107
107
{
108
108
foreach ((array )$ assets as &$ item ) {
109
109
$ item = ltrim (trim ($ item ), '/ ' );
110
-
110
+
111
111
if (!in_array ($ item , $ this ->appendedStyles )) {
112
112
$ this ->appendedStyles [$ item ] = [
113
113
'src ' => $ item ,
@@ -122,8 +122,8 @@ public function addStylesDirectly($assets)
122
122
/**
123
123
* Add scripts directly.
124
124
*
125
- * @param string|array $assets
126
- * @param string $location
125
+ * @param string|array $assets
126
+ * @param string $location
127
127
* @return $this
128
128
*/
129
129
public function addScriptsDirectly ($ assets , $ location = self ::ASSETS_SCRIPT_POSITION_FOOTER )
@@ -145,7 +145,7 @@ public function addScriptsDirectly($assets, $location = self::ASSETS_SCRIPT_POSI
145
145
/**
146
146
* Remove Css to current module.
147
147
*
148
- * @param array $assets
148
+ * @param array $assets
149
149
* @return $this
150
150
*/
151
151
public function removeStyles ($ assets )
@@ -169,7 +169,7 @@ public function removeStyles($assets)
169
169
/**
170
170
* Add scripts.
171
171
*
172
- * @param array $assets
172
+ * @param array $assets
173
173
* @return $this
174
174
*/
175
175
public function removeScripts ($ assets )
@@ -190,10 +190,33 @@ public function removeScripts($assets)
190
190
return $ this ;
191
191
}
192
192
193
+ /**
194
+ * Remove script/style items directly.
195
+ *
196
+ * @param array|string $assets
197
+ * @param string|null $location `header` or `footer`
198
+ * @return $this
199
+ */
200
+ public function removeItemDirectly ($ assets , ?string $ location = null )
201
+ {
202
+ foreach ((array )$ assets as $ item ) {
203
+ $ item = ltrim (trim ($ item ), '/ ' );
204
+
205
+ if ($ location && in_array ($ location , [self ::ASSETS_SCRIPT_POSITION_HEADER , self ::ASSETS_SCRIPT_POSITION_FOOTER ])) {
206
+ Arr::forget ($ this ->appendedScripts [$ location ], $ item );
207
+ } else {
208
+ Arr::forget ($ this ->appendedScripts [self ::ASSETS_SCRIPT_POSITION_HEADER ], $ item );
209
+ Arr::forget ($ this ->appendedScripts [self ::ASSETS_SCRIPT_POSITION_FOOTER ], $ item );
210
+ }
211
+ }
212
+
213
+ return $ this ;
214
+ }
215
+
193
216
/**
194
217
* Get All scripts in current module.
195
218
*
196
- * @param string $location `header` or `footer`
219
+ * @param string $location `header` or `footer`
197
220
* @return array
198
221
*/
199
222
public function getScripts ($ location = null )
@@ -218,7 +241,7 @@ public function getScripts($location = null)
218
241
/**
219
242
* Get All CSS in current module.
220
243
*
221
- * @param array $lastStyles Append last CSS to current module
244
+ * @param array $lastStyles Append last CSS to current module
222
245
* @return array
223
246
*/
224
247
public function getStyles ($ lastStyles = [])
@@ -242,8 +265,8 @@ public function getStyles($lastStyles = [])
242
265
/**
243
266
* Convert script to html.
244
267
*
245
- * @param string $name
246
- * @return string|null
268
+ * @param string $name
269
+ * @return string|null
247
270
*/
248
271
public function scriptToHtml ($ name )
249
272
{
@@ -253,7 +276,7 @@ public function scriptToHtml($name)
253
276
/**
254
277
* Convert style to html.
255
278
*
256
- * @param string $name
279
+ * @param string $name
257
280
*/
258
281
public function styleToHtml ($ name )
259
282
{
@@ -263,9 +286,9 @@ public function styleToHtml($name)
263
286
/**
264
287
* Get script item.
265
288
*
266
- * @param string $location
267
- * @param string $configName
268
- * @param string $script
289
+ * @param string $location
290
+ * @param string $configName
291
+ * @param string $script
269
292
* @return array
270
293
*/
271
294
protected function getScriptItem ($ location , $ configName , $ script )
@@ -282,8 +305,8 @@ protected function getScriptItem($location, $configName, $script)
282
305
/**
283
306
* Convert item to html.
284
307
*
285
- * @param string $name
286
- * @param string $type
308
+ * @param string $name
309
+ * @param string $type
287
310
* @return string
288
311
*/
289
312
protected function itemToHtml ($ name , $ type = 'style ' )
@@ -310,7 +333,7 @@ protected function itemToHtml($name, $type = 'style')
310
333
}
311
334
312
335
/**
313
- * @param string $configName
336
+ * @param string $configName
314
337
* @return string|array
315
338
*/
316
339
protected function getSourceUrl ($ configName )
@@ -329,7 +352,7 @@ protected function getSourceUrl($configName)
329
352
}
330
353
331
354
/**
332
- * @param string $configName
355
+ * @param string $configName
333
356
* @return bool
334
357
*/
335
358
protected function isUsingCdn ($ configName )
@@ -338,8 +361,8 @@ protected function isUsingCdn($configName)
338
361
}
339
362
340
363
/**
341
- * @param string $configName
342
- * @param string $location
364
+ * @param string $configName
365
+ * @param string $location
343
366
* @return array
344
367
*/
345
368
protected function getSource ($ configName , $ location = null )
@@ -396,8 +419,9 @@ public function getHtmlBuilder()
396
419
/**
397
420
* Render assets to header.
398
421
*
399
- * @param array $lastStyles
422
+ * @param array $lastStyles
400
423
* @return string
424
+ *
401
425
* @throws \Throwable
402
426
*/
403
427
public function renderHeader ($ lastStyles = [])
@@ -413,6 +437,7 @@ public function renderHeader($lastStyles = [])
413
437
* Render assets to footer.
414
438
*
415
439
* @return string
440
+ *
416
441
* @throws \Throwable
417
442
*/
418
443
public function renderFooter ()
0 commit comments