Impromptu and Instances

1.3k Views Asked by At

I am having a problem with impromptu and instances. I have two instances of impromptu, so when i call to close the first, the other closes too.

Is there any way to say to close one and no the other?

3

There are 3 best solutions below

1
On BEST ANSWER

So I'm guessing you're using jQuery.prompt.close() ?

I've never used impromptu, but it seems to me that it isn't meant to support multiple instances that are open at the same time. You can tell as much by looking at the source.

http://trentrichardson.com/Impromptu/scripts/jquery-impromptu.3.1.js

Personally, I'd suggest you switch to a better designed prompt system, but if you really want to continue using that, you'll have to close them manually. This is the internal structure of the .close() call

$('#'+ $.prompt.currentPrefix +'box').fadeOut('fast',function(){
  $(this).remove();
});

Where currentPrefix is equal to:

$.prompt( 'test', { prefix: 'the_prefix' } );
$.prompt( 'test', { prefix: 'the_prefix2' } );

So if you wanted to keep the two instances separate, you'd just need to use two separate prefixes and them manually close them like:

$('#the_prefixbox').fadeOut('fast',function(){
  $(this).remove();
});
$('#the_prefix2box').fadeOut('fast',function(){
  $(this).remove();
});
0
On

I tried BBonifield's solution above but it did not work for me. Maybe I was doing it wrong. My situation required that I just close whatever prompt was currently being displayed so that I can display the next one. To do that I used the following line:

$(".jqibox").remove();

That will destroy the current prompt immediately.

0
On

http://trentrichardson.com/Impromptu/

Impromptu 4.2

I tried the code supplied by BBonifield and I still wasn't getting the desired results. Either both prompts would close, or the first prompt wouldn't close (depending on execution order). The issue was still the prefix as suggested earlier, but the ID selector wasn't working. I had to use the class.

$('.the_prefixbox').fadeOut('fast',function(){
  $(this).remove();
});
$('.the_prefix2box').fadeOut('fast',function(){
  $(this).remove();
});

Also if you use a prefix other than the default you need to replace all instances of 'jqi' with your prefix in jquery-impromptu.css.