Can someone tell me how I can make one popup close before I open the next one , on the same page?
thanks,
Diana

Comments

dianacastillo’s picture

Status: Active » Closed (fixed)

I solved this by assigning a global variable to the active popup and closing it when another is click upon.

roman_iglin’s picture

I came with the same problem how to make it, it is possible in more detail?
thanks,
Romeo

reych9’s picture

I would like to close the popup if I click out of it, except if "close" is visible, not just if you click on another popup.

reych9’s picture

Title: how to close other popup before opening new one » Close popup after clicking outside it
Issue summary: View changes
Status: Closed (fixed) » Active

it is not clear how to do that, could you be more especific?

Scheepers de Bruin’s picture

It is possible to provide a new popup effect that does just this. See hook_popup_effects in README.txt

Create a module that implements this hook.

It should return something like the following:

     array(
       'show' => array(
         'exclusive' => '$(".popup-element").trigger("hide"); this.body.show();',
       ),
       'hide' => array(
         'exclusive' => 'this.body.hide();'
       ),
      );
jessinwyoming’s picture

Would anyone be willing to explain what exactly to add to the popup.js file to make this happen? (I don't know much about javascript.)

Thanks much in advance -
Jessica

jtronchon’s picture

Hi jessinwyoming,

by now you've probably resolved your problem but it could help others...

In order to do the scheepers response in your code, you'll have to create a new module and implement the hook_popup_effects.
For example, you have a module named "my_module".. In your my_module.module, implement this :

function my_module_popup_effects() {
  return array(
    'show' => array(
      'exclusive' => '$(".popup-element").trigger("hide"); this.body.show();',
    ),
    'hide' => array(
      'exclusive' => 'this.body.hide();'
    ),
  );
}

"exclusive" is the name of the effect that you have just created so when you want to build the popup, you'll have to specify the 'effect' in $attributes.

Example with a test code that I've created in a form_alter

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'my_form') {
    module_load_include('inc', 'popup', 'includes/popup.api');
    $attributes = array(
                    'view' => 'search_media',
                    'id' => 'my-popup',
                    'activate' => 'click',
                    'title' => t('Search'),
                    'width' => '500px',
                    'expand' => 'bottom-right',
                    'effect' => 'name_of_custom_effect_here',
                    'close' => true,
                  );
    $form['field_product_main_cover']['und']['#suffix'] = popup($attributes);

This code allows me to add a link after an autocomplete field in order to display a view containing several images (with filter). The final purpose (in progress) is to click on an image and add it to my autocomplete field.

I know there is the "references dialog" module but for an unknown reason it doesn't work as planned on my instance.

Cheers.

doxigo’s picture

You can manage such thing by jQuery :

  $("a.popup-element-title").click(function() {
    $('.popup-element-body').hide();
    var lid = $(this).parent().attr("id");
    var id = lid.split('-')[2];
    var bodyId = $("#popup-element-" + id + "-active .popup-element-body").show();
  });

Even though I guess this should be an option that users can be able to enable.

alex awg 2015’s picture

You can add to your_theme.js or your_module.js


jQuery(document).mouseup(function (e) {
    jQuery(".popup-element-body").each(function (i) {
        var elem = jQuery(this);
        if (e.target != elem[0] && !elem.has(e.target).length ){
            elem.hide();
        }
    })

});

It close popup after clicking outside its