#203 enhancement
Ken Snyder

Add Event.addMethods to allow adding methods to Event instances

Reported by Ken Snyder | July 3rd, 2008 @ 06:23 AM

I've created a patch that will allow developers to roll out their own Event instance methods.

Examples of such methods:

getKeyCode - gets event.keyCode or event.charCode, whichever is set

getAscii - gets the ASCII code of the key pressed (if any)

getWheelDetail - gets event.detail or event.wheelDelta, whichever is set

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev July 3rd, 2008 @ 03:54 PM

    I think it might make sense to use an event decorator/wrapper rather than extending event object with methods. Events have read-only properties, extending them might introduce name-clashes. Wrappers could solve these problems.

  • Ken Snyder

    Ken Snyder July 3rd, 2008 @ 04:34 PM

    Hmm. Maybe I'm taking the wrong approach then. I see that Prototype adds methods to all event instances such as stop, inspect, isRightClick. As a developer, I would like to add additional methods.

  • Juriy Zaytsev

    Juriy Zaytsev July 3rd, 2008 @ 04:38 PM

    Ken, I understand exactly what you mean. As a matter of fact I'm using almost identical patch for quite some time : ) (with custom methods like Event#isPointerWithin)

    I'm just thinking out loud about a future of our Event implementation. Do you think wrappers would make sense?

  • John-David Dalton

    John-David Dalton July 7th, 2008 @ 03:54 PM

    • State changed from “new” to “enhancement”
    +1 For wrappers.
    It's the only way to avoid Host Object/Native Object conflicts/bugs.
    For example Opera's implementation of event.timestamp returns 0.
    If you try to change that it causes an error.
    With wrappers we could avoid things like that.
    
    Also with Element methods if we used a wrapper we wouldn't have to worry about 
    form elements and the "select" method and others
    
    Also I dig late binding mixins :)
    
  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:55 AM

    • Tag changed from events, patched to patched, section:dom

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:56 AM

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Attachments

Pages