Couple of thoughts I had today whilst working on a project
1) If you have an enumerable, such as is returned from $$, how do you access
the ''nth'' element without the use of a closure & $break?
Is a ''at'' or ''nth'' function something
that would get used? In my
scenario, I got a bunch of items and I wanted the first one, which is simple
enough, but if you wanted the last one, or the one in the middle?
I guess enumerable.entries()[0] or enumerable.entries()[enumerable.size()-1]
would do the trick for first & last...
2) I was using the eulerian tech datepicker and wondering why it wasnt
working. I realised that because I wasn''t loading the date-picker when
the
page loaded (as a lot of ajax style apps do) that the hook for
dom:oncontentloaded (previously window.load) wasn''t fired, as it got
observed *after* the event had occurred.
What are your guys thoughts on storing this event has occured and any
observers added to these events after the event has fired would fire
immediately? Would it cause too many problems?
Thoughts, criticisms et al welcome & encouraged.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Gareth,
http://www.prototypejs.org/api/array/first
and
http://www.prototypejs.org/api/array/last
should do the trick.
The problem arises when you need to access next element in a
collection. Consider this example:
$$(''input[type=text]'').invoke(''observe'',
''keypress'', function(e) {
if (Event.KEY_TAB == e.keyCode) {
// focus next element in collection
}
})
Inside a callback we could resort to
this.next(''input[type=text]''),
but this unfortunately will not work if input elements are not in a
linear order
One way to make it happen is by storing index of a current element in
a closure and focusing the element with index = index + 1 when the key
is pressed
$$(''input[type=text]'').each(function(el, index) {
el.observe(''keypress'', function(e)) {
if (Event.KEY_TAB == e.keyCode) {
$$(''input[type=text]'')[index+1].focus()
}
}
})
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Oh, didn''t realise an enumerable had the array methods available. You can''t use the [ ] notation so I assumed it wouldnt work and didnt actually try it. In your example, yeah i''d agree you''d have to use some sort of indexing scenario. Though, using index like the second example works? The ''index'' is only available while iterating, at the time the event fires, wouldn''t it be gone, closure or no closure? I spoke to Mathieu who has made a change to the datepicker to allow it to be initialized if it hasnt when you click it, which solves my 2) question, but still wondering why that would be a bad idea anyway. On 11/15/07, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Gareth, > > http://www.prototypejs.org/api/array/first > and > http://www.prototypejs.org/api/array/last > should do the trick. > > The problem arises when you need to access next element in a > collection. Consider this example: > > $$(''input[type=text]'').invoke(''observe'', ''keypress'', function(e) { > if (Event.KEY_TAB == e.keyCode) { > // focus next element in collection > } > }) > > Inside a callback we could resort to this.next(''input[type=text]''), > but this unfortunately will not work if input elements are not in a > linear order > One way to make it happen is by storing index of a current element in > a closure and focusing the element with index = index + 1 when the key > is pressed > > $$(''input[type=text]'').each(function(el, index) { > el.observe(''keypress'', function(e)) { > if (Event.KEY_TAB == e.keyCode) { > $$(''input[type=text]'')[index+1].focus() > } > } > }) > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
$$ returns an Array, not any Enumerable :) Best, -foca On Nov 14, 2007 6:03 PM, Gareth Evans <agrath-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh, didn''t realise an enumerable had the array methods available. > You can''t use the [ ] notation so I assumed it wouldnt work and didnt > actually try it. > > In your example, yeah i''d agree you''d have to use some sort of indexing > scenario. > Though, using index like the second example works? The ''index'' is only > available while iterating, at the time the event fires, wouldn''t it be gone, > closure or no closure? > > I spoke to Mathieu who has made a change to the datepicker to allow it to > be initialized if it hasnt when you click it, which solves my 2) question, > but still wondering why that would be a bad idea anyway. > > > > On 11/15/07, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Gareth, > > > > http://www.prototypejs.org/api/array/first > > and > > http://www.prototypejs.org/api/array/last > > should do the trick. > > > > The problem arises when you need to access next element in a > > collection. Consider this example: > > > > $$(''input[type=text]'').invoke(''observe'', ''keypress'', function(e) { > > if (Event.KEY_TAB == e.keyCode) { > > // focus next element in collection > > } > > }) > > > > Inside a callback we could resort to this.next(''input[type=text]''), > > but this unfortunately will not work if input elements are not in a > > linear order > > One way to make it happen is by storing index of a current element in > > a closure and focusing the element with index = index + 1 when the key > > is pressed > > > > $$(''input[type=text]'').each(function(el, index) { > > el.observe(''keypress'', function(e)) { > > if (Event.KEY_TAB == e.keyCode) { > > $$(''input[type=text]'')[index+1].focus() > > } > > } > > }) > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---