Element.addMethods accepts specific tag name (optionally)

Element.addMethods('select', { ... }); // will extend <select>
elements only

- kangax

On Apr 11, 2:24 am, Michael  Stillwell <[EMAIL PROTECTED]>
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to