On Tue, Sep 23, 2008 at 3:05 PM, FigglesKoy <[EMAIL PROTECTED]> wrote:
>
> I have some code for a lightbox below:
>
> LightBox.prototype.showBox = function(){
>
>        ...
>
>        //Assign event handlers
>        this.okBtn = this.lbElm.select('INPUT.control.ok')[0];
>        if(this.okBtn)
>        {
>                this.okBtn.observe('click', this.okClick.bind(this));
>                this.okBtn.focus();
>        }
>
>        ...
>
> };
>
> LightBox.prototype.okClick = function(){
>        this.closeBox();
> };
>
>
> LightBox.prototype.closeBox = function(){
>        alert('hi');
>        var elms = this.lbElm.select('INPUT.control');
>        elms.invoke('stopObserving');
>        this.lbElm.remove();
>        this.backDrop.remove();
> };
>
>
>
>
> The issue is that the stopObserving doesn't seem to work.  The OK
> button will still pop-up the alert('hi') no matter how many times I
> click it.  I tried doing something like this.okBtn.stopObserving() but
> that didn't work either.  Any ideas?
>
> >
>

Check out the docs on stopobserving.
http://prototypejs.org/api/event/stopObserving. The issues you're
having are described in detail.

Essentially, you need to do a couple things:
1) Cache the reference to your bound function, like so:

var bound = this.okClick.bind(this);
this.okBtn.observe('click', bound);

so you can remove the function call later.

2) Pass the correct parameters when attempting to stop observing:

this.okBtn.stopObserving('click', bound);

Notice, as specified in the docs, that you have to have the correct
function reference so that the browser knows WHAT you want to stop
observing. Assuming you want to bind the same function to all of your
elements, you could also do:

elms.invoke('stopObserving', 'click', bound);

...BUT you still need the reference to bound, and it has to be the
SAME function that you initially hooked to your click event.

-- 
Jerod Venema
Senior Software Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
(919) 368-5105
---
WebWidgetry.com / MashupStudio.com
Future Home of the World's First Complete Web Platform

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to