Thank you for the demo code, excellent for finding out about contenteditable commands.
I found a couple of bugs:
The code which passed the value to the execCommand was at fault
val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "";
document.execCommand(cmd.cmd, false, (cmd.val || ""));
val = (typeof cmd.val !== "undefined") ? prompt("Value for " + cmd.cmd + "?", cmd.val) : "" ;
document.execCommand(cmd.cmd, false, (val || ""));
The definition for formatBlock in the array did not specify a value, but formatBlock needs a value to know which tag to use ie: <div> <h1> etc.
So the definition of formatBlock in the array changes from:
"desc": "Adds an HTML block-style tag around the line ..."
"desc": "Adds an HTML block-style tag around the line ..."</div>
Thank you Kev
You have increased the level of quality in my pen by finding and helping fix a couple of bugs! I have fixed them and now two features actually do what they should :-)
This is one of the awesomest things I've seen in CodePen. And using vanilla JS which is more awesome. Could you provide some ideas on how one would go about saving the changes? I'm thinking I would save them as an array in localStorage at least.
Need to know how to enable it? Go here.