You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

Disassociating Overlay with an element Created Nov 23, 2009

This thread is solved

Views: 1773     Replies: 4     Last reply Nov 24, 2009  
You must login first before you can use this feature

tigerfoot

Posts: 6

Registered:
Nov 23, 2009

Disassociating Overlay with an element

Posted: Nov 23, 2009

Hello,

I have an overlay that pops up when a link is clicked. Under javascript control I want to toggle this link between an active/inactive state.

When the link is toggled inactive, what's the best way to disassociate the link with the overlay behavior? I don't want to hack it wrong and possibly have lots of zombie overlay objects polluting the browser's memory.

Thanks!

degenerate

Posts: 156

Registered:
Sep 19, 2008

» Disassociating Overlay with an element

Posted: Nov 23, 2009

Reply to: Disassociating Overlay with an element, from tigerfoot
I think your understanding of how javascript works is a little off. You are not wasting memory or "polluting" anything by leaving elements binded to functions. The javascript does not run and therefore does not create the overlay until you initiate the function by clicking the link.

But what you are looking to do is unbind the element(s) from their expose call. Simply unbind the element using unbind() and it will no longer be a trigger for the overlay. When you want to rebind it, recall overlay() on that element.

tigerfoot

Posts: 6

Registered:
Nov 23, 2009

» » Disassociating Overlay with an element

Posted: Nov 23, 2009

Reply to: » Disassociating Overlay with an element, from degenerate
Yep, my JS knowledge is without doubt incomplete (Java-think).

I tried unbind(), which worked great, but rebinding with overlay() didn't work.


	<a class="button button_special" onclick="
		$('#flipper').toggleClass('button_inactive');
		if($('#flipper').hasClass('button_inactive')){
			$('#flipper').unbind();
		} else {
			$('#flipper').overlay();
		};
		return false;" href="#"><span>Da Da Da</span></a>
	<a class="button button_inactive" id="flipper" rel="#porsche" onclick="this.blur();return false;" href="#"><span>Inactive</span></a>

Any idea why calling overlay() after the first binding doesn't work?

Thanks!

tigerfoot

Posts: 6

Registered:
Nov 23, 2009

» » » Disassociating Overlay with an element

Posted: Nov 23, 2009

Reply to: » » Disassociating Overlay with an element, from tigerfoot
Got it!
Looking at the Overlook code it seems that a data element is associated with the trigger. So if the data element exists then the call to Overlay (which does the bind) never happens again.

So, the fix to the code above would be the unbind call:


$('#flipper').unbind('click').removeData('overlay');

With removeData added calling overlay() again later works fine.

degenerate

Posts: 156

Registered:
Sep 19, 2008

» » » » Disassociating Overlay with an element

Posted: Nov 24, 2009

Reply to: » » » Disassociating Overlay with an element, from tigerfoot
Hm, interesting, thanks for posting the complete solution. Didn't know about removeData().