RFLudwick wrote:
> I'm trying to tie in all of a website's event handlers in HTML to
> Prototype. I.e.
>
> <a onclick="..."></a>
>
> I can't easily strip out these event handlers from the HTML and put
> them in Javascript, but I would like to get them into Prototype's
> event handling system so they can unregister for IE, etc.
>
> I believe what I'm looking for is Event.extend(), but the
> documentation on it is minimal and it tells of extending an event
> registered in other ways. But how exactly do I retrieve the onclick
> event of a link as it is defined in HTML?
>
> ...
Doesn't sound like a good idea. Such code will be pretty complicated and 
run slowly. Here is something that conceptually would work:


var code, fn, elements = document.getElementsByTagName('*');
// check each element
for (var i = 0, len = elements.length; i < len; i++) {
  // check each possible event (whatever events you might find in your code)
  $w('blur focus resize scroll load unload click dblclick mousedown 
mouseup mousemove mouseover mouseout change reset select submit keydown 
keypress keyup error').each(function(eventName) {
    if (code = elements[i]['on' + eventName]) {
      // replace "return false" with "Event.stop()" in function body
      code = String(code).replace('return false', 'Event.stop(event)');
      // create a function by evaluating the contents of the event attribute
      fn = eval('function(event) { ' + code + '}');
      // translate event names as needed
      eventName = (eventName == 'load' : 'dom:loaded' : eventName);
      // attach the event to the element
      $(elements[i]).observe(eventName, fn.bindAsEventListener());
    }
  });
}



There may be other things to account for.

- Ken Snyder




--~--~---------~--~----~------------~-------~--~----~
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