Sunday, January 29, 2012

The Case of the Missing "Close" Button on a JQuery Tools Overlay

I have a button on a page that may or may not be there. When I clicked the button, I wanted a JQuery Tools Overlay to pop up with some information and links. Because the button may or may not be there, I had to create the overlay programatically. I found information on doing so here: http://flowplayer.org/tools/demos/overlay/trigger.html So, on my page, I created a div for the overlay as such:
And, in the function called by the button's on click event, I added this:
 $('#interp_pool_div').html(doctor_selection);
 $('#interp_pool_div').overlay({
            oneInstance: false,
            mask: '#dcdcdc',
            effect: 'apple',
           });
               
         $("#interp_pool_div").overlay().load();
This worked well, except for one thing - the close button didn't appear the second time that I opened the overlay. Also, I was a but worried about memory leaks caused by repeatedly creating the overlay. It turns out that because I was putting the data directly in the overlay div, the second time it ran, it was overwriting the html for the close button. So, the answer was to put a second div inside the overlay div and then load the content into that one. I also but a simple check around the code that creates the overlay to avoid creating it a second time. So, the final working code appears as such: In the HTML:
In the JavaScript, outside the onclick function:
 var overlay_exists = false;
In the function called by the button click:

$('#interp_data').html(doctor_selection);
                              
if(overlay_exists === false){
     $('#interp_pool_div').overlay({
          oneInstance: false,
          mask: '#dcdcdc',
           effect: 'apple',
           
         });
         overlay_exists = true;
}
$("#interp_pool_div").overlay().load();

3 comments:

Raymond said...

hey i am doing the same way as you did but i have another problem with the effect.

my trigger button is at the right and supposingly the apple effect start from the button but it starts from top left for the first time and middle left for the 2nd time and so on...

do you facing this problem?

Raymond said...

hey i do the same way as you did but im facing another problem

supposingly the apple effect start from the trigger button but mine start from other place than the button...

do you face this problem?

Amy said...

Raymond, I'm not seeing that problem on mine. The overlay is popping up right at the trigger, as expected.