Some years ago I made a web app (that I use daily)
it includes a toggle pop-up notepad,
where the save button is visible only if
new/changed text is present in the editor field.
Attached are some extracted related fragments
of the code, in case it could add any more ideas.
Code: [Local Link Removed for Guests]
#storeBut {
float: left;
background:#eae9ca;
color: #008300;
}
<div id="buttLine">
<button id="storeBut">📌 Save</button>
<button id="recallBut">Recall from saved</button>
<button id="delFieldBut">Erase text field</button>
<button id="deleteBut">Erase everything saved</button>
</div>
<script>
// these events activates logic for button display
document.getElementById("pad").addEventListener("keyup", checkStore_TfieldStatus);
document.getElementById("pad").addEventListener("touchend", checkStore_TfieldStatus);
var txtCont;
var storCont;
function retrieveStored() {
// if stored data exist, show
if (localStorage.padkey !== "") {
storCont = localStorage.padkey;
document.getElementById("pad").innerHTML = storCont;
}
// faul-fix, there is a more proper way to prevent realtime thread runaway
TimeFix();
};
function TimeFix() {
setTimeout(checkStore_TfieldStatus, 45);
};
// decide what buttons to show
function checkStore_TfieldStatus() {
storCont = localStorage.padkey;
txtCont = document.getElementById("pad").innerHTML;
// do not show the Save button if the text-field and stored content is equal,
// or if the text-field is emty
if (storCont == txtCont || txtCont == "")
{ document.getElementById("storeBut").style.visibility = "hidden";
}
else { document.getElementById("storeBut").style.visibility = "visible";
}
// --------------- Other optional buttons to show/not show --------------
// if stored data exist and the text-field is empty,
// show button for recall of stored data -
// (the textfield has to be empty before a recall)
if (storCont !== "" && txtCont == "")
{ document.getElementById("recallBut").style.visibility = "visible";
}
else { document.getElementById("recallBut").style.visibility = "hidden";
}
// if the text-field is not empty, show the button for its erase
if (txtCont !== "")
{ document.getElementById("delFieldBut").style.visibility = "visible";
}
else { document.getElementById("delFieldBut").style.visibility = "hidden";
}
// if the data store is not empty, show the button for its erase
if (storCont !== "")
{ document.getElementById("deleteBut").style.visibility = "visible";
}
else { document.getElementById("deleteBut").style.visibility = "hidden";
}
if (document.getElementById("pad").innerHTML == "undefined")
{
localStorage.padkey = "";
document.getElementById("pad").innerHTML = "Intro info in the text-field ...";
}
};
// --------------------------------------------
// -------- Button Actions --------
// Save
document.getElementById("storeBut").addEventListener("click", function() {
localStorage.padkey = document.getElementById("pad").innerHTML;
checkStore_TfieldStatus();
});
// Show Stored Data
document.getElementById("recallBut").addEventListener("click", function() {
document.getElementById("pad").innerHTML = localStorage.padkey;
checkStore_TfieldStatus();
});
// Erase the Text-field
document.getElementById("delFieldBut").addEventListener("click", function() {
document.getElementById("pad").innerHTML = "";
checkStore_TfieldStatus();
});
// Erase Stored Data
document.getElementById("deleteBut").addEventListener("click", function() {
if (confirm("Warnings ....") !== true) {
checkStore_TfieldStatus();
} else {
localStorage.padkey = "";
}
checkStore_TfieldStatus();
});
</script>