I am making a WYSIWYG editor from scratch using execCommand(). I want to disable my formatting buttons (alignment, bold, italicize, underline, color, size, family, etc) when the user has no text selected.
I have the document code inside of an IFRAME, and outside of the IFRAME are the buttons/scripts. I made the iframe's document contentEditable and turned designMode on.
What exactly can I do to find out if any text is selected?
If possible, how can I find out if the user has their cursor anywhere inside of a DIV element for text alignment? I am sure I could use this to detect if the cursor is inside of an already-bolded text or similar, too.
<iframe src="/builder/ajax/load?id=1"></iframe>
<script type="text/javascript">
function init() {
// editor is defined in another script as the iframe.contentWindow.document
editor.body.contentEditable = "true";
editor.body.designMode = "on";
}
</script>
This can be done using queryCommandSupported and queryCommandEnabled as I just now discovered!