Last active
April 24, 2023 17:45
-
-
Save tararoys/2fa6581a485f8ab152a5f10a83b40c79 to your computer and use it in GitHub Desktop.
PoypbMX
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
<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> |
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
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