Hi,

I'm using Ctools modal plugin to display login / registration form in a modal window, which works fine. I created a menu hook that when clicked displays my forms in the modal window, so that's all fine. I'm curious if there's a way to trigger the modal window without clicking a link. A use case would be when you're trying to view a node you don't have permission to view and the login / register form appears in the modal. Right now I achieved this functionality by adding inline js and programatically clicking the link but it's not the best approach I think. What I really want to do is call a function that triggers the modal display.

Thanks,

Rob

Comments

merlinofchaos’s picture

Status: Active » Fixed

There isn't really a function you can call; the whole thing is bound to the event, which in this case is a click. Anything else would ultimately take more code, so calling $('.class-of-link').trigger('click') is probably the simplest thing you can do.

rvarkonyi’s picture

Status: Fixed » Closed (works as designed)

OK thanks anyway, closing the issue

rvarkonyi’s picture

Status: Closed (works as designed) » Active

Hi merlin,

sorry to reopen... It would be great if you could point me in a direction, obviously I don't expect a fully working solution, but I would appreciate if you could give me some tips in terms of where to start.

Thank you

Rob

merlinofchaos’s picture

Status: Active » Fixed

Um. I thought I did?

The complex thing to do would be to modify the ajax object just for that. It's a little complex to do that, though, and requires a lot of understanding of the ajax framework and javascript.

But basically, it works like this. In ajax.js the event is bound like this:

  // Bind the ajaxSubmit function to the element event.
  $(ajax.element).bind(element_settings.event, function (event) {
    return ajax.eventResponse(this, event);
  });

So you COULD just call Drupal.ajax[link_id].eventResponse($('#idoflink').get(0)) rather than triggering the click.

I'm not sure that's actually much better.

rvarkonyi’s picture

Status: Fixed » Closed (fixed)

OK, thanks. Closing. Won't reopen I promise