javascript - Tinymce toggle format, formats the button not the editor -
so im having little issue tinymce4 api, iv created custom format want tigger button. happens when button clicked, style applied button instead of actual contenteditable field..
tinymce.init({ selector: '#editable', inline: true, menubar: false, toolbar:false, statusbar: false, }); settimeout(function(){ tinymce.activeeditor.formatter.register('mycustomformat', { inline : 'span', styles: {color: 'red'} }); },200); $('.js-toggleformat').on('click', function(e) { tinymce.activeeditor.formatter.apply('mycustomformat'); })
and html:
<button class="js-toggleformat">toggle</button> <div id="editable" contenteditable="true"></div>
take @ example. tinymce plugin "textcolor" uses function "applyformat" applying color. looks this:
function applyformat(format, value) { editor.focus(); editor.formatter.apply(format, {value: value}); editor.nodechanged(); }
based on that, should work in case:
tinymce.activeeditor.focus(); tinymce.activeeditor.formatter.apply('mycustomformat'); tinymce.activeeditor.nodechanged();
Comments
Post a Comment