Michael Stillwell
2008-Apr-11 06:24 UTC
how to annotate select elements in a prototype-like way?
I''ve written a function that takes a select element and adds an
"add
new option ..." option to it (as well as various behaviours to support
this). What''s the most prototype-like way to invoke this on a
particular element?
I could do:
function annotate(e) { ... };
annotate(select_element);
select_element.observe("data:change", function() { ... });
but that sort of construction ("raw" function calls) doesn''t
seem to
be used in prototype, and doesn''t feel right.
So, what I''m doing at the moment is:
Element.addMethods({
annotate: function(e) { ... }
});
select_element.annotate();
select_element.observe("data:change", function() { ... });
but this unsatisfactory too, because that adds the annotate() method
to all extended elements.
Is there a better way?
Cheers,
Michael
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Element.addMethods accepts specific tag name (optionally)
Element.addMethods(''select'', { ... }); // will extend
<select>
elements only
- kangax
On Apr 11, 2:24 am, Michael Stillwell
<ithinkihavea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''ve written a function that takes a select element and adds an
"add
> new option ..." option to it (as well as various behaviours to support
> this). What''s the most prototype-like way to invoke this on a
> particular element?
>
> I could do:
>
> function annotate(e) { ... };
>
> annotate(select_element);
> select_element.observe("data:change", function() { ... });
>
> but that sort of construction ("raw" function calls)
doesn''t seem to
> be used in prototype, and doesn''t feel right.
>
> So, what I''m doing at the moment is:
>
> Element.addMethods({
>
> annotate: function(e) { ... }
>
> });
>
> select_element.annotate();
> select_element.observe("data:change", function() { ... });
>
> but this unsatisfactory too, because that adds the annotate() method
> to all extended elements.
>
> Is there a better way?
>
> Cheers,
> Michael
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---