Project Outline
«
pulp javascript framework

Class pulp.event

Defined in: pulp.event.js.

Constructor
^ top
new pulp.event()
Return a pulp.event instance given an Event object

                  
                  
                  
                    
                      
Parameters:
{Event}
Field Summary
^ top
raw The raw event object
custom Allows plugging in custom events
_cache The internal cache of attached events to enable detachment.
_identify Get a node's id, assign one if it doesn't have one, and return <window> and <document> as appropriate
observable An observable interface that is copied to pulp.event
eventDetail A collection of methods to be called on an Event object.
Method Summary
^ top
_byId(id) Get an object by id
_attachAndCache(node, type, handlerOriginal, handlerToCall) Attach a handler and add to pulp.event.
_detachAndCleanCache(node, type, handlerOriginal) Remove a handler and its entry in pulp.event.
_addDispatcher(node, type) Create dispatcher and addEventListener (one dispatcher per element per event)
_removeDispatcher(node, type, handler) Run removeEventListener for the given element an event
observe(node, type, handler) (chainable) Register a handler to be called on the given event for the given HTMLElement
stopObserving(node, type, handler) (chainable) Unegister a handler for the given event for the given HTMLElement
fire(node, type [, data]) (chainable) Manually trigger all handlers associated with the given node and event.
listHandlers([node] [, type]) Return an Array of handlers registered to the given node for the given event type.
ready(handler) (chainable) Shorthand for register a handler to be fired on dom:loaded
isLeftClick(event) Return true if the click event included the left click button
isMiddleClick(event) Return true if the click event included the middle click button
isRightClick(event) Return true if the click event included the right click button
getRelatedTarget(event) Get the node from which the mouse came before the event fired as in mouseover.
findParent(event [, tagName]) Find the parentNode of the event target with the given tagName.
pointer(event) Return an object with properties x and y representing the coordinates of the mouse pointer at the time the event fired.
pointerX(event) Return the x coordinate of the mouse pointer at the time the event fired
pointerY(event) Return the x coordinate of the mouse pointer at the time the event fired
stop(event) (chainable) Prevent the default action and stop the event's propagation.
getKeyCode(event) Return the Browser character code for the pressed key.
getWheelDirection(event) Return -1, 0, or 1 to represent the mouse wheel scrolling up, none, or down respectively.
element(event) Return event's target.
isButton(event, code)
listObservers() alias of pulp.event.listHandlers, pulp.event#listHandlers, and pulp.event.observable.listHandlers
stopDelegating(selector, type, handler, delegator, bubbleLevel) Remove a handler
Field Detail
^ top
raw
The raw event object

									
								
									
										
										
										
										
				
								
pulp.event.isIE : True if browser reports itself as IE

									
								
									
										
										
										
										
				
								
pulp.event.isWebkit : True if browser reports itself as Webkit

									
								
									
										
										
										
										
				
								
pulp.event.isOpera : True if browser reports itself as Opera

									
								
									
										
										
										
										
				
								
pulp.event.custom
Allows plugging in custom events

									
								
									
										
										
										
										
				
								
pulp.event._cache
The internal cache of attached events to enable detachment. Example cache structure: { myid: { mouseover: [
, mouseover, handlerOriginal, handlerToCall] } }

									
								
									
										
										
										
										
				
								
pulp.event._identify : String
Get a node's id, assign one if it doesn't have one, and return and as appropriate

									
								
									
										
										
										
										
				
								
pulp.event.observable
An observable interface that is copied to pulp.event

									
								
									
										
										
										
										
				
								
pulp.event.eventDetail
A collection of methods to be called on an Event object. These can be called statically as in "pulp.event.stop(event)" or on an instance as in "new pulp.event(event).stop()"

									
								
									
										
										
										
										
				
								
Method Detail
^ top
pulp.event._byId(id) -> HTMLElement
Get an object by id

										
									
Parameters:
{String} id a dom node id or dom node
Returns:
{HTMLElement}
pulp.event._attachAndCache(node, type, handlerOriginal, handlerToCall) -> undefined
Attach a handler and add to pulp.event._cache

										
									
Parameters:
{HTMLElement} node The node to observe
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Function} handlerOriginal The function that will be used to detach
{Function} handlerToCall The possibly altered function that will be called on the event
Returns:
{undefined}
pulp.event._detachAndCleanCache(node, type, handlerOriginal) -> undefined
Remove a handler and its entry in pulp.event._cache

										
									
Parameters:
{HTMLElement} node The node that was observed
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Function} handlerOriginal The function originally passed in the observe call
Returns:
{undefined}
pulp.event._addDispatcher(node, type) -> Function
Create dispatcher and addEventListener (one dispatcher per element per event)

										
									
Parameters:
{HTMLElement} node The node to observe
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
Returns:
{Function} The newly created dispatcher
pulp.event._removeDispatcher(node, type, handler) -> undefined
Run removeEventListener for the given element an event

										
									
Parameters:
{HTMLElement} node The node to observe
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Function} handler The dispatcher function that was created in pulp.event._addDispatcher
Returns:
{undefined}
pulp.event.observe(node, type, handler) -> HTMLElement
Register a handler to be called on the given event for the given HTMLElement

										
									
Parameters:
{HTMLElement|String} node The node to observe
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Function} handler The function to call
Returns:
{HTMLElement} The HTMLElement given or the HTMLElement with the given id
pulp.event.stopObserving(node, type, handler) -> HTMLElement
Unegister a handler for the given event for the given HTMLElement

										
									
Parameters:
{HTMLElement|String} node The node on which to unregister
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Function} handler The function that was originally registered
Returns:
{HTMLElement} The HTMLElement given or the HTMLElement with the given id
pulp.event.fire(node, type [, data]) -> HTMLElement
Manually trigger all handlers associated with the given node and event. Optionally pass an object with data that is sent as the first argument to each handler.

										
									
Parameters:
{HTMLElement|String} node The node on which to fire
{String} type The event name (e.g. mouseover, click, dblclick, etc.)
{Object} data?, Default: Information to send to each handler
Returns:
{HTMLElement} The HTMLElement given or the HTMLElement with the given id
pulp.event.listHandlers([node] [, type]) -> Function[]
Return an Array of handlers registered to the given node for the given event type. If type is not specified, all handlers for the node are returned. If node is not specified, all handlers for any node are returned.

										
									
Parameters:
{HTMLElement|String} node?, Default: The node on which to look
{String} type?, Default: The event name (e.g. mouseover, click, dblclick, etc.)
Returns:
{Function[]} Array of functions that were registered
pulp.event.ready(handler) -> pulp.event
Shorthand for register a handler to be fired on dom:loaded

										
									
Parameters:
{Function} handler The handler to fire
Returns:
{pulp.event}
pulp.event.isLeftClick(event) -> Boolean
Return true if the click event included the left click button

										
									
Parameters:
{Event} event
Returns:
{Boolean}
pulp.event.isMiddleClick(event) -> Boolean
Return true if the click event included the middle click button

										
									
Parameters:
{Event} event
Returns:
{Boolean}
pulp.event.isRightClick(event) -> Boolean
Return true if the click event included the right click button

										
									
Parameters:
{Event} event
Returns:
{Boolean}
pulp.event.getRelatedTarget(event) -> HTMLElement|null
Get the node from which the mouse came before the event fired as in mouseover. This value can be null as in the case when the mouse moves into the node from outside the window.

										
									
Parameters:
{Event} event
Returns:
{HTMLElement|null}
pulp.event.findParent(event [, tagName]) -> HTMLElement|null
Find the parentNode of the event target with the given tagName. If tagName is omitted, the direct parent is returned. If pulp.cssQuery is present, tagName may optionally be a css selector and the first parent matching the selector will be returned.

										
									
Parameters:
{Event} event
{String} tagName?, Default:
Returns:
{HTMLElement|null}
pulp.event.pointer(event) -> Object
Return an object with properties x and y representing the coordinates of the mouse pointer at the time the event fired.

										
									
Parameters:
{Event} event
Returns:
{Object} Object with properties x and y which are both numbers
pulp.event.pointerX(event) -> Number
Return the x coordinate of the mouse pointer at the time the event fired

										
									
Parameters:
{Event} event
Returns:
{Number}
pulp.event.pointerY(event) -> Number
Return the x coordinate of the mouse pointer at the time the event fired

										
									
Parameters:
{Event} event
Returns:
{Number}
pulp.event.stop(event) -> Event
Prevent the default action and stop the event's propagation. Stop a default action: do not follow link; do not submit form; etc. Stop propagation: do not trigger other handlers on this element or any parent element.

										
									
Parameters:
{Event} event
Returns:
{Event}
pulp.event.getKeyCode(event) -> Number
Return the Browser character code for the pressed key. Should be used with the native JavaScript function String.fromCharCode(). Note that beyond alphanumeric characters, browsers are inconsistent with code meanings.

										
									
Parameters:
{Event} event
Returns:
{Number}
pulp.event.getWheelDirection(event) -> Number
Return -1, 0, or 1 to represent the mouse wheel scrolling up, none, or down respectively.

										
									
Parameters:
{Event} event
Returns:
{Number}
pulp.event.element(event) -> Number
Return event's target. If pulp.node is present, return a new pulp.node object

										
									
Parameters:
{Event} event
Returns:
{Number}
pulp.event.isButton(event, code) -> Boolean

										
									
Parameters:
{Event} event The event object which to read
{Number} code The button code number to test for (0=left, 1=middle, 2=right)
Returns:
{Boolean} If true, that button was pressed
pulp.event.listObservers()
alias of pulp.event.listHandlers, pulp.event#listHandlers, and pulp.event.observable.listHandlers

										
									
pulp.event.stopDelegating(selector, type, handler, delegator, bubbleLevel) -> Element
Remove a handler

Defined in: pulp.event.delegate.js.

  // pass arguments
  pulp.event.stopDelegating('a.modal', 'click', displayMyModal);
  pulp.event.stopDelegating('div.expand', 'click', expandSection);
  
  // pass a "ruleset" object
  pulp.event.stopDelegating({
    'a.modal': {
      click: displayMyModal
    },
    'div.expand': {
      click: expandSection
    }
  });
Parameters:
{String} selector The CSS selector identifying a set of elements
{String} type The event type (e.g. mouseover, click, etc.)
{Function} handler The function to call when the event is triggered
{String|Element} delegator [optional] The parent container inside which events are observed [default=document]
{Number} bubbleLevel [optional] The number of steps to traverse up the DOM tree to look for matches [default=0]
Returns:
{Element} The element passed
Documentation generated by JsDoc Toolkit 2.1.0 on Tue Aug 18 2009 22:40:28; Template based on jProton by Pedro Simonetti