seb.schaetz-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Jul-07 16:46 UTC
script.aculo.us slider - this and event handler - depending sliders
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2008-Jul-07 16:51 UTC
Re: script.aculo.us slider - this and event handler - depending sliders
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Could you please post your question there instead? Thanks! -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
T.J. Crowder
2008-Jul-07 16:53 UTC
Re: script.aculo.us slider - this and event handler - depending sliders
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <seb.scha...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
seb.schaetz-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Jul-07 17:15 UTC
Re: script.aculo.us slider - this and event handler - depending sliders
> 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/curryI''ll have look at curry. Thanks for the suggestions! Sebastian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
T.J. Crowder
2008-Jul-07 17:23 UTC
Re: script.aculo.us slider - this and event handler - depending sliders
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-scriptaculous/t/8744c1d0156cbcd5 -- T.J. :-) On Jul 7, 6:15 pm, "seb.scha...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <seb.scha...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---