mirror of
https://github.com/s00500/ESPUI.git
synced 2025-11-27 23:03:16 +00:00
Add instructions to README
This commit is contained in:
27
README.md
27
README.md
@@ -667,6 +667,33 @@ All the example sketches include the DNS related code and will work as captive p
|
||||
ESPUI.captivePortal = false;
|
||||
```
|
||||
|
||||
### User-defined JavaScript
|
||||
|
||||
You can add your own custom JavaScript to the UI. This allows you to create custom controls, handle events, or otherwise extend the functionality of the UI.
|
||||
|
||||
To add custom JavaScript, call `ESPUI.setCustomJS()` before `ESPUI.begin()`. The argument to `setCustomJS()` is a C-string containing the JavaScript code. This string must remain valid for the lifetime of the ESPUIClass instance.
|
||||
|
||||
```cpp
|
||||
const char* myCustomJS = "alert('Hello from custom JS!');";
|
||||
|
||||
void setup() {
|
||||
// ...
|
||||
ESPUI.setCustomJS(myCustomJS);
|
||||
ESPUI.begin("ESPUI Control");
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
The custom JavaScript is served at `/js/custom.js` and is automatically included in the `index.htm` file. You can use this to interact with the UI elements, handle events, and create new UI components. For example, you can use `zepto.js` to listen for clicks on a button:
|
||||
|
||||
```cpp
|
||||
const char* myCustomJS = R"=====(
|
||||
$(document).on('click', '#my-button', function() {
|
||||
alert('Button clicked!');
|
||||
});
|
||||
)=====";
|
||||
```
|
||||
|
||||
|
||||
# Notes for Development
|
||||
|
||||
|
||||
Reference in New Issue
Block a user