I'm trying to implement the basic Rich Text Editing functionalities of ContentEditable in Meteor and I'm having an issue with execCommand. The undo and redo commands work fine but every other command such as bold and italic do not work and give out no errors. The code also worked fine as a regular page (I've done the obvious adaptations for Meteor such as templates and the events).
My html:
<body>
{{> buttons}}
<div id="editor" class="textZone" contenteditable="true"></div>
</body>
<template name="buttons">
<div id="rtfOptions">
<div class="separate">
<div class="rtfOption" id="undo">undo</div>
<div class="rtfOption" id="redo">redo</div>
</div>
<div class="separate">
<div class="rtfOption" id="bold">bold</div>
<div class="rtfOption" id="italic">italic</div>
</div>
</div>
</template>
My events (only 2 non-working + the undo as it works. As for the rest its pretty much the same):
if (Meteor.isClient) {
Template.buttons.events({
"click #bold": function() { // Toggles bold on/off for the selection or at the insertion point
document.execCommand("bold", false, "null");
},
"click #italic": function() { // Toggles italics on/off for the selection or at the insertion point
document.execCommand("italic", false, "null");
},
"click #undo": function() { // Undoes the last executed command.
document.execCommand('undo', false, "null");
}
)};
}
Someone know the issue? Does it have something to do with document or the scope?
"null"is wrong. It should be justnullwithout the quotation marks. However, I'm not sure that would make any difference. Is your editor using an iframe for the editor content? - Tim Down