The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far. The sciences, each straining in its own direction, have hitherto harmed us little; but some day the piecing together of dissociated knowledge will open up such terrifying vistas of reality, and of our frightful position therein, that we shall either go mad from the revelation or flee from the deadly light into the peace and safety of a new dark age.
this is execCommand :
The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far. The sciences, each straining in its own direction, have hitherto harmed us little; but some day the piecing together of dissociated knowledge will open up such terrifying vistas of reality, and of our frightful position therein, that we shall either go mad from the revelation or flee from the deadly light into the peace and safety of a new dark age.
the code is simple
var demoBtns = document.querySelectorAll( "button.demo-ec" );
for ( var i = 0; i < demoBtns.length; i++ ) {
demoBtns[i].addEventListener( "click", function( e ) {
document.execCommand( this.innerText );
return false;
});
}
current selection can affect whether commands work
same commands produce different markup in different browsers
values may not be faithfully appended
values may be quietly rejected
none of this is documented like.. anywhere
useful exercise:
add a class to an element in a contenteditable area
The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of infinity, and it was not meant that we should voyage far. The sciences, each straining in its own direction, have hitherto harmed us little; but some day the piecing together of dissociated knowledge will open up such terrifying vistas of reality, and of our frightful position therein, that we shall either go mad from the revelation or flee from the deadly light into the peace and safety of a new dark age.
let's talk about what works
traditional "marking up"
lists, indentation
undo, redo, basic selection control
colors and fonts (even though they shouldn't)
how about what's generated?
generally, tags as expected
IE uses strong and em
non-standard commands get a span with inline style
..except in IE, where they get a font tag
how about what's MAGICALLY generated
blocks, y'all
maybe it's a div, maybe it's a p !
maybe it's nothing at all
can be changed if formatBlock works
..but it doesn't in IE
..and only allows HTML4 block elements in FF
..and your formatted block might still be wrapped in the default
the (standard) commands in detail
works as expected
bold, italic, subscript, superscript
createLink, unlink
delete, forwardDelete (except IE)
insertOrderedList, insertUnorderedList
formatBlock
accepts tags only
no attributes
finite list of options in FF
no support in IE
alters default block type of subsequent blocks added by pressing enter