I've run into a very odd issue trying to make Aloha work in the Panels admin.
First problem is getting it loaded in the first place. CTools modal attempts to load the JS when the modal opens, the problem is that require.js needs to be loaded before jQuery, but the latter is allready loaded when the modal opens. A workaround is:
function hook_init() {
drupal_add_library('aloha', 'aloha-for-textareas');
}
But in the long run, we'd probably just want require.js to be loaded on each page.
The next hurdle is a undefined error, caused by Drupal.aloha.init being called in aloha.drupal.js instead of aloha.drupal.textarea.js. This can be fixed by checking for a function (first part of aloha.patch).
This gets us as far as having a working Aloha in the first modal opened. However, using the close link in the modal, and opening a new modal with an Aloha editor, it seriously blows up. The buttons looses their icons and the interface doesn't respond at all. Part of the problem is that Aloha don't get properly detached when using the close link in the corner of the modal, which we can fix by implementing an event handler on CToolsDetachBehaviors (that's the second part of aloha.patch).
This still doesn't make it work though.
After two days of hunting, I've found that the attached CTools patch works around this issue, but I have no idea *why* it works.
A timeout > 150 seems to fix things, making Aloha properly detach so it can re-attach to the next textarea that comes up. This is odd as the CToolsDetachBehaviors event handler should have let Drupal.aloha.detach do all it's work, before returning and letting modal.js .remove() the modal content.
Trying to single-step through the code, I haven't been able to spot any setTimeout that might explain things.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | aloha-1796294-4.patch | 525 bytes | xen |
| #2 | aloha-1796294-2.patch | 454 bytes | xen |
| ctools.patch | 400 bytes | xen | |
| aloha.patch | 918 bytes | xen |
Comments
Comment #1
webchickMarking needs review, since there's a patch here. Thanks! Sorry, I can provide no insight as to why this works.
Comment #2
xen commentedReroll. Now only adds the CToolsDetatchBehaviors event handler. CTools patch still needed.
Comment #3
Snipon commentedThis detaches the aloha behavior whenever you globally call .close() or Drupal.CTools.Modal.dismiss();
Comment #4
xen commentedNew patch, now only detaches aloha if it was part of the modal.