static
Class Event
private static object
private static object
private static Y.Event.Custom
static Error
static final int
private
static
boolean
_isValidCollection
(
o
)
o
<object>
the object to test
boolean
private
static
void
_poll
(
)
private
static
void
_unload
(
)
static
EventHandle
attach
(
type
,
fn
,
el
,
context
,
args
)
type
<String>
The type of event to append
fn
<Function>
The method the event invokes
el
<String|HTMLElement|Array|NodeList>
An id, an element
reference, or a collection of ids and/or elements to assign the
listener to.
context
<Object>
optional context object
args
<Boolean|object>
0..n arguments to pass to the callback
EventHandle
static
boolean
detach
(
type
,
fn
,
el
)
type
<String>
the type of event to remove.
fn
<Function>
the method the event invokes. If fn is
undefined, then all event handlers for the type of event are
removed.
el
<String|HTMLElement|Array|NodeList|EventHandle>
An
event handle, an id, an element reference, or a collection
of ids and/or elements to remove the listener from.
boolean
static
SyntheticEvent
Event.define
(
type
,
config
,
force
)
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.
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 on
,
detach
, delegate
, and detachDelegate
.
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.
This is a list of properties and methods that you can or should specify in the configuration object:
on
function (node, subscription, notifier)
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 subscription
object. When the
criteria have been met to fire the synthetic event, call
notifier.fire(e)
. See Notifier's fire()
method for details about what to pass as parameters.detach
function (node, subscription, notifier)
The
implementation logic for cleaning up a detached subscription. E.g.
detach any DOM subscriptions added in on
.delegate
function (node, subscription, notifier, filter)
The
implementation logic for subscription via Y.delegate
or
node.delegate
. The filter is typically either a selector
string or a function. You can use
Y.delegate.compileFilter(selectorString)
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 on
DOM event subscriptions. Store subscription
related objects and information on the subscription
object. When the criteria have been met to fire the synthetic event,
call notifier.fire(e)
as noted above.detachDelegate
function (node, subscription, notifier)
The
implementation logic for cleaning up a detached delegate subscription.
E.g. detach any DOM delegate subscriptions added in
delegate
.publishConfig
fire
method
for details.processArgs
function (argArray, fromDelegate)
Optional method
to extract any additional arguments from the subscription
signature. Using this allows on
or
delegate
signatures like
node.on("hover", overCallback,
outCallback)
.
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 outCallback
needs to be splice
d
out of the array. The expected signature of the args array for
on()
subscriptions is:
[type, callback, target, contextOverride, argN...]
And for delegate()
:
[type, callback, target, filter, contextOverride, argN...]
where target
is the node the event is being
subscribed for. You can see these signatures documented for
Y.on()
and Y.delegate()
respectively.
Whatever gets returned from the function will be stored on the
subscription
object under
subscription._extra
.
subMatch
function (sub, args)
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
Y.on(...)
or node.detach(...)
etc.
type
<String>
the name of the event
config
<Object>
the prototype definition for the new event (see above)
force
<Boolean>
override an existing event (use with caution)
SyntheticEvent
static
string
generateId
(
el
)
el
<object>
the element to create the id for
string
static
Event
getEvent
(
e
,
el
)
e
<Event>
the event parameter from the handler
el
<HTMLElement>
the element the listener was attached to
Event
static
Y.Custom.Event
getListeners
(
el
,
type
)
el
<HTMLElement|string>
the element or element id to inspect
type
<string>
optional type of listener to return. If
left out, all listeners will be returned
Y.Custom.Event
private
static
void
nativeAdd
(
el
,
type
,
fn
,
capture
)
el
<HTMLElement>
the element to bind the handler to
type
<string>
the type of event handler
fn
<function>
the callback to invoke
capture
<boolen>
capture or bubble phase
private
static
void
nativeRemove
(
el
,
type
,
fn
,
capture
)
el
<HTMLElement>
the element to bind the handler to
type
<string>
the type of event handler
fn
<function>
the callback to invoke
capture
<boolen>
capture or bubble phase
static
void
onAvailable
(
id
,
fn
,
p_obj
,
p_override
,
checkContent
)
The callback is executed with a single parameter: the custom object parameter, if provided.
id
<string||string[]>
the id of the element, or an array
of ids to look for.
fn
<function>
what to execute when the element is found.
p_obj
<object>
an optional object to be passed back as
a parameter to fn.
p_override
<boolean|object>
If 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
<boolean>
check child node readiness (onContentReady)
static
void
onContentReady
(
id
,
fn
,
obj
,
override
)
The callback is executed with a single parameter: the custom object parameter, if provided.
id
<string>
the id of the element to look for.
fn
<function>
what to execute when the element is ready.
obj
<object>
an optional object to be passed back as
a parameter to fn.
override
<boolean|object>
If set to true, fn will execute
in the context of p_obj. If an object, fn will
exectute in the context of that object
static
void
purgeElement
(
el
,
recurse
,
type
)
el
<HTMLElement>
the element to purge
recurse
<boolean>
recursively purge this element's children
as well. Use with caution.
type
<string>
optional type of listener to purge. If
left out, all listeners will be removed
static
void
simulate
(
target
,
type
,
options
)
target
<HTMLElement>
The DOM element that's the target of the event.
type
<String>
The type of event to simulate (i.e., "click").
options
<Object>
(Optional) Extra options to copy onto the event object.