Forum: Rails Spinoffs (closed, excessive spam) script.aculo.us slider - this and event handler - depending sliders

Posted by seb.schaetz@googlemail.com (Guest)
on 2008-07-07 18:47
(Received via mailing list)
Hi,

I successfully created depending sliders with prototype and slider.js.
See the result here: http://www.soa-world.de/dev/slider/slider.html
(here's the code: http://pastebin.com/ma1e82eb)
There is one problem with my code. What I do is I have a sliders class

"function sliders()"

inside I create the 5 sliders in a for loop and store them inside an
array which is a member of the class:

for()
{
   this.sliders[i].ctrl = new Control.Slider();
}

I then add callbacks for the onChange and onSlide events also inside
the loop with:

this.sliders[i].ctrl.options.onSlide = handleSliderChange;
this.sliders[i].ctrl.options.onChange = handleSliderChange;

In the callback I get two parameters: the new value and the slider
that triggered the event. To do my stuff I now need one more thing: a
reference to the array that contians ALL the sliders - naturally you
would think this.sliders[] but no of course not, the event callback
doesn't recognize the this keyword anymore because it doesn't know it
belongs to the sliders class. I worked around this by using the object
I create and access the array there so I write:

s = new sliders();

and inside the callback I access the array:

s.sliders[]

but I think that's ugly. I tried it using bindAsEventListener - that
worked as far as the this keyword goes. I could access the array then
via this.sliders however I lost the second parameter for my callback
so I didn't know which slider triggered the event.

How could I make this work?
Thanks in advance,
Sebastian S.
Posted by Christophe Porteneuve (tdd)
on 2008-07-07 18:52
(Received via mailing list)
Hey Sebastian,

We've started transitioning to a new, better-named, spam-policed group
for Prototype and script.aculo.us:

   http://groups.google.com/group/prototype-scriptaculous/

   prototype-scriptaculous@googlegroups.com

Could you please post your question there instead?  Thanks!

--
Christophe Porteneuve aka TDD
tdd@tddsworld.com
Posted by T.J. Crowder (Guest)
on 2008-07-07 18:54
(Received via mailing list)
Hi,

> In the callback I get two parameters: the new value and the slider
> that triggered the event.

Are these event handlers, or are you calling them directly?  If you're
calling them directly from other code, you probably want bind() rather
than bindAsEventHandler().  If they are event handlers, then the
parameters to them will be just the event -- but you can use
Function.curry[1] to deal with that.
[1] http://www.prototypejs.org/api/function/curry

Just FYI:  We're moving from this group to the new Prototype &
script.aculo.us group:

http://groups.google.com/group/prototype-scriptaculous
prototype-scriptaculous@googlegroups.com

Although people are still answering here (for now), it's best to start
new threads over there.  We plan to stop replying to new threads in
this group 'round about the 15th of July.
--
T.J. Crowder
tj / crowder software / com

On Jul 7, 5:46 pm, "seb.scha...@googlemail.com"
Posted by seb.schaetz@googlemail.com (Guest)
on 2008-07-07 19:16
(Received via mailing list)
> Are these event handlers, or are you calling them directly?  If you're
> calling them directly from other code, you probably want bind() rather
> than bindAsEventHandler().  

To be honest I can't tell the difference. But no I don't think they
are events they are callbacks I can register so I'm not calling them
directly from my code. The slider.js merely provides them. I think I
already tried bind() and got the same result as with
bindAsEventHandler(). The second parameter got lost.

> If they are event handlers, then the
> parameters to them will be just the event -- but you can use
> Function.curry[1] to deal with that.
> [1]http://www.prototypejs.org/api/function/curry

I'll have look at curry.
Thanks for the suggestions!
Sebastian
Posted by T.J. Crowder (Guest)
on 2008-07-07 19:24
(Received via mailing list)
Hi,

Sorry, you did mention slider.js, didn't you?  I missed it.

Let's pick this up in your thread in the new forum.
http://groups.google.com/group/prototype-scriptacu...

-- T.J. :-)

On Jul 7, 6:15 pm, "seb.scha...@googlemail.com"
This topic is locked and can not be replied to.