mirror of
https://github.com/s00500/ESPUI.git
synced 2025-11-27 23:03:16 +00:00
Add ability to set custom js at /js/custom.js
This commit is contained in:
@@ -17,6 +17,15 @@
|
|||||||
#include <umm_malloc/umm_heap_select.h>
|
#include <umm_malloc/umm_heap_select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char* customJS = nullptr;
|
||||||
|
|
||||||
|
// Set custom JavaScript to be included in the UI.
|
||||||
|
// js: JavaScript code as a String or C-string. Must remain valid for the lifetime of the ESPUIClass instance.
|
||||||
|
void ESPUIClass::setCustomJS(const char* js)
|
||||||
|
{
|
||||||
|
customJS = js;
|
||||||
|
}
|
||||||
|
|
||||||
static String heapInfo(const __FlashStringHelper* mode)
|
static String heapInfo(const __FlashStringHelper* mode)
|
||||||
{
|
{
|
||||||
String result;
|
String result;
|
||||||
@@ -1272,6 +1281,15 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas
|
|||||||
yield();
|
yield();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server->on("/js/custom.js", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
if (ESPUI.basicAuth && !request->authenticate(ESPUI.basicAuthUsername, ESPUI.basicAuthPassword))
|
||||||
|
{
|
||||||
|
return request->requestAuthentication();
|
||||||
|
}
|
||||||
|
|
||||||
|
request->send(200, "application/javascript", customJS ? customJS : "");
|
||||||
|
});
|
||||||
|
|
||||||
server->begin();
|
server->begin();
|
||||||
|
|
||||||
#if defined(DEBUG_ESPUI)
|
#if defined(DEBUG_ESPUI)
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ public:
|
|||||||
|
|
||||||
void updateVisibility(uint16_t id, bool visibility, int clientId = -1);
|
void updateVisibility(uint16_t id, bool visibility, int clientId = -1);
|
||||||
|
|
||||||
|
// Set optional global custom JavaScript to be included in the UI.
|
||||||
|
void setCustomJS(const char* js);
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
const char* ui_title = "ESPUI"; // Store UI Title and Header Name
|
||||||
Control* controls = nullptr;
|
Control* controls = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user