You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,24 @@ This package makes it much more convenient by allowing you to keep inline script
83
83
-**Unit testing** : your JavaScript code using tools like Vitest or Jest _(see [bonus section](#bonus))_
84
84
-**IDE support** : with syntax highlighting and error detection in dedicated JS files _(see [example bellow](#using-js-code-directly))_
85
85
86
+
## Advanced Usage: Custom Script Processing
87
+
88
+
Want to do more advanced processing of your JavaScript code before inlining it?
89
+
90
+
Create a PHP class:
91
+
- that implements the `RenderableScript` interface - using it you can fetch / prepare / create JS code in any way you want;
92
+
- and place it in `BladeInlineScripts::take(...)` method.
93
+
94
+
Use interface `ScriptWithPlaceholders` for scripts with placeholders to be replaced with variables.
95
+
96
+
Want to load JS code from a file? Extend the abstract class `FromFile` or `FromFileWithPlaceholders`.
97
+
98
+
```php
99
+
abstract class FromFile implements RenderableScript;
100
+
101
+
abstract class FromFileWithPlaceholders implements ScriptWithPlaceholders;
102
+
```
103
+
86
104
# Explanation Through Example: Color scheme switch script
87
105
88
106
Modern websites often provide users with the ability to switch between light and dark themes. In such cases, you might want to remember the user's choice using `localStorage` and apply the selected theme on page load. To avoid **FOUC** (Flash of Unstyled Content), you can use _inline script_ to set the theme before the page fully loads.
@@ -195,24 +213,6 @@ Select the one that suits your frontend and insert it in your template:
0 commit comments