Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSS body classes for each page #1767

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,22 +1272,23 @@ void WiFiManager::startWPS() {
}
#endif

String WiFiManager::getHTTPHead(String title){
String WiFiManager::getHTTPHead(String title, String classes){
String page;
page += FPSTR(HTTP_HEAD_START);
page.replace(FPSTR(T_v), title);
page += FPSTR(HTTP_SCRIPT);
page += FPSTR(HTTP_STYLE);
page += _customHeadElement;

if(_bodyClass != ""){
String p = FPSTR(HTTP_HEAD_END);
p.replace(FPSTR(T_c), _bodyClass); // add class str
page += p;
String p = FPSTR(HTTP_HEAD_END);
if (_bodyClass != "") {
if (classes != "") {
classes += " "; // add spacing, if necessary
}
classes += _bodyClass; // add class str
}
else {
page += FPSTR(HTTP_HEAD_END);
}
p.replace(FPSTR(T_c), classes);
page += p;

return page;
}
Expand Down Expand Up @@ -1332,7 +1333,7 @@ void WiFiManager::handleRoot() {
#endif
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
handleRequest();
String page = getHTTPHead(_title); // @token options @todo replace options with title
String page = getHTTPHead(_title, FPSTR(C_root)); // @token options @todo replace options with title
String str = FPSTR(HTTP_ROOT_MAIN); // @todo custom title
str.replace(FPSTR(T_t),_title);
str.replace(FPSTR(T_v),configPortalActive ? _apName : (getWiFiHostname() + " - " + WiFi.localIP().toString())); // use ip if ap is not active for heading @todo use hostname?
Expand All @@ -1357,7 +1358,7 @@ void WiFiManager::handleWifi(boolean scan) {
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi
String page = getHTTPHead(FPSTR(S_titlewifi), FPSTR(C_wifi)); // @token titlewifi
if (scan) {
#ifdef WM_DEBUG_LEVEL
// DEBUG_WM(WM_DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh")));
Expand Down Expand Up @@ -1413,7 +1414,7 @@ void WiFiManager::handleParam(){
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi
String page = getHTTPHead(FPSTR(S_titleparam), FPSTR(C_param)); // @token titlewifi

String pitem = "";

Expand Down Expand Up @@ -1878,11 +1879,11 @@ void WiFiManager::handleWifiSave() {
String page;

if(_ssid == ""){
page = getHTTPHead(FPSTR(S_titlewifisettings)); // @token titleparamsaved
page = getHTTPHead(FPSTR(S_titlewifisettings), FPSTR(C_wifi)); // @token titleparamsaved
page += FPSTR(HTTP_PARAMSAVED);
}
else {
page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved
page = getHTTPHead(FPSTR(S_titlewifisaved), FPSTR(C_wifi)); // @token titlewifisaved
page += FPSTR(HTTP_SAVED);
}

Expand Down Expand Up @@ -1911,7 +1912,7 @@ void WiFiManager::handleParamSave() {

doParamSave();

String page = getHTTPHead(FPSTR(S_titleparamsaved)); // @token titleparamsaved
String page = getHTTPHead(FPSTR(S_titleparamsaved), FPSTR(C_param)); // @token titleparamsaved
page += FPSTR(HTTP_PARAMSAVED);
if(_showBack) page += FPSTR(HTTP_BACKBTN);
page += FPSTR(HTTP_END);
Expand Down Expand Up @@ -1977,7 +1978,7 @@ void WiFiManager::handleInfo() {
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo
String page = getHTTPHead(FPSTR(S_titleinfo), FPSTR(C_info)); // @token titleinfo
reportStatus(page);

uint16_t infos = 0;
Expand Down Expand Up @@ -2322,7 +2323,7 @@ void WiFiManager::handleExit() {
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit
String page = getHTTPHead(FPSTR(S_titleexit), FPSTR(C_exit)); // @token titleexit
page += FPSTR(S_exiting); // @token exiting
// ('Logout', 401, {'WWW-Authenticate': 'Basic realm="Login required"'})
server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache
Expand All @@ -2339,7 +2340,7 @@ void WiFiManager::handleReset() {
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset
String page = getHTTPHead(FPSTR(S_titlereset), FPSTR(C_restart)); //@token titlereset
page += FPSTR(S_resetting); //@token resetting
page += FPSTR(HTTP_END);

Expand All @@ -2364,7 +2365,7 @@ void WiFiManager::handleErase(boolean opt) {
DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase
String page = getHTTPHead(FPSTR(S_titleerase), FPSTR(C_erase)); // @token titleerase

bool ret = erase(opt);

Expand Down Expand Up @@ -2469,7 +2470,7 @@ void WiFiManager::handleClose(){
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close"));
#endif
handleRequest();
String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose
String page = getHTTPHead(FPSTR(S_titleclose), FPSTR(C_close)); // @token titleclose
page += FPSTR(S_closing); // @token closing
HTTPSend(page);
}
Expand Down Expand Up @@ -3874,7 +3875,7 @@ void WiFiManager::handleUpdate() {
DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update"));
#endif
if (captivePortal()) return; // If captive portal redirect instead of displaying the page
String page = getHTTPHead(_title); // @token options
String page = getHTTPHead(_title, FPSTR(C_update)); // @token options
String str = FPSTR(HTTP_ROOT_MAIN);
str.replace(FPSTR(T_t), _title);
str.replace(FPSTR(T_v), configPortalActive ? _apName : (getWiFiHostname() + " - " + WiFi.localIP().toString())); // use ip if ap is not active for heading
Expand Down Expand Up @@ -3984,7 +3985,7 @@ void WiFiManager::handleUpdateDone() {
DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done"));
// if (captivePortal()) return; // If captive portal redirect instead of displaying the page

String page = getHTTPHead(FPSTR(S_options)); // @token options
String page = getHTTPHead(FPSTR(S_options), FPSTR(C_update)); // @token options
String str = FPSTR(HTTP_ROOT_MAIN);
str.replace(FPSTR(T_t),_title);
str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading
Expand Down
2 changes: 1 addition & 1 deletion WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class WiFiManager
String getIpForm(String id, String title, String value);
String getScanItemOut();
String getStaticOut();
String getHTTPHead(String title);
String getHTTPHead(String title, String classes = "");
String getMenuOut();
//helpers
boolean isIp(String str);
Expand Down
13 changes: 13 additions & 0 deletions wm_consts_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static PGM_P _menutokens[] PROGMEM = {
const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P));


// Routes
const char R_root[] PROGMEM = "/";
const char R_wifi[] PROGMEM = "/wifi";
const char R_wifinoscan[] PROGMEM = "/0wifi";
Expand All @@ -62,6 +63,18 @@ const char R_update[] PROGMEM = "/update";
const char R_updatedone[] PROGMEM = "/u";


// Classes
const char C_root[] PROGMEM = "home";
const char C_wifi[] PROGMEM = "wifi";
const char C_info[] PROGMEM = "info";
const char C_param[] PROGMEM = "param";
const char C_close[] PROGMEM = "close";
const char C_restart[] PROGMEM = "restart";
const char C_exit[] PROGMEM = "exit";
const char C_erase[] PROGMEM = "erase";
const char C_update[] PROGMEM = "update";


//Strings
const char S_ip[] PROGMEM = "ip";
const char S_gw[] PROGMEM = "gw";
Expand Down
13 changes: 13 additions & 0 deletions wm_consts_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static PGM_P _menutokens[] PROGMEM = {
const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P));


// Routes
const char R_root[] PROGMEM = "/";
const char R_wifi[] PROGMEM = "/wifi";
const char R_wifinoscan[] PROGMEM = "/0wifi";
Expand All @@ -63,6 +64,18 @@ const char R_update[] PROGMEM = "/update";
const char R_updatedone[] PROGMEM = "/u";


// Classes
const char C_root[] PROGMEM = "home";
const char C_wifi[] PROGMEM = "wifi";
const char C_info[] PROGMEM = "info";
const char C_param[] PROGMEM = "param";
const char C_close[] PROGMEM = "close";
const char C_restart[] PROGMEM = "restart";
const char C_exit[] PROGMEM = "exit";
const char C_erase[] PROGMEM = "erase";
const char C_update[] PROGMEM = "update";


//Strings
const char S_ip[] PROGMEM = "ip";
const char S_gw[] PROGMEM = "gw";
Expand Down