Last active
October 28, 2016 09:12
-
-
Save ardianzzz/8037651 to your computer and use it in GitHub Desktop.
1Kb HTML5 WYSWYG Editor
This file contains hidden or 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> | |
<head> | |
<title>1Kb HTML5 WYSWYG Editor</title> | |
<style> | |
.control { | |
margin:0 0 8px; | |
} | |
#editable { | |
padding:10px; | |
border:solid 1px #ccc; | |
min-height:8em; | |
} | |
#txtLen { | |
margin:8px 0 0; | |
text-align:right; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="control"> | |
<button onclick="document.execCommand('bold',null,false);" accesskey="b"> | |
<b>Bold</b> | |
</button> | |
<button onclick="document.execCommand('italic',null,false);" accesskey="i"> | |
<i>Italic</i> | |
</button> | |
<button onclick="document.execCommand('insertUnorderedList',null,false);"> | |
Ul | |
</button> | |
<button onclick="document.execCommand('insertOrderedList',null,false);"> | |
Ol | |
</button> | |
</div> | |
<div id="editable" contenteditable="true" onfocus="countChars()" onkeydown="countChars()" onkeyup="countChars()" spellcheck="false"> | |
Write something... | |
</div> | |
<div id="txtLen">20000</div> | |
<script type="text/javascript"> | |
function countChars() { | |
var l = "20000"; | |
var str = document.getElementById("editable").textContent; | |
var len = str.length; | |
document.getElementById("txtLen").textContent=l-len; | |
if(len > l) document.getElementById("txtLen").style.color='red'; | |
else | |
document.getElementById("txtLen").style.color=''; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment