I'm work on inserting images in 'tag' form into wysiwyg editor. I need detect editor status before insert - if editor is enabled in HTML mode i want insert tag ([[...]]) else, in TEXT mode i want insert HTML (<img src="".... />).
In JS wysiwyg plugin, in invoke function is there variable data.format with editor status. Is possible check current status of editor calling some function from wysiwyg JS API? Something like:
Drupal.wysiwyg.instances[Drupal.wysiwyg.activeId].status();
would be useful.
Thanks for advice.
Comments
Comment #1
twodThere is currently no other way to get that info.
Actually, the
data.formatproperty will always be set to 'html' since none of the editors we support will insert any content when not in WYSIWYG/HTML mode.FCKEditor will throw an error, CKEditor does nothing, TinyMCE inserts the HTML as usual but any changes done in the WYSIWYG area will be lost if clicking "Update" in the HTML Source Editor dialog. YUI Editor does not seem to have a "view source" mode.
Editors will usually also disable the toolbar buttons when entering "view source" mode so there's so far been no reason to actually implement something where
data.formatis set to anything but "html".I've not looked into whether supporting a "getContentFormat()" method for use outside the invoke() method would be possible in all editors, I'd have to get back to you on that.
Comment #2
havran commentedI have workaround for CKEditor (insertIntoActiveEditor is event for Insert module which i use for insert images):
But if mode === 'source' insert not work, maybe something with default insert method...Comment #3
twodOk, that works for when the editor generates HTML markup, but sometimes it may generate BBCode, or perhaps Markdown, in which case
data.formatwould be 'bbcode' or 'markdown' (or at least, that was the original idea, not implemented yet).Comment #4
havran commentedI have some problems in my latest code - now i use this variant:
This seems work better because (for example) i have content with text format which don't enable wysiwyg editor (ckeditor) in body textarea - then Drupal.wysiwyg.activeId is set to next initialized textarea. Then my code return html === true even if body (which i use for inserting) is simple textarea.
Comment #4.0
havran commentedtypo
Comment #5
steinmb commentedOld and solved.