Extending events
Some events, such as mouseenter
and ready
, are designated as special events by the jQuery internals. These events use the elaborate event extension framework offered by jQuery. Such events get the opportunity to take action at various times in the life cycle of an event handler. They may react to handlers being bound or unbound, and they can even have preventable default behaviors like clicked links or submitted forms do. The event extension API lets us create sophisticated new events that act much like native DOM events.
The throttling behavior we implemented for scrolling in Listing 10.13 is useful, and we may want to generalize it for use in other projects. We can accomplish this by creating a new event that encapsulates the throttling technique within the special event hooks.
To implement special behavior for an event, we add a property to the $.event.special
object. This added property, which is itself an object, has our event name as its key. It can contain callbacks...