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
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Allows ✨:
7
7
- process / modify the script in a dedicated PHP class.
8
8
9
9
Extra - build in **ready-to-use** scripts:
10
-
- theme switching script
10
+
- theme switching script (two states - light/dark)
11
11
-_more coming later_
12
12
13
13
### Requirements
@@ -69,7 +69,7 @@ Inline scripts are JavaScript code blocks embedded directly into HTML documents.
69
69
</head>
70
70
```
71
71
72
-
This package makes it much more convenient by allowing you to keep inline scripts in separate JavaScript files, which enables:
72
+
This package makes it much more convenient by allowing you to keep inline scripts in separate JavaScript files, which enables ✨:
73
73
74
74
-**Complex script processing** using dedicated PHP classes _(see example below)_
75
75
-**Variable passing** from PHP to JavaScript _(see example below)_
@@ -91,6 +91,8 @@ That will copy the scripts to `resources/js/theme-switch-two-states/[theme-init.
91
91
`theme-init.js` - initializes the theme based on the user's previous choice stored in `localStorage`.
92
92
`theme-switch.js` - a function to toggle between light and dark themes by hitting a selected KEY and saves the choice in `localStorage`.
93
93
94
+
They switch theme by adding/removing a CSS class to/from the `<html>` element.
95
+
94
96
**Step 2**: Register the scripts in your `AppServiceProvider`:
95
97
96
98
```php
@@ -132,13 +134,14 @@ You can create a custom PHP class to process or modify your JavaScript code befo
132
134
133
135
Create a custom PHP processor class implementing the `RenderableScript` or `ScriptWithPlaceholders` interface and register it using the `BladeInlineScripts::take()` method.
134
136
135
-
We have prepared abstract base implementations for each of the interfaces:
137
+
I have prepared abstract base implementations for each of the interfaces:
136
138
```php
137
139
abstract class FromFile implements RenderableScript
140
+
138
141
abstract class FromFileWithPlaceholders implements ScriptWithPlaceholders
139
142
```
140
143
141
-
To show them in action, we have created PHP processors extending the base classes for the theme switch scripts:
144
+
To show them in action, I have created PHP processors extending the base classes for the theme switch scripts:
142
145
143
146
**Step 1**: Publish the built-in theme switch scripts with the PHP processor:
144
147
@@ -167,7 +170,7 @@ class AppServiceProvider extends ServiceProvider
167
170
168
171
Now hit the `d` key to toggle theme.
169
172
170
-
## Extra - get the tests for the built-in scripts and PHP processors
173
+
## Extra - get the unit tests for JS scripts and PHP processors
0 commit comments