This patch adds explanations to the api file. They are intended for those developers who want to write a plugin for WYSIWYG respectively add an own button to the editors which WYSIWYG supports.

This is the first draft and almost the whole thing could be wrong (be lenient, please ;) ). Those things of the hook functions that are not clear to me are marked with "?" (search for ?).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Great stuff! Sorry for not following up earlier.

I'll definitely review, fill in the missing pieces, and commit this in the next days.

Alan D.’s picture

This will be a valuable asset to developers. Using the notes, I had created my first WYSIWYG plugin in no time.

Could this be extended to briefly include notes on how to handle dialog popups? Namely the init, cancel and close/update API's

Thanks in advance

Alan

GuillaumeDuveau’s picture

Thanks for the notes Roi Danton it's very usefull.

Richard Blackborder’s picture

Good stuff. Similar notes on the javascript would be invaluable too.

Roi Danton’s picture

Some Javascript thoughts (many further thoughts needed ;) ):

In wysiwyg.init.js you see the Drupal.wysiwyg objects.

2.c (I) As far as I understand the Javascript of a plugin is initialized by adding it to Drupal.wysiwyg.plugins['plugin_name'] where plugin_name is the name set in step 2b) of the patch above. However img_assist is using Drupal.wysiwyg.plugins.plugin_name. Both methods work with WYSIWYG v2.

2.c (II) Within that object you use some of the functions Drupal.wysiwyg.editor provides (see wysiwyg.init.js). In break.js explanations are provided:

isNode
Return whether the passed node belongs to this plugin. (break and img_assist check if the class is part of the node object)
invoke
Execute the button using parameters data, settings, instanceID and storing your data in a variable your_variable. On the end of this function add the variable to the instances of the Drupal.wysiwyg Object and execute something:
    if (typeof your_variable != 'undefined') {
      Drupal.wysiwyg.instances[instanceId].JSFunction(your_variable);
    }

where JSFunction(your_variable) could be insert, openDialog etc (default jQuery functions and custom functions?).

attach
Break and img_assist plugins use it to replace all their tags with fancy images so their appearance in WYSIWYG editors looks nice.
detach
Undo what was done in attach when the WYSIWYG editor gets detached.
jdelaune’s picture

Would be great if the maintainers could write all these up. Rather than making us all play guessing games. I'm sure you will be able to quickly document everything far faster and easier than any of us. It would great for everyone's benefit :)

TwoD’s picture

You have a point there Starnox. As eager we are to get started on the next major version (which will change how plugins interact with the active editor, this time without even needing to know its name), we really should take some time to document how it all works in its current incarnation.

There's a bit of a dilemma here though. Few editor implementations support plugins yet and part of the reason is that we want to wait for the changes I mentioned above, before writing a bunch of code we'll soon have to rewrite. So, we're looking ahead to see which parts of the current code needs an overhaul to support the features one would expect from a module trying to wrap different editors in the same packaging.

At the same time, the community is getting interested in writing plugins (which is awsome btw!). They'll most likely run into problems because of the current API drawbacks, or end up writing hacks/workarounds which will just complicate somehting that should be easy (from a plugin POV, like inserting content at the caret position) no matter which editor is on the other side of the API. We really don't want people to have to go through that, but is it better to help people understand and work around the 2.x code which has many limitations rather than focusing on the 3.x code and "stall" the eager plugin developers until they have something better to work with?

I'm mainly thinking about "Drupal plugins" here, but much of this also applies to native editor plugins in some way or another.

Time is not merciful when one wishes to do all things... ;)
Sun has been busy lately and now I'm getting my hands full for the next couple of days [or maybe weeks], not to mention I'm looking for a new job. :/

This post got way more elaborate than I had in mind, but before I completely lose focus:
What you have so far seems pretty much accurate, but I see you struggle with the same things I did when first seeing the code. As soon as I have some time over I'll look through the notes here and add some of my own.

I really shouldn't post this late hehe... ;)

Richard Blackborder’s picture

TwoD, another benefit of writing documentation is that it frees up a lot of developer time, and some of that time may actually go into benefiting this project.

I put myself forward as an example of this. I like WYMeditor, and using it with Drupal/WYSIWYG has led me to submit a patch to update the WYMeditor integration.

I believe I would have submitted several patches by now if I had access to documentation. Without it, it just takes so long trying to figure out how things work or how they are supposed to work.

"Help me to help you" as the saying goes :-)

GuillaumeDuveau’s picture

+1 for good doc or very simple examples, like a plugin that adds a dialog, a simple form, and inserts code based on the form values. teaser_break is too simple and img_assist is way too complex.

TwoD’s picture

I agree with you on that guix, docmentation is much more useful with good examples. We should of course include the the parts you mention, but in Wysiwyg 2.x there's not really much support for dialogs except for opening them. (Which is why Image Assist currently needs different implementation files for each editor and is a pain to extend IMHO, and I think Sun agrees on that...)
An example of that working with all editors will get very complicated, as not all editors implement the insert() method. I'll try my best to explain that in the docs.

This is of course to be adressed in 3.x, probably with an API method to notify Wysiwyg module that the dialog is done loading and it needs the editor instance.

And Likeless has a good point too. I don't know how long Wysiwyg 2.x will be around, but I guess that since 3.x will probably take some time to get stable, we can't stop improving the editor implementations with what we've got so far. If we at least get insert() implemented in all editors, it would make it much more useful and easier to write good [example] plugins for.

Oh btw, my ISP seems to have "misplaced" my IP etc while we were away the last two weeks... I've only got internet access through my netbook for now, so development has slowed down considerably, but I hear "they've filed an error report and will get back to me within some time". :(

Roi Danton’s picture

With the provided examples the plugin creation for 2.x works well for me though the WYSIWYG live replacements (replacing tag/macro with image instead of actual content) and button UI are quite limited as was written here already. Sun also wrote that the JS API will change for 3.x.

However with the provided descriptions and break + img_assst the plugin creation is possible for 2.x with all the features the WYSIWYG 2.x plugin system provides. Therefore this issue should be fixed for 2.x.

Richard Blackborder’s picture

Roi, I must thank you for the documentation you have provided in this thread. It's very helpful. I have to disagree with you on that last point, though. I don't think that having enough material that some people can figure it all out given enough time is any substitute for real documentation. I think it's clear from the comments in this thread that there are a significant number of keen contributors having problems figuring out this API.

TwoD - My take would be that the longer there is to wait for 3.x, the more important 2.x docs are. That said, I think 3.x docs will be far more important.

And "some time" sounds bad. The Mesozoic era was "some time".

sun’s picture

Status: Needs work » Fixed
FileSize
13.34 KB

I spent some hours tonight to document this.

Thanks for reporting, reviewing, and testing! Committed attached patch to all branches.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Richard Blackborder’s picture

Looks helpful, thanks sun :)

GuillaumeDuveau’s picture

Also img_assist-6.x-2.x seems outdated and I guess the reference should be img_assist-6.x-3.x ! May be obvious but not for me :)

Some things I noticed that were changed in 3.x
- uses hook_wysiwyg_include_directory() and the plugins directory instead of hook_wysiwyg_plugin()
- in 2.x there was custom code for TinyMCE to register a new popup window, now it's gone, all is in img_assist/img_assist.inc

[edit] I finally get it, I have a lightweight module using a popup wizard in 2 steps with WYSIWYG+TinyMCE. A lot of things are hard-coded and horrible like the wizard is in GET not in POST and Forms API. It allows to select an imagefield attached to the node by clicking the image and insert some code

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.