I'm trying to figure out how to get all of my confirmation dialogues (drupal_confirm()s) site-wide to appear in pop-ups and for whatever the normal 'Cancel' link is, to operate like the Popups 'Close' button.

I've gotten as far as having my confirmation dialogues all in pop-ups, but I'm having a hard time getting the cancel links to close them.

Since we can't preprocess much about confirmation forms, (it'd really be nice to be able to preprocess the classes used to create the cancel link) I've resorted to trying to add some inline js within a hook_form_alter() that simply targets the link and does an .addClass('popups-close'), but this seems to work very sporadically.

So I'm wondering if you have any better suggestions on how to accomplish this.

Thanks a lot, can't wait to show you what we're coming up with utilizing Popups API! You've saved us a lot of time with this!

Comments

sirkitree’s picture

Here's what I'm doing so far, moved it to hook_init()


  if (module_exists('popups')) {
    drupal_add_js("
      Drupal.library = function() {};
      Drupal.behaviors.library = function() {
        $('form.confirmation div.container-inline a').click(function() {
          Drupal.popups.close();
          return false;
        });
      };
    ", 'inline');  
  }

This is slightly unreliable, because div.container-inline is one of the things that could be changed within a hook_form_alter().

p.s. drupal_confirm() mentioned above should be confirm_form()

starbow’s picture

Hmm. It seems like what you want is a kind of popup lifecycle javascript hook - like nate's patch over at #336063, but triggered after popup creation. Is that right?

sirkitree’s picture

Kinda... that looks more like it applies after the form that is within the pop-up is submitted, I want to be able to call a function as soon as the pop-up is displayed.

Drupal.behaviors takes care of this, reapplying the js after a pop-up is displayed, which will work just fine in my case.

I guess what I'm really looking for is a better (as in 'always going to work') selection criteria for selecting whatever the 'Cancel' link is for any confirmation dialogue. Maybe I'm just not being imaginative enough ;) Perhaps $('form.confirmation input[@type~=submit]').next(); will always give me that link...

pribeh’s picture

Any Luck?