Event Class
The event utility provides functions to add and remove event listeners, event cleansing. It also tries to automatically remove listeners it registers during the unload event.
Index
Methods
- _applyFilter
- _calculateDefaultPoint
- _clean static
- _createTouchList
- _end static
- _getDims
- _getEmptyTouchList
- _isSingleTouch
- _isValidCollection static deprecated
- _load static
- _move
- _poll static
- _simulateEvent
- _start static
- _toRadian
- _unload static
- attach static
- compileFilter static
- define static
- defineOutside static
- delegate static
- delegate static
- detach static
- detach static
- detachDelegate static
- flick
- generateId static
- getEvent static
- getListeners static
- move
- nativeAdd static
- nativeRemove static
- notifySub static
- on static
- onAvailable static deprecated
- onContentReady static deprecated
- pinch
- purgeElement static
- rotate
- simulate static
- simulateGesture static
- startInterval static
- tap
Properties
- _avail static
- _disabledRE
- _dri static
- _el_events static
- _interval static
- _loadComplete static
- _retryCount static
- _wrappers static
- DOMReady static
- lastError static
- POLL_INTERVAL static
- POLL_RETRYS static
Events
Methods
_applyFilter
-
filter
-
args
-
ce
Walks up the parent axis of an event's target, and tests each element against a supplied filter function. If any Nodes, including the container, satisfy the filter, the delegated callback will be triggered for each.
Hosted as a protected property of the delegate
method (e.g.
Y.delegate._applyFilter
).
Parameters:
-
filter
Functionboolean function to test for inclusion in event notification
-
args
Arraythe arguments that would be passed to subscribers
-
ce
CustomEventthe DOM event wrapper
_calculateDefaultPoint
-
point
Helper method to convert a point relative to the node element into the point in the page coordination.
Parameters:
-
point
ArrayA point relative to the node element.
Returns:
The same point in the page coordination.
_clean
-
wrapper
Removes all object references and the DOM proxy subscription for a given event for a DOM node.
Parameters:
-
wrapper
CustomEventCustom event proxy for the DOM subscription
_createTouchList
-
touchPoints
Helper method to convert an array with touch points to TouchList object as defined in http://www.w3.org/TR/touch-events/
Parameters:
-
touchPoints
Array
Returns:
If underlaying platform support creating touch list a TouchList object will be returned otherwise a fake Array object will be returned.
_end
-
event
-
node
-
subscription
-
notifier
-
delegate
-
context
Called when the monitor(s) fires a touchend event (or the mouse equivalent). This method fires the 'tap' event if certain requirements are met.
Parameters:
-
event
DOMEventFacade -
node
Node -
subscription
Array -
notifier
Boolean -
delegate
Boolean -
context
Object
_getDims
()
Array
private
Helper method to get height/width while accounting for rotation/scale transforms where possible by using the bounding client rectangle height/width instead of the offsetWidth/Height which region uses.
Returns:
Array with [height, width]
_getEmptyTouchList
()
TouchList | Array
private
Helper method to return a singleton instance of empty touch list.
Returns:
An empty touch list object.
_isSingleTouch
-
touches
-
targetTouches
-
changedTouches
Helper method to check the single touch.
Parameters:
-
touches
TouchList -
targetTouches
TouchList -
changedTouches
TouchList
_isValidCollection
-
o
We want to be able to use getElementsByTagName as a collection to attach a group of events to. Unfortunately, different browsers return different types of collections. This function tests to determine if the object is array-like. It will also fail if the object is an array, but is empty.
Parameters:
-
o
Objectthe object to test
Returns:
true if the object is array-like and populated
_load
()
private
static
hook up any deferred listeners
_move
-
cb
-
path
-
duration
A base method on top of "move" and "flick" methods. The method takes the path with start/end properties and duration to generate a set of touch events for the movement gesture.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
path
ObjectAn object with "start" and "end" properties. Each property should be an array with x and y coordination (e.g. start: [100, 50])
-
duration
NumberA duration of the gesture in millisecond.
_poll
()
private
static
Polling function that runs before the onload event fires, attempting to attach to DOM Nodes as soon as they are available
_simulateEvent
-
target
-
type
-
options
Parameters:
-
target
HTMLElementThe DOM element that's the target of the event.
-
type
StringThe type of event or name of the supported gesture to simulate (i.e., "click", "doubletap", "flick").
-
options
Object(Optional) Extra options to copy onto the event object. For gestures, options are used to refine the gesture behavior.
_start
-
event
-
node
-
subscription
-
notifier
-
delegate
Called when the monitor(s) are tapped on, either through touchstart or mousedown.
Parameters:
-
event
DOMEventFacade -
node
Node -
subscription
Array -
notifier
Boolean -
delegate
Boolean
_toRadian
-
deg
Helper method to convert a degree to a radian.
Parameters:
-
deg
NumberA degree to be converted to a radian.
Returns:
The degree in radian.
_unload
()
private
static
Removes all listeners registered by pe.event. Called automatically during the unload event.
attach
-
type
-
fn
-
el
-
context
-
args
Adds an event listener
Parameters:
-
type
StringThe type of event to append
-
fn
FunctionThe method the event invokes
-
el
String | HTMLElement | Array | NodeListAn id, an element reference, or a collection of ids and/or elements to assign the listener to.
-
context
Objectoptional context object
-
args
Boolean | Object0..n arguments to pass to the callback
Returns:
an object to that can be used to detach the listener
compileFilter
-
selector
Compiles a selector string into a filter function to identify whether Nodes along the parent axis of an event's target should trigger event notification.
This function is memoized, so previously compiled filter functions are returned if the same selector string is provided.
This function may be useful when defining synthetic events for delegate handling.
Hosted as a property of the delegate
method (e.g. Y.delegate.compileFilter
).
Parameters:
-
selector
Stringthe selector string to base the filtration on
Returns:
define
-
type
-
config
-
force
<p>Defines a new event in the DOM event system. Implementers are responsible for monitoring for a scenario whereby the event is fired. A notifier object is provided to the functions identified below. When the criteria defining the event are met, call notifier.fire( [args] ); to execute event subscribers.</p>
<p>The first parameter is the name of the event. The second parameter is a configuration object which define the behavior of the event system when the new event is subscribed to or detached from. The methods that should be defined in this configuration object are <code>on</code>, <code>detach</code>, <code>delegate</code>, and <code>detachDelegate</code>. You are free to define any other methods or properties needed to define your event. Be aware, however, that since the object is used to subclass SyntheticEvent, you should avoid method names used by SyntheticEvent unless your intention is to override the default behavior.</p>
<p>This is a list of properties and methods that you can or should specify in the configuration object:</p>
<dl> <dt><code>on</code></dt> <dd><code>function (node, subscription, notifier)</code> The implementation logic for subscription. Any special setup you need to do to create the environment for the event being fired--E.g. native DOM event subscriptions. Store subscription related objects and state on the <code>subscription</code> object. When the criteria have been met to fire the synthetic event, call <code>notifier.fire(e)</code>. See Notifier's <code>fire()</code> method for details about what to pass as parameters.</dd>
<dt><code>detach</code></dt> <dd><code>function (node, subscription, notifier)</code> The implementation logic for cleaning up a detached subscription. E.g. detach any DOM subscriptions added in <code>on</code>.</dd>
<dt><code>delegate</code></dt> <dd><code>function (node, subscription, notifier, filter)</code> The implementation logic for subscription via <code>Y.delegate</code> or <code>node.delegate</code>. The filter is typically either a selector string or a function. You can use <code>Y.delegate.compileFilter(selectorString)</code> to create a filter function from a selector string if needed. The filter function expects an event object as input and should output either null, a matching Node, or an array of matching Nodes. Otherwise, this acts like <code>on</code> DOM event subscriptions. Store subscription related objects and information on the <code>subscription</code> object. When the criteria have been met to fire the synthetic event, call <code>notifier.fire(e)</code> as noted above.</dd>
<dt><code>detachDelegate</code></dt> <dd><code>function (node, subscription, notifier)</code> The implementation logic for cleaning up a detached delegate subscription. E.g. detach any DOM delegate subscriptions added in <code>delegate</code>.</dd>
<dt><code>publishConfig</code></dt> <dd>(Object) The configuration object that will be used to instantiate the underlying CustomEvent. See Notifier's <code>fire</code> method for details.</dd>
<dt><code>processArgs</code></dt <dd> <p><code>function (argArray, fromDelegate)</code> Optional method to extract any additional arguments from the subscription signature. Using this allows <code>on</code> or <code>delegate</code> signatures like <code>node.on("hover", overCallback, outCallback)</code>.</p> <p>When processing an atypical argument signature, make sure the args array is returned to the normal signature before returning from the function. For example, in the "hover" example above, the <code>outCallback</code> needs to be <code>splice</code>d out of the array. The expected signature of the args array for <code>on()</code> subscriptions is:</p> <pre> <code>[type, callback, target, contextOverride, argN...]</code> </pre> <p>And for <code>delegate()</code>:</p> <pre> <code>[type, callback, target, filter, contextOverride, argN...]</code> </pre> <p>where <code>target</code> is the node the event is being subscribed for. You can see these signatures documented for <code>Y.on()</code> and <code>Y.delegate()</code> respectively.</p> <p>Whatever gets returned from the function will be stored on the <code>subscription</code> object under <code>subscription._extra</code>.</p></dd> <dt><code>subMatch</code></dt> <dd> <p><code>function (sub, args)</code> Compares a set of subscription arguments against a Subscription object to determine if they match. The default implementation compares the callback function against the second argument passed to <code>Y.on(...)</code> or <code>node.detach(...)</code> etc.</p> </dd> </dl>
Parameters:
-
type
Stringthe name of the event
-
config
Objectthe prototype definition for the new event (see above)
-
force
Booleanoverride an existing event (use with caution)
Returns:
the subclass implementation instance created to handle event subscriptions of this type
defineOutside
-
event
-
name
Defines a new outside event to correspond with the given DOM event.
By default, the created synthetic event name will be the name of the event with "outside" appended (e.g. "click" becomes "clickoutside"). If you want a different name for the created Event, pass it as a second argument like so: <code>Y.Event.defineOutside(eventType, "yonderclick")</code>.
Parameters:
-
event
StringDOM event
-
name
String(optional) custom outside event name
delegate
-
type
-
fn
-
el
-
filter
-
context
-
args
<p>Sets up event delegation on a container element. The delegated event will use a supplied selector or filtering function to test if the event references at least one node that should trigger the subscription callback.</p>
<p>Selector string filters will trigger the callback if the event originated from a node that matches it or is contained in a node that matches it. Function filters are called for each Node up the parent axis to the subscribing container node, and receive at each level the Node and the event object. The function should return true (or a truthy value) if that Node should trigger the subscription callback. Note, it is possible for filters to match multiple Nodes for a single event. In this case, the delegate callback will be executed for each matching Node.</p>
<p>For each matching Node, the callback will be executed with its 'this' object set to the Node matched by the filter (unless a specific context was provided during subscription), and the provided event's <code>currentTarget</code> will also be set to the matching Node. The containing Node from which the subscription was originally made can be referenced as <code>e.container</code>.
Parameters:
-
type
Stringthe event type to delegate
-
fn
Functionthe callback function to execute. This function will be provided the event object for the delegated event.
-
el
String | Nodethe element that is the delegation container
-
filter
String | Functiona selector that must match the target of the event or a function to test target and its parents for a match
-
context
Objectoptional argument that specifies what 'this' refers to.
-
args
Object multiple0..n additional arguments to pass on to the callback function. These arguments will be added after the event object.
Returns:
the detach handle
delegate
-
node
-
subscription
-
notifier
-
filter
Event delegation for the 'tap' event. The delegated event will use a supplied selector or filtering function to test if the event references at least one node that should trigger the subscription callback.
Usage:
node.delegate('tap', function (e) {
Y.log('li a inside node was tapped.');
}, 'li a');
Parameters:
-
node
Node -
subscription
Array -
notifier
Boolean -
filter
String | Function
detach
-
type
-
fn
-
el
Removes an event listener. Supports the signature the event was bound with, but the preferred way to remove listeners is using the handle that is returned when using Y.on
Parameters:
-
type
Stringthe type of event to remove.
-
fn
Functionthe method the event invokes. If fn is undefined, then all event handlers for the type of event are removed.
-
el
String | HTMLElement | Array | NodeList | EventHandleAn event handle, an id, an element reference, or a collection of ids and/or elements to remove the listener from.
Returns:
true if the unbind was successful, false otherwise.
detach
-
node
-
subscription
-
notifier
Detaches all event subscriptions set up by the event-tap module
Parameters:
-
node
Node -
subscription
Array -
notifier
Boolean
detachDelegate
-
node
-
subscription
-
notifier
Detaches the delegated event subscriptions set up by the event-tap module. Only used if you use node.delegate(...) instead of node.on(...);
Parameters:
-
node
Node -
subscription
Array -
notifier
Boolean
flick
-
cb
-
point
-
axis
-
distance
-
duration
The "flick" gesture is a specialized "move" that has some velocity and the movement always runs either x or y axis. The velocity is calculated with "distance" and "duration" arguments. If the calculated velocity is below than the minimum velocity, the given duration will be ignored and new duration will be created to make a valid flick gesture.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
point
ArrayA point(relative to the top left corner of the target node element) where the flick gesture should start. The default is the center of the taget node.
-
axis
StringEither "x" or "y".
-
distance
NumberA distance in pixels to flick.
-
duration
NumberA duration of the gesture in millisecond.
generateId
-
el
Generates an unique ID for the element if it does not already have one.
Parameters:
-
el
Objectthe element to create the id for
Returns:
the resulting id of the element
getEvent
-
e
-
el
Finds the event in the window object, the caller's arguments, or in the arguments of another method in the callstack. This is executed automatically for events registered through the event manager, so the implementer should not normally need to execute this function at all.
Parameters:
-
e
Eventthe event parameter from the handler
-
el
HTMLElementthe element the listener was attached to
Returns:
the event
getListeners
-
el
-
type
Returns all listeners attached to the given element via addListener. Optionally, you can specify a specific type of event to return.
Parameters:
-
el
HTMLElement | Stringthe element or element id to inspect
-
type
Stringoptional type of listener to return. If left out, all listeners will be returned
Returns:
the custom event wrapper for the DOM event(s)
move
-
cb
-
path
-
duration
The "move" gesture simulate the movement of any direction between the straight line of start and end point for the given duration. The path argument is an object with "point", "xdist" and "ydist" properties. The "point" property is an array with x and y coordinations(relative to the top left corner of the target node element) while "xdist" and "ydist" properties are used for the distance along the x and y axis. A negative distance number can be used to drag either left or up direction.
If no arguments are given, it will simulate the default move, which is moving 200 pixels from the center of the element to the positive X-axis direction for 1 sec.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
path
ObjectAn object with "point", "xdist" and "ydist".
-
duration
NumberA duration of the gesture in millisecond.
nativeAdd
-
el
-
type
-
fn
-
capture
Adds a DOM event directly without the caching, cleanup, context adj, etc
Parameters:
-
el
HTMLElementthe element to bind the handler to
-
type
Stringthe type of event handler
-
fn
Functionthe callback to invoke
-
capture
Booleancapture or bubble phase
nativeRemove
-
el
-
type
-
fn
-
capture
Basic remove listener
Parameters:
-
el
HTMLElementthe element to bind the handler to
-
type
Stringthe type of event handler
-
fn
Functionthe callback to invoke
-
capture
Booleancapture or bubble phase
notifySub
-
thisObj
-
args
-
ce
Overrides the <code>_notify</code> method on the normal DOM subscription to inject the filtering logic and only proceed in the case of a match.
This method is hosted as a private property of the delegate
method
(e.g. Y.delegate.notifySub
)
Parameters:
-
thisObj
Objectdefault 'this' object for the callback
-
args
Arrayarguments passed to the event's <code>fire()</code>
-
ce
CustomEventthe custom event managing the DOM subscriptions for the subscribed event on the subscribing node.
Returns:
false if the event was stopped
on
-
node
-
subscription
-
notifier
This function should set up the node that will eventually fire the event.
Usage:
node.on('tap', function (e) {
Y.log('the node was tapped on');
});
Parameters:
-
node
Node -
subscription
Array -
notifier
Boolean
onAvailable
-
id
-
fn
-
p_obj
-
p_override
-
checkContent
Executes the supplied callback when the item with the supplied id is found. This is meant to be used to execute behavior as soon as possible as the page loads. If you use this after the initial page load it will poll for a fixed time for the element. The number of times it will poll and the frequency are configurable. By default it will poll for 10 seconds.
<p>The callback is executed with a single parameter: the custom object parameter, if provided.</p>
Parameters:
-
id
String | | Stringthe id of the element, or an array of ids to look for.
-
fn
Functionwhat to execute when the element is found.
-
p_obj
Objectan optional object to be passed back as a parameter to fn.
-
p_override
Boolean | ObjectIf set to true, fn will execute in the context of p_obj, if set to an object it will execute in the context of that object
-
checkContent
Booleancheck child node readiness (onContentReady)
onContentReady
-
id
-
fn
-
obj
-
override
Works the same way as onAvailable, but additionally checks the state of sibling elements to determine if the content of the available element is safe to modify.
<p>The callback is executed with a single parameter: the custom object parameter, if provided.</p>
Parameters:
-
id
Stringthe id of the element to look for.
-
fn
Functionwhat to execute when the element is ready.
-
obj
Objectan optional object to be passed back as a parameter to fn.
-
override
Boolean | ObjectIf set to true, fn will execute in the context of p_obj. If an object, fn will exectute in the context of that object
pinch
-
cb
-
center
-
startRadius
-
endRadius
-
duration
-
start
-
rotation
The "rotate" and "pinch" methods are essencially same with the exact same arguments. Only difference is the required parameters. The rotate method requires "rotation" parameter while the pinch method requires "startRadius" and "endRadius" parameters.
The "pinch" gesture can simulate various 2 finger gestures such as pinch, spread and/or rotation. The "startRadius" and "endRadius" are required. If endRadius is larger than startRadius, it becomes a spread gesture otherwise a pinch gesture.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
center
ArrayA center point where the pinch gesture of two fingers should happen. It is relative to the top left corner of the target node element.
-
startRadius
NumberA radius of start circle where 2 fingers are on when the gesture starts. This paramenter is required.
-
endRadius
NumberA radius of end circle where 2 fingers will be on when the pinch or spread gestures are completed. This parameter is required.
-
duration
NumberA duration of the gesture in millisecond.
-
start
NumberA start angle(0 degree at 12 o'clock) where the gesture should start. Default is 0.
-
rotation
NumberIf rotation is desired during the pinch or spread gestures, this parameter can be used. Default is 0 degree.
purgeElement
-
el
-
recurse
-
type
Removes all listeners attached to the given element via addListener. Optionally, the node's children can also be purged. Optionally, you can specify a specific type of event to remove.
Parameters:
-
el
HTMLElementthe element to purge
-
recurse
Booleanrecursively purge this element's children as well. Use with caution.
-
type
Stringoptional type of listener to purge. If left out, all listeners will be removed
rotate
-
cb
-
center
-
startRadius
-
endRadius
-
duration
-
start
-
rotation
The "rotate" and "pinch" methods are essencially same with the exact same arguments. Only difference is the required parameters. The rotate method requires "rotation" parameter while the pinch method requires "startRadius" and "endRadius" parameters.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
center
ArrayA center point where the pinch gesture of two fingers should happen. It is relative to the top left corner of the target node element.
-
startRadius
NumberA radius of start circle where 2 fingers are on when the gesture starts. This is optional. The default is a fourth of either target node width or height whichever is smaller.
-
endRadius
NumberA radius of end circle where 2 fingers will be on when the pinch or spread gestures are completed. This is optional. The default is a fourth of either target node width or height whichever is less.
-
duration
NumberA duration of the gesture in millisecond.
-
start
NumberA start angle(0 degree at 12 o'clock) where the gesture should start. Default is 0.
-
rotation
NumberA rotation in degree. It is required.
simulate
-
target
-
type
-
options
Simulates the event or gesture with the given name on a target.
Parameters:
-
target
HTMLElementThe DOM element that's the target of the event.
-
type
StringThe type of event or name of the supported gesture to simulate (i.e., "click", "doubletap", "flick").
-
options
Object(Optional) Extra options to copy onto the event object. For gestures, options are used to refine the gesture behavior.
simulateGesture
-
node
-
name
-
[options]
-
[cb]
Simulates the higher user level gesture of the given name on a target.
This method generates a set of low level touch events(Apple specific gesture
events as well for the iOS platforms) asynchronously. Note that gesture
simulation is relying on Y.Event.simulate()
method to generate
the touch events under the hood. The Y.Event.simulate()
method
itself is a synchronous method.
Users are suggested to use Node.simulateGesture()
method which
basically calls this method internally. Supported gestures are tap
,
doubletap
, press
, move
, flick
, pinch
and rotate
.
The pinch
gesture is used to simulate the pinching and spreading of two
fingers. During a pinch simulation, rotation is also possible. Essentially
pinch
and rotate
simulations share the same base implementation to allow
both pinching and rotation at the same time. The only difference is pinch
requires start
and end
option properties while rotate
requires rotation
option property.
The pinch
and rotate
gestures can be described as placing 2 fingers along a
circle. Pinching and spreading can be described by start and end circles while
rotation occurs on a single circle. If the radius of the start circle is greater
than the end circle, the gesture becomes a pinch, otherwise it is a spread spread.
Parameters:
-
node
HTMLElement | NodeThe YUI node or HTML element that's the target of the event.
-
name
StringThe name of the supported gesture to simulate. The supported gesture name is one of "tap", "doubletap", "press", "move", "flick", "pinch" and "rotate".
-
[options]
Object optionalExtra options used to define the gesture behavior:
Valid options properties for the
tap
gesture:-
[point] (Optional) Indicates the [x,y]
Array optionalcoordinates where the tap should be simulated. Default is the center of the node element.
-
[hold=10]
Number optional(Optional) The hold time in milliseconds. This is the time between
touchstart
andtouchend
event generation. -
[times=1]
Number optional(Optional) Indicates the number of taps.
-
[delay=10]
Number optional(Optional) The number of milliseconds before the next tap simulation happens. This is valid only when
times
is more than 1.Valid options properties for the
doubletap
gesture: -
[point] (Optional) Indicates the [x,y]
Array optionalcoordinates where the doubletap should be simulated. Default is the center of the node element.
Valid options properties for the
press
gesture: -
[point] (Optional) Indicates the [x,y]
Array optionalcoordinates where the press should be simulated. Default is the center of the node element.
-
[hold=3000]
Number optional(Optional) The hold time in milliseconds. This is the time between
touchstart
andtouchend
event generation. Default is 3000ms (3 seconds).Valid options properties for the
move
gesture: -
[path]
Object optional(Optional) Indicates the path of the finger movement. It's an object with three optional properties:
point
,xdist
andydist
.-
[point]
Array optionalA starting point of the gesture. Default is the center of the node element. -
[xdist=200]
Number optionalA distance to move in pixels along the X axis. A negative distance value indicates moving left. -
[ydist=0]
Number optionalA distance to move in pixels along the Y axis. A negative distance value indicates moving up.
-
-
[duration=1000]
Number optional(Optional) The duration of the gesture in milliseconds.
Valid options properties for the
flick
gesture: -
[point] (Optional) Indicates the [x, y]
Array optionalcoordinates where the flick should be simulated. Default is the center of the node element.
-
[axis='x']
String optional(Optional) Valid values are either "x" or "y". Indicates axis to move along. The flick can move to one of 4 directions(left, right, up and down).
-
[distance=200]
Number optional(Optional) Distance to move in pixels
-
[duration=1000]
Number optional(Optional) The duration of the gesture in milliseconds. User given value could be automatically adjusted by the framework if it is below the minimum velocity to be a flick gesture.
Valid options properties for the
pinch
gesture: -
[center]
Array optional(Optional) The center of the circle where two fingers are placed. Default is the center of the node element.
-
[r1]
Number optional(Required) Pixel radius of the start circle where 2 fingers will be on when the gesture starts. The circles are centered at the center of the element.
-
[r2]
Number optional(Required) Pixel radius of the end circle when this gesture ends.
-
[duration=1000]
Number optional(Optional) The duration of the gesture in milliseconds.
-
[start=0]
Number optional(Optional) Starting degree of the first finger. The value is relative to the path of the north. Default is 0 (i.e., 12:00 on a clock).
-
[rotation=0]
Number optional(Optional) Degrees to rotate from the starting degree. A negative value means rotation to the counter-clockwise direction.
Valid options properties for the
rotate
gesture: -
[center]
Array optional(Optional) The center of the circle where two fingers are placed. Default is the center of the node element.
-
[r1]
Number optional(Optional) Pixel radius of the start circle where 2 fingers will be on when the gesture starts. The circles are centered at the center of the element. Default is a fourth of the node element width or height, whichever is smaller.
-
[r2]
Number optional(Optional) Pixel radius of the end circle when this gesture ends. Default is a fourth of the node element width or height, whichever is smaller.
-
[duration=1000]
Number optional(Optional) The duration of the gesture in milliseconds.
-
[start=0]
Number optional(Optional) Starting degree of the first finger. The value is relative to the path of the north. Default is 0 (i.e., 12:00 on a clock).
-
[rotation]
Number optional(Required) Degrees to rotate from the starting degree. A negative value means rotation to the counter-clockwise direction.
-
-
[cb]
Function optionalThe callback to execute when the asynchronouse gesture simulation is completed.
-
err
ErrorAn error object if the simulation is failed.
-
Example:
var node = Y.one("#target");
// double tap example
node.simulateGesture("doubletap", function() {
// my callback function
});
// flick example from the center of the node, move 50 pixels down for 50ms)
node.simulateGesture("flick", {
axis: y,
distance: -100
duration: 50
}, function() {
// my callback function
});
// simulate rotating a node 75 degrees counter-clockwise
node.simulateGesture("rotate", {
rotation: -75
});
// simulate a pinch and a rotation at the same time.
// fingers start on a circle of radius 100 px, placed at top/bottom
// fingers end on a circle of radius 50px, placed at right/left
node.simulateGesture("pinch", {
r1: 100,
r2: 50,
start: 0
rotation: 90
});
startInterval
()
private
static
tap
-
cb
-
point
-
times
-
hold
-
delay
The "tap" gesture can be used for various single touch point gestures such as single tap, N number of taps, long press. The default is a single tap.
Parameters:
-
cb
FunctionThe callback to execute when the gesture simulation is completed.
-
point
ArrayA point(relative to the top left corner of the target node element) where the tap gesture should start. The default is the center of the taget node.
-
times
NumberThe number of taps. Default is 1.
-
hold
NumberThe hold time in milliseconds between "touchstart" and "touchend" event generation. Default is 10ms.
-
delay
NumberThe time gap in millisecond between taps if this gesture has more than 1 tap. Default is 10ms.
Properties
_avail
Unknown
private
static
onAvailable listeners
_disabledRE
RegExp
protected
Regex to test for disabled elements during filtering. This is only relevant to
IE to normalize behavior with other browsers, which swallow events that occur
to disabled elements. IE fires the event from the parent element instead of the
original target, though it does preserve event.srcElement
as the disabled
element. IE also supports disabled on <a>
, but the event still bubbles, so it
acts more like e.preventDefault()
plus styling. That issue is not handled here
because other browsers fire the event on the <a>
, so delegate is supported in
both cases.
_dri
Unknown
private
static
document readystate poll handle
_el_events
Unknown
private
static
Custom event wrapper map DOM events. Key is Element uid stamp. Each item is a hash of custom event wrappers as provided in the _wrappers collection. This provides the infrastructure for getListeners.
_interval
Unknown
private
static
poll handle
_loadComplete
Boolean
private
static
True after the onload event has fired
_retryCount
Unknown
private
static
The number of times to poll after window.onload. This number is increased if additional late-bound handlers are requested after the page load.
_wrappers
CustomEvent
private
static
Custom event wrappers for DOM events. Key is 'event:' + Element uid stamp + event type
DOMReady
Boolean
static
True when the document is initially usable
lastError
Error
static
addListener/removeListener can throw errors in unexpected scenarios. These errors are suppressed, the method returns false, and this property is set
POLL_INTERVAL
Int
final
static
The poll interval in milliseconds
POLL_RETRYS
Int
final
static
The number of times we should look for elements that are not in the DOM at the time the event is requested after the document has been loaded. The default is 1000@amp;40 ms, so it will poll for 40 seconds or until all outstanding handlers are bound (whichever comes first).
Events
tap
Sets up a "tap" event, that is fired on touch devices in response to a tap event (finger down, finder up). This event can be used instead of listening for click events which have a 500ms delay on most touch devices. This event can also be listened for using node.delegate().
Event Payload:
-
type
String"tap"
-
fn
FunctionThe method the event invokes. It receives the event facade of the underlying DOM event.