1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00

Don'tr estore content if there's something in the editor already.

This commit is contained in:
Starbeamrainbowlabs 2016-10-22 16:48:21 +01:00
parent d3b6b1c54e
commit b7b34bff16
3 changed files with 9 additions and 5 deletions

View file

@ -3853,12 +3853,14 @@ register_module([
$content .= <<<SMARTSAVE
<!-- Smart saving script -->
<script>
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").trim(); }
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
document.querySelector("textarea[name=content]").value = localStorage.getItem(getSmartSaveKey());
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don't restore if there's data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
});
</script>
SMARTSAVE;

View file

@ -122,7 +122,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1477150472,
"lastupdate": 1477151244,
"optional": false
},
{

View file

@ -107,12 +107,14 @@ register_module([
$content .= <<<SMARTSAVE
<!-- Smart saving script -->
<script>
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").trim(); }
function getSmartSaveKey() { return document.querySelector("main h1").innerHTML.replace("Creating ", "").replace("Editing ", "").trim(); }
// Saving
document.querySelector("textarea[name=content]").addEventListener("keyup", function(event) { window.localStorage.setItem(getSmartSaveKey(), event.target.value) });
// Loading
window.addEventListener("load", function(event) {
document.querySelector("textarea[name=content]").value = localStorage.getItem(getSmartSaveKey());
var editor = document.querySelector("textarea[name=content]");
if(editor.value.length > 0) return; // Don't restore if there's data in the editor already
editor.value = localStorage.getItem(getSmartSaveKey());
});
</script>
SMARTSAVE;