I currently have a tinymce plugin that works reasonable well. It is very close to the tinyMCE example plugin, wherein it pops up a dialog, accepts input from the user, and then inserts the input (with special formatting) into the editor window.
That works fine. I even made a module http://drupal.org/project/wysiwyg_syntaxhl that wraps it up and uses the hook_wysiwyg_plugin() function. All is good.
Now however, I wanted to do something more advanced and I wanted to change the user's input on both an attach and detach of the editor. So when the content is loaded, a conversion happens, and when it is saved, a conversion happens. This is actually exactly what the break plugin does, so I studied that code. However, that uses the 'drupal plugin' abstraction layer, so I'm confused as to how to integrate my existing plugin to use the 'attach and 'detach' function.
I suppose I have two approaches:
One) go the Drupal plugin route.
Is it ok to do that even if my plugin is only really for tinymce? If I do, do I still use hook_wysiwyg_plugin()? Or do I use hook_wysiwyg_include_directory() and hookwy_include_plugin()?
If I take this approach and write the plugin following the break.js example, where do I put code to popup a window for user input? In my existing plugin, it is like this:
init : function(ed, url) {
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
ed.addCommand('mceSyntaxHL', function() {
ed.windowManager.open({
file : url + '/dialog.htm',
width : 450 + parseInt(ed.getLang('syntaxhl.delta_width', 0)),
height : 400 + parseInt(ed.getLang('syntaxhl.delta_height', 0)),
inline : 1
}, {
plugin_url : url // Plugin absolute URL
});
});
two) go the tinymce plugin route.
If I do this, I just need to know what the tinymce equivalents are of the drupal plugin 'attach' and 'detach' functions. Can you give me a clue here?
Comments
Comment #1
twod1)
A Drupal plugin can not be limited to work in only one editor so it's really not a good solution. The attach and detach functions are methods on the plugin object itself and must be so, these are automatically called on all plugins each time content is retrieved or sent to the editor, not only when it is loaded or unloaded. If your popup is opened from there, it will do so in unexpected situations and maybe also multiple times in a row, depending on what the editor does. Wysiwyg 3.x might get 'global' attach/detach callbacks, but that is not yet decided.
You need to use the second set of hooks for Drupal plugins. Drupal plugins are currently assumed to be implementing a toolbar button, that should change in 3.x tho. You could maybe use the invoke method on the Drupal plugin object to launch your popup when the toolbar button is created. The Image Assist plugin does this, but it currently only works with TinyMCE (lacking implementations in Wysiwyg module and editor specific code in IA).
2)
Try the onBeforeSetContent and onGetContent events, as documented on http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.Editor. Those are the ones we use to initiate the call to the Drupal plugin attach/detach methods.
Comment #2
meecect commentedThanks for the quick reply. Just to clarify, my popup does get launched from a button on the toolbar, not when the editor is launched, but since it is tinymce only for now, I will go with route 2, and use the events you referenced.