Skip to content

Instantly share code, notes, and snippets.

@tararoys
Last active April 24, 2023 17:45
Show Gist options
  • Save tararoys/2fa6581a485f8ab152a5f10a83b40c79 to your computer and use it in GitHub Desktop.
Save tararoys/2fa6581a485f8ab152a5f10a83b40c79 to your computer and use it in GitHub Desktop.
PoypbMX
<html>
<script>
window.addEventListener("load", function () {
var editbox = document.getElementById("elm_editable");
editbox.addEventListener("input", (e) => {
// and here is how to detect the enter key
var last_character = e.currentTarget.innerText.charAt(
e.currentTarget.innerText.length - 1
);
if ("." === last_character || '?' === last_character || "!" === last_character) {
e.target.removeAttribute("contenteditable");
var para = document.createElement("p");
para.contentEditable = "true";
editbox.appendChild(para);
para.focus();
}
});
});
</script>
</head>
<body>
<a onclick="this.href='data:text/html;charset=UTF-8,'+encodeURIComponent(document.documentElement.outerHTML)" href="#" download="page.html">Download</a>
<div id="elm_editable">
<p class="box" contenteditable="true" id="editable">
text
</p>
</div>
</body>
</html>
window.addEventListener("load", function () {
var editbox = document.getElementById("elm_editable");
editbox.addEventListener("input", (e) => {
// and here is how to detect the enter key
var last_character = e.currentTarget.innerText.charAt(
e.currentTarget.innerText.length - 1
);
if ("." === last_character || '?' === last_character || "!" === last_character) {
e.target.removeAttribute("contenteditable");
var para = document.createElement("p");
para.contentEditable = "true";
editbox.appendChild(para);
para.focus();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment