-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contenteditable sections and url saving
* Add contenteditable sections and url saving This allows for editing inline various pieces of content which will then save the content to the url which allows it to be shared with the url with the new content on the page. This does not actually save data anywhere.
- Loading branch information
Showing
7 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,5 +148,6 @@ | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" | ||
crossorigin="anonymous"></script> | ||
<script src="static/editable.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
document.querySelectorAll("[data-mlcedit]").forEach(function (el) { | ||
const isEditable = el.isContentEditable; | ||
el.contentEditable = !isEditable; | ||
}); | ||
|
||
function updateURL() { | ||
const edits = {}; | ||
document.querySelectorAll("[data-mlcedit]").forEach((el) => { | ||
const id = el.getAttribute("data-mlcedit"); | ||
edits[id] = encodeURIComponent(el.innerHTML); | ||
}); | ||
const newUrl = `${location.pathname}?${new URLSearchParams( | ||
edits, | ||
).toString()}`; | ||
history.pushState({}, "", newUrl); | ||
} | ||
|
||
document.querySelectorAll("[data-mlcedit]").forEach((el) => { | ||
["blur", "change", "keyup"].forEach((event) => { | ||
el.addEventListener(event, updateURL); | ||
}); | ||
}); | ||
|
||
function loadEdits() { | ||
const params = new URLSearchParams(window.location.search); | ||
params.forEach((value, key) => { | ||
const el = document.querySelector(`[data-mlcedit="${key}"]`); | ||
if (el) { | ||
el.innerHTML = decodeURIComponent(value); | ||
} | ||
}); | ||
} | ||
|
||
loadEdits(); | ||
}); |