Chaos Tools can be fantastic to work with on the php side. And has helped pick up alot of the heavy lifting of javascript. Which is great, but interacting with ctools on the JS side can be a bit of a pain. It's possible im just take the wrong approach and there already be better approaches to these types of problems. Having said that I feel it would be useful if chaos tools provided custom javascript events to some of the plugins.

For example events like modalBeforeOpen, modalOpen, modalClose, ajaxResponderComplete, etc, etc.

This came to thought after working on a project that leverages the ajax responder plugin. Which worked well, but I found no way in javascript to attach to the responder and find out if it has completed running all of its commands. Something like this would simplify writing javascript that has to execute after or before these interactions take place.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

There is an event that fires when the modal closes now, but that's the only one I've added. It seems reasonable to add more as we identify good ones.

I probably won't add any events to the ajax responder, since that code is in core in 7 and I'd rather not have code in 6 that I can't also put in 7, it's already hard enough. I can do stuff like that with the modal, though.

cangeceiro’s picture

Status: Active » Needs review

In the particular use case that I am working with, I want to be able to listen for an event that lets me know that the modal has finished loading so that I can attach to the event, and does some logic when the modal is done rendering, but currently have no way to listen for that event.


@@ -269,6 +269,7 @@
   Drupal.CTools.Modal.modal_display = function(ajax, response, status) {
     $('#modal-title').html(response.title);
     $('#modal-content').html(response.output);
+    $(document).trigger('CToolsAttachBehaviors', $('#modalContent'));
     Drupal.attachBehaviors();
   }

I implemented the above to accomplish this. However I'm open to input if you think there is a better place to put this trigger to get it committed. Or if there is just a better way to go about this.

cangeceiro’s picture

Version: 6.x-1.8 » 7.x-1.x-dev
FileSize
397 bytes

I am running into another situation where this would be really helpful to have in the js api of modals. attached is a patch that triggers CtoolsAttachBehaviors once the modal is done rendering and has focus. Patch is against 7.x

rjbrown99’s picture

Been playing around with this. I'm using 6.x but the concept is the same for both. I am using this with a ctools wizard multi-step modal form. What I want is an event that fires after the new modal form is completely done loading. I can't use click handlers on the previous step's submit function because that won't account for form validation failures. IE, if you are on step #1 of my multi-step form, and validation fails, I do not want to run any events. I want the event to only run when we successfully passed validate+submit on step 1 and we're on to step 2 with a fully loaded new form.

Patch #2 sort of works, in that it will run an event on the second form. The problem is it fires multiple times as content is being loaded into the modal. In my case I have it loading a carousel of images and it's firing on each image that is loaded. This is undesirable as I want only one event at the tail end of loading.

Patch #3 is not fired at all after new content is loaded to the modal. It's only fired when the first modal form pops up.

I'm off to search for the right place to fire this event - one time, after the modal is done loading.

merlinofchaos’s picture

#4: For your comment about #2, I'm not sure CTools has any knowledge of 'tail end of loading' -- if it calls modal_display it can't tell the difference between an update and a fresh load. You'll have to have some kind of marker to figure that out on your own, I think.

Why does #3 not include #2?

merlinofchaos’s picture

Status: Needs review » Needs work
cangeceiro’s picture

3 was basically a different approach that I tried on a different project. I can't say I have settled on the best way to approach this. if you have time during drupalcon I would be happy to meet up and discuss more in depth, also wouldn't mind chatting in person in regards to the field able panel panes module.

rjbrown99’s picture

I just settled on #2 for now as-is and worked my own JS around it. For right now it works for my need for an event.

merlinofchaos’s picture

Sure, I'd love to.

cangeceiro’s picture

whats the best way to track you down? I had no idea this place would be as packed as it is.

rjbrown99’s picture

#10 try Twitter - I have seen him pop on there a few times recently. @merlinofchaos

merlinofchaos’s picture

I remember meeting you but I don't remember what we actually discussed, or if we managed to discuss what you wanted. Much of Drupalcon is a blur to me. :(

cangeceiro’s picture

Its all good, i was still in precaffiene daze myself. I was just wanting to clear up the possibility of getting this patch to add CtoolsDetachBehaviors committed. and if the there was anything else i could do to get the patch up to snuff to do so.

merlinofchaos’s picture

I think we just need to resolve the differences; I marked it needs work because there are 2 approaches and I'm having trouble telling which one of them was working for other people. When someone says "This doesn't work for me" but it's not clear why that tends to slow things down.

earthday47’s picture

Very interested in this.

Here's a patch that implements comment #2, applied against 7.x-1.x.

earthday47’s picture

Here's the same patch applied from 7.x-1.4.

temkin’s picture

Status: Needs work » Needs review

The last submitted patch, 3: ctools-attach-behaviors-1018724.patch, failed testing. View results

temkin’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

geek-merlin’s picture

Issue tags: +low-regression-risk
MustangGB’s picture

Why is this a regression risk at all?

DamienMcKenna’s picture

joelpittet’s picture

rivimey’s picture

@axel.rutz please explain the regression risk -- or we have no way to either evaluate the risk, explain it, or mitigate it.

geek-merlin’s picture

> please explain the regression risk

i added that tag "low (or no) regression risk" a year ago to sort issues for a release. you can ignore or remove this now.

MustangGB’s picture

Issue tags: -low-regression-risk
joelpittet’s picture

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks I've committed this to the dev branch and will be in the next release (today). Thanks for your patience and hard work on this everybody!

  • joelpittet committed c16b4e6 on 7.x-1.x authored by earthday47
    Issue #1018724 by earthday47, cangeceiro, merlinofchaos, rjbrown99,...

Status: Fixed » Closed (fixed)

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