TempEvent.js revision 401e53f52972a8dd26da029c0ff475f591ce303b
// Temporary wrapper for the 2.x event
//
// This will be broken into descrete modules
//
//
//
/**
* The Event.Custom class lets you define events for your application
* that can be subscribed to by one or more independent component.
*
* @param {String} type The type of event, which is passed to the callback
* when the event fires
* @param {Object} context The context the event will fire from. "this" will
* refer to this object in the callback. Default value:
* the window object. The listener can override this.
* @param {boolean} silent pass true to prevent the event from writing to
* the debugsystem
* @param {int} signature the signature that the custom event subscriber
* will receive. Y.Event.Custom.LIST or
* Y.Event.Custom.FLAT. The default is
* Y.Event.Custom.LIST.
* @namespace Y
* @class Event.Custom
* @constructor
*/
/**
* The type of event, returned to subscribers when the event fires
* @property type
* @type string
*/
/**
* The context the the event will fire from by default. Defaults to the YUI
* instance.
* @property context
* @type object
*/
/**
* By default all custom events are logged in the debug build, set silent
* to true to disable debug outpu for this event.
* @property silent
* @type boolean
*/
/**
* Custom events support two styles of arguments provided to the event
* subscribers.
* <ul>
* <li>Y.Event.Custom.LIST:
* <ul>
* <li>param1: event name</li>
* <li>param2: array of arguments sent to fire</li>
* <li>param3: <optional> a custom object supplied by the subscriber</li>
* </ul>
* </li>
* <li>Y.Event.Custom.FLAT
* <ul>
* <li>param1: the first argument passed to fire. If you need to
* pass multiple parameters, use and array or object literal</li>
* <li>param2: <optional> a custom object supplied by the subscriber</li>
* </ul>
* </li>
* </ul>
* @property signature
* @type int
*/
/**
* The subscribers to this event
* @property subscribers
* @type Event.Subscriber[]
*/
this.subscribers = [];
if (!this.silent) {
}
var onsubscribeType = "_YUICEOnSubscribe";
// Only add subscribe events for events that are not generated by
// Event.Custom
if (type !== onsubscribeType) {
/**
* Custom events provide a custom event that fires whenever there is
* a new subscriber to the event. This provides an opportunity to
* handle the case where there is a non-repeating event that has
* already fired has a new subscriber.
*
* @event subscribeEvent
* @type Y.Event.Custom
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
* fires
* @param {boolean|Object} override If true, the obj passed in becomes
* the execution context of the listener.
* if an object, that object becomes the
* the execution context.
*/
this.subscribeEvent =
new Y.CustomEvent(onsubscribeType, this, true);
/**
* This event fires only once if true
*
* @property once
* @type boolean
* @default false;
*/
this.once = false;
/**
* This event has fired if true
*
* @property fired
* @type boolean
* @default false;
*/
this.fired = false;
/**
* This event should only fire one time if true, and if
* it has fired, any new subscribers should be notified
* immediately.
*
* @property fireOnce
* @type boolean
* @default false;
*/
this.fireOnce = false;
}
/**
* In order to make it possible to execute the rest of the subscriber
* stack when one thows an exception, the subscribers exceptions are
* caught. The most recent exception is stored in this property
* @property lastError
* @type Error
*/
this.lastError = null;
};
/**
* Event.Subscriber listener sigature constant. The LIST type returns three
* parameters: the event type, the array of args passed to fire, and
* the optional custom object
* @property Y.Event.Custom.LIST
* @static
* @type int
*/
/**
* Event.Subscriber listener sigature constant. The FLAT type returns two
* parameters: the first argument passed to fire and the optional
* custom object
* @property Y.Event.Custom.FLAT
* @static
* @type int
*/
Y.CustomEvent.prototype = {
/**
* Subscribes the caller to this event
* @method subscribe
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
* fires
* @param {boolean|Object} override If true, the obj passed in becomes
* the execution context of the listener.
* if an object, that object becomes the
* the execution context.
*/
if (!fn) {
}
if (this.subscribeEvent) {
}
this._notify(s);
}
this.subscribers.push(s);
},
/**
* Unsubscribes subscribers.
* @method unsubscribe
* @param {Function} fn The subscribed function to remove, if not supplied
* all will be removed
* @param {Object} obj The custom object passed to subscribe. This is
* optional, but if supplied will be used to
* disambiguate multiple listeners that are the same
* (e.g., you subscribe many object using a function
* that lives on the prototype)
* @return {boolean} True if the subscriber was found and detached.
*/
if (!fn) {
return this.unsubscribeAll();
}
var found = false;
var s = this.subscribers[i];
this._delete(i);
found = true;
}
}
return found;
},
if (!this.silent) {
"info", "Event" );
}
var param = null;
}
try {
} catch(e) {
this.lastError = e;
Y.log(this + " subscriber exception: " + e,
"error", "Event");
}
} else {
try {
} catch(ex) {
"error", "Event");
}
}
if (false === ret) {
if (!this.silent) {
}
//break;
return false;
}
return true;
},
/**
* Notifies the subscribers. The callback functions will be executed
* from the context specified when the event was created, and with the
* following parameters:
* <ul>
* <li>The type of event</li>
* <li>All of the arguments fire() was executed with as an array</li>
* <li>The custom object (if any) that was passed into the subscribe()
* method</li>
* </ul>
* @method fire
* @param {Object*} arguments an arbitrary set of parameters to pass to
* the handler.
* @return {boolean} false if one of the subscribers returned false,
* true otherwise
*/
fire: function() {
return true;
}
if (!this.silent) {
"subscribers: " + len,
"info", "Event" );
}
for (i=0; i<len; ++i) {
var s = this.subscribers[i];
if (!s) {
rebuild=true;
} else {
if (!ret) {
break;
}
}
}
if (rebuild) {
}
this.subscribers=newlist;
}
this.fired = true;
return ret;
},
/**
* Removes all listeners
* @method unsubscribeAll
* @return {int} The number of listeners unsubscribed
*/
unsubscribeAll: function() {
}
this.subscribers=[];
return i;
},
/**
* @method _delete
* @private
*/
var s = this.subscribers[index];
if (s) {
delete s.fn;
delete s.obj;
}
this.subscribers[index]=null;
},
/**
* @method toString
*/
toString: function() {
"context: " + this.context;
}
};
/////////////////////////////////////////////////////////////////////
/**
* Stores the subscriber information to be used when the event fires.
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event fires
* @param {boolean} override If true, the obj passed in becomes the execution
* context of the listener
* @class Event.Subscriber
* @constructor
*/
/**
* The callback that will be execute when the event fires
* @property fn
* @type function
*/
/**
* An optional custom object that will passed to the callback when
* the event fires
* @property obj
* @type object
*/
/**
* The default execution context for the event listener is defined when the
* event is created (usually the object which contains the event).
* By setting override to true, the execution context becomes the custom
* object passed in by the subscriber. If override is an object, that
* object becomes the context.
* @property override
* @type boolean|object
*/
};
/**
* Returns the execution context for this listener. If override was set to true
* the custom obj will be the context. If override is an object, that is the
* context, otherwise the default context will be used.
* @method getScope
* @param {Object} defaultScope the context to use if this listener does not
* override it.
*/
if (this.override) {
if (this.override === true) {
return this.obj;
} else {
return this.override;
}
}
return defaultScope;
};
/**
* Returns true if the fn and obj match this objects properties.
* Used by the unsubscribe method to match the right subscriber.
*
* @method contains
* @param {Function} fn the function to execute
* @param {Object} obj an object to be passed along when the event fires
* @return {boolean} true if the supplied arguments match this
* subscriber's signature.
*/
if (obj) {
} else {
}
};
/**
* @method toString
*/
return "Subscriber { obj: " + this.obj +
};
/**
* The Event Utility provides utilities for managing DOM Events and tools
* for building event systems
*
* @module event
* @title Event Utility
* @namespace Y
* @requires yahoo
*/
// The first instance of Event will win if it is loaded more than once.
// @TODO this needs to be changed so that only the state data that needs to
// be preserved is kept, while methods are overwritten/added as needed.
// This means that the module pattern can't be used.
if (!Y.Event) {
/**
* 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.
*
* @class Event
* @static
*/
Y.Event = function() {
/**
* True after the onload event has fired
* @property loadComplete
* @type boolean
* @static
* @private
*/
var loadComplete = false;
/**
* Cache of wrapped listeners
* @property listeners
* @type array
* @static
* @private
*/
var listeners = [];
/**
* User-defined unload function that will be fired before all events
* are detached
* @property unloadListeners
* @type array
* @static
* @private
*/
var unloadListeners = [];
/**
* Cache of DOM0 event handlers to work around issues with DOM2 events
* in Safari
* @property legacyEvents
* @static
* @private
*/
var legacyEvents = [];
/**
* Listener stack for DOM0 events
* @property legacyHandlers
* @static
* @private
*/
var legacyHandlers = [];
/**
* The number of times to poll after window.onload. This number is
* increased if additional late-bound handlers are requested after
* the page load.
* @property retryCount
* @static
* @private
*/
var retryCount = 0;
/**
* onAvailable listeners
* @property onAvailStack
* @static
* @private
*/
var onAvailStack = [];
/**
* Lookup table for legacy events
* @property legacyMap
* @static
* @private
*/
var legacyMap = [];
/**
* Counter for auto id generation
* @property counter
* @static
* @private
*/
var counter = 0;
/**
* @property webkitKeymap
* @type {int: int}
* @private
* @static
* @final
*/
var webkitKeymap = {
63232: 38, // up
63233: 40, // down
63234: 37, // left
63235: 39, // right
63276: 33, // page up
63277: 34, // page down
25: 9 // SHIFT-TAB (Safari provides a different key code in
// this case, even though the shiftKey modifier is set)
};
return {
/**
* 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 2000@amp;20 ms, so it will poll
* for 40 seconds or until all outstanding handlers are bound
* (whichever comes first).
* @property POLL_RETRYS
* @type int
* @static
* @final
*/
POLL_RETRYS: 2000,
/**
* The poll interval in milliseconds
* @property POLL_INTERVAL
* @type int
* @static
* @final
*/
POLL_INTERVAL: 20,
/**
* Element to bind, int constant
* @property EL
* @type int
* @static
* @final
*/
EL: 0,
/**
* Type of event, int constant
* @property TYPE
* @type int
* @static
* @final
*/
TYPE: 1,
/**
* Function to execute, int constant
* @property FN
* @type int
* @static
* @final
*/
FN: 2,
/**
* Function wrapped for context correction and cleanup, int constant
* @property WFN
* @type int
* @static
* @final
*/
WFN: 3,
/**
* Object passed in by the user that will be returned as a
* parameter to the callback, int constant. Specific to
* unload listeners
* @property OBJ
* @type int
* @static
* @final
*/
UNLOAD_OBJ: 3,
/**
* Adjusted context, either the element we are registering the event
* on or the custom object passed in by the listener, int constant
* @property ADJ_SCOPE
* @type int
* @static
* @final
*/
ADJ_SCOPE: 4,
/**
* The original obj passed into addListener
* @property OBJ
* @type int
* @static
* @final
*/
OBJ: 5,
/**
* The original context parameter passed into addListener
* @property OVERRIDE
* @type int
* @static
* @final
*/
OVERRIDE: 6,
/**
* addListener/removeListener can throw errors in unexpected scenarios.
* These errors are suppressed, the method returns false, and this property
* is set
* @property lastError
* @static
* @type Error
*/
lastError: null,
/**
* Safari detection
* @property isSafari
* @private
* @static
* @deprecated use Y.env.ua.webkit
*/
/**
* webkit version
* @property webkit
* @type string
* @private
* @static
* @deprecated use Y.env.ua.webkit
*/
/**
* IE detection
* @property isIE
* @private
* @static
* @deprecated use Y.env.ua.ie
*/
/**
* poll handle
* @property _interval
* @static
* @private
*/
_interval: null,
/**
* document readystate poll handle
* @property _dri
* @static
* @private
*/
_dri: null,
/**
* True when the document is initially usable
* @property DOMReady
* @type boolean
* @static
*/
DOMReady: false,
/**
* @method startInterval
* @static
* @private
*/
startInterval: function() {
if (!this._interval) {
var self = this;
}
},
/**
* 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>
*
* @method onAvailable
*
* @param {string||string[]} p_id the id of the element, or an array
* of ids to look for.
* @param {function} p_fn what to execute when the element is found.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_override If set to true, p_fn will execute
* in the context of p_obj, if set to an object it
* will execute in the context of that object
* @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
checkReady: checkContent });
}
retryCount = this.POLL_RETRYS;
this.startInterval();
},
/**
* 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>
*
* @method onContentReady
*
* @param {string} p_id the id of the element to look for.
* @param {function} p_fn what to execute when the element is ready.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_override If set to true, p_fn will execute
* in the context of p_obj. If an object, p_fn will
* exectute in the context of that object
*
* @static
*/
},
/**
* Executes the supplied callback when the DOM is first usable. This
* will execute immediately if called after the DOMReady event has
* fired. @todo the DOMContentReady event does not fire when the
* script is dynamically injected into the page. This means the
* DOMReady custom event will never fire in FireFox or Opera when the
* library is injected. It _will_ fire in Safari, and the IE
* implementation would allow for us to fire it if the defered script
* is not available. We want this to behave the same in all browsers.
* Is there a way to identify when the script has been injected
* instead of included inline? Is there a way to know whether the
* window onload event has fired without having had a listener attached
* to it when it did so?
*
* <p>The callback is a Event.Custom, so the signature is:</p>
* <p>type <string>, args <array>, customobject <object></p>
* <p>For DOMReady events, there are no fire argments, so the
* signature is:</p>
* <p>"DOMReady", [], obj</p>
*
*
* @method onDOMReady
*
* @param {function} p_fn what to execute when the element is found.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_context If set to true, p_fn will execute
* in the context of p_obj, if set to an object it
* will execute in the context of that object
*
* @static
*/
setTimeout(function() {
var s = Y;
if (p_override) {
if (p_override === true) {
s = p_obj;
} else {
s = p_override;
}
}
}, 0);
} else {
}
},
/**
* Appends an event handler
*
* @method addListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* listener to.
* @param {String} sType The type of event to append
* @param {Function} fn The method the event invokes
* @param {Object} obj An arbitrary object that will be
* passed as a parameter to the handler
* @param {Boolean|object} override If true, the obj passed in becomes
* the execution context of the listener. If an
* object, this object becomes the execution
* context.
* @return {Boolean} True if the action was successful or defered,
* false if one or more of the elements
* could not have the listener attached,
* or if the operation throws an exception.
* @static
*/
// throw new TypeError(sType + " addListener call failed, callback undefined");
return false;
}
// The el argument can be an array of elements or element ids.
if ( this._isValidCollection(el)) {
var ok = true;
fn,
obj,
}
return ok;
// If the el argument is a string, we assume it is
// actually the id of the element. If the page is loaded
// we convert el to the actual element, otherwise we
// defer attaching the event until onload event fires
// check to see if we need to delay hooking up the event
// until after the page loads.
if (oEl) {
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
});
return true;
}
}
// Element should be an html element or an array if we get
// here.
if (!el) {
// this.logger.debug("unable to attach event " + sType);
return false;
}
// we need to make sure we fire registered unload events
// prior to automatically unhooking them. So we hang on to
// these instead of attaching them to the window and fire the
// handles explicitly during our one unload event.
return true;
}
// this.logger.debug("Adding handler: " + el + ", " + sType);
// if the user chooses to override the context, we use the custom
// object passed in, otherwise the executing context will be the
// HTML element that the event is registered on
if (override) {
if (override === true) {
} else {
}
}
// wrap the function so we can return the obj object when
// the event fires;
var wrappedFn = function(e) {
obj);
};
// cache the listener so we can try to automatically unload
// Add a new dom0 wrapper if one is not detected for this
// element
if ( legacyIndex == -1 ||
// cache the signature for the DOM0 event, and
// include the existing handler for the event, if any
legacyHandlers[legacyIndex] = [];
function(e) {
};
}
// add a reference to the wrapped listener to our custom
// stack of events
//legacyHandlers[legacyIndex].push(index);
} else {
try {
} catch(ex) {
// handle an error trying to attach an event. If it fails
// we need to clean up the cache
return false;
}
}
return true;
},
/**
* When using legacy events, the handler is routed to this object
* so we can fire our custom listener stack.
* @method fireLegacyEvent
* @static
* @private
*/
fireLegacyEvent: function(e, legacyIndex) {
// this.logger.debug("fireLegacyEvent " + legacyIndex);
}
}
// Fire the original handler if we replaced one. We fire this
// after the other events to keep stopPropagation/preventDefault
// that happened in the DOM0 handler from touching our DOM2
// substitute
le[2](e);
}
return ok;
},
/**
* Returns the legacy event index that matches the supplied
* signature
* @method getLegacyIndex
* @static
* @private
*/
return -1;
} else {
}
},
/**
* Logic that determines when we should automatically use legacy
* events instead of DOM2 events. Currently this is limited to old
* Safari browsers with a broken preventDefault
* @method useLegacyEvent
* @static
* @private
*/
if (!isNaN(v) && v<418) {
return true;
}
}
return false;
},
/**
* Removes an event listener
*
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* the listener from.
* @param {String} sType the type of event to remove.
* @param {Function} fn the method the event invokes. If fn is
* undefined, then all event handlers for the type of event are
* removed.
* @return {boolean} true if the unbind was successful, false
* otherwise.
* @static
*/
// The el argument can be a string
if (typeof el == "string") {
// The el argument can be an array of elements or element ids.
} else if ( this._isValidCollection(el)) {
var ok = true;
}
return ok;
}
// this.logger.debug("Error, function is not valid " + fn);
//return false;
}
if ("unload" == sType) {
li = unloadListeners[i];
if (li &&
//unloadListeners.splice(i, 1);
unloadListeners[i]=null;
return true;
}
}
return false;
}
var cacheItem = null;
// The index is a hidden parameter; needed to remove it from
// the method signature because it was tempting users to
// try and take advantage of it, which is not possible.
if ("undefined" === typeof index) {
}
if (index >= 0) {
}
// this.logger.debug("cached listener not found");
return false;
}
// this.logger.debug("Removing handler: " + el + ", " + sType);
if (llist) {
if (li &&
//llist.splice(i, 1);
llist[i]=null;
break;
}
}
}
} else {
try {
} catch(ex) {
return false;
}
}
// removed the wrapped handler
//listeners.splice(index, 1);
return true;
},
/**
* Returns the event's target element. Safari sometimes provides
* a text node, and this is automatically resolved to the text
* node's parent so that it behaves like other browsers.
* @method getTarget
* @param {Event} ev the event
* @param {boolean} resolveTextNode when set to true the target's
* parent will be returned if the target is a
* text node. @deprecated, the text node is
* now resolved automatically
* @return {HTMLElement} the event's target
* @static
*/
return this.resolveTextNode(t);
},
/**
* In some cases, some browsers will return a text node inside
* the actual element that was targeted. This normalizes the
* return value for getTarget and getRelatedTarget.
* @method resolveTextNode
* @param {HTMLElement} node node to resolve
* @return {HTMLElement} the normized node
* @static
*/
resolveTextNode: function(node) {
return node.parentNode;
} else {
return node;
}
},
/**
* Returns the event's pageX
* @method getPageX
* @param {Event} ev the event
* @return {int} the event's pageX
* @static
*/
if (!x && 0 !== x) {
if ( this.isIE ) {
x += this._getScrollLeft();
}
}
return x;
},
/**
* Returns the event's pageY
* @method getPageY
* @param {Event} ev the event
* @return {int} the event's pageY
* @static
*/
if (!y && 0 !== y) {
if ( this.isIE ) {
y += this._getScrollTop();
}
}
return y;
},
/**
* Returns the pageX and pageY properties as an indexed array.
* @method getXY
* @param {Event} ev the event
* @return {[x, y]} the pageX and pageY properties of the event
* @static
*/
},
/**
* Returns the event's related target
* @method getRelatedTarget
* @param {Event} ev the event
* @return {HTMLElement} the event's relatedTarget
* @static
*/
getRelatedTarget: function(ev) {
var t = ev.relatedTarget;
if (!t) {
t = ev.fromElement;
}
}
return this.resolveTextNode(t);
},
/**
* Returns the time of the event. If the time is not included, the
* event is modified using the current time.
* @method getTime
* @param {Event} ev the event
* @return {Date} the time of the event
* @static
*/
var t = new Date().getTime();
try {
} catch(ex) {
return t;
}
}
},
/**
* Convenience method for stopPropagation + preventDefault
* @method stopEvent
* @param {Event} ev the event
* @static
*/
this.stopPropagation(ev);
this.preventDefault(ev);
},
/**
* Stops event propagation
* @method stopPropagation
* @param {Event} ev the event
* @static
*/
stopPropagation: function(ev) {
if (ev.stopPropagation) {
} else {
ev.cancelBubble = true;
}
},
/**
* Prevents the default behavior of the event
* @method preventDefault
* @param {Event} ev the event
* @static
*/
preventDefault: function(ev) {
if (ev.preventDefault) {
ev.preventDefault();
} else {
ev.returnValue = false;
}
},
/**
* 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.
* @method getEvent
* @param {Event} e the event parameter from the handler
* @param {HTMLElement} boundEl the element the listener is attached to
* @return {Event} the event
* @static
*/
if (!ev) {
while (c) {
break;
}
c = c.caller;
}
}
},
/**
* Returns the charcode for an event
* @method getCharCode
* @param {Event} ev the event
* @return {int} the event's charCode
* @static
*/
getCharCode: function(ev) {
// webkit normalization
}
return code;
},
/**
* Locating the saved event handler data by function ref
*
* @method _getCacheIndex
* @static
* @private
*/
if ( li &&
return i;
}
}
return -1;
},
/**
* Generates an unique ID for the element if it does not already
* have one.
* @method generateId
* @param el the element to create the id for
* @return {string} the resulting id of the element
* @static
*/
generateId: function(el) {
if (!id) {
++counter;
}
return id;
},
/**
* 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.
* @method _isValidCollection
* @param o the object to test
* @return {boolean} true if the object is array-like and populated
* @static
* @private
*/
_isValidCollection: function(o) {
try {
return ( o && // o is something
typeof o !== "string" && // o is not a string
o.length && // o is indexed
!o.tagName && // o is not an HTML element
!o.alert && // o is not a window
typeof o[0] !== "undefined" );
} catch(ex) {
Y.log("_isValidCollection error, assuming that " +
" this is a cross frame problem and not a collection", "warn");
return false;
}
},
/**
* We cache elements bound by id because when the unload event
* fires, we can no longer use document.getElementById
* @method getEl
* @static
* @private
* @deprecated Elements are not cached any longer
*/
},
/**
* Custom event the fires when the dom is initially usable
* @event DOMReadyEvent
*/
/**
* hook up any deferred listeners
* @method _load
* @static
* @private
*/
_load: function(e) {
if (!loadComplete) {
loadComplete = true;
// Just in case DOMReady did not go off for some reason
// Available elements may not have been detected before the
// window load event fires. Try to find them now so that the
// the user is more likely to get the onAvailable notifications
// before the window load notification
}
},
/**
* Fires the DOMReady event listeners the first time the document is
* usable.
* @method _ready
* @static
* @private
*/
_ready: function(e) {
// Fire the content ready custom event
}
},
/**
* Polling function that runs before the onload event fires,
* attempting to attach to DOM Nodes as soon as they are
* available
* @method _tryPreloadAttach
* @static
* @private
*/
_tryPreloadAttach: function() {
if (this.locked) {
return false;
}
if (this.isIE) {
// Hold off if DOMReady has not fired and check current
// readyState to protect against the IE operation aborted
// issue.
if (!this.DOMReady) {
this.startInterval();
return false;
}
}
this.locked = true;
// this.logger.debug("tryPreloadAttach");
// keep trying until after the page is loaded. We need to
// check the page load state prior to trying to bind the
// elements so that we can be certain all elements have been
// tested appropriately
var tryAgain = !loadComplete;
if (!tryAgain) {
}
// onAvailable
var notAvail = [];
} else {
}
}
};
// onAvailable
item = onAvailStack[i];
if (el) {
onAvailStack[i] = null;
} else {
}
}
}
// onContentReady
item = onAvailStack[i];
if (el) {
// The element is available, but not necessarily ready
// @todo should we test parentNode.nextSibling?
onAvailStack[i] = null;
}
} else {
}
}
}
if (tryAgain) {
// we may need to strip the nulled out items here
this.startInterval();
} else {
clearInterval(this._interval);
this._interval = null;
}
this.locked = false;
return true;
},
/**
* 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.
* @method purgeElement
* @param {HTMLElement} el the element to purge
* @param {boolean} recurse recursively purge this element's children
* as well. Use with caution.
* @param {string} sType optional type of listener to purge. If
* left out, all listeners will be removed
* @static
*/
if (elListeners) {
var l = elListeners[i];
}
}
}
}
},
/**
* Returns all listeners attached to the given element via addListener.
* Optionally, you can specify a specific type of event to return.
* @method getListeners
* @param el {HTMLElement|string} the element or element id to inspect
* @param sType {string} optional type of listener to return. If
* left out, all listeners will be returned
* @return {Object} the listener. Contains the following fields:
* type: (string) the type of event
* fn: (function) the callback supplied to addListener
* obj: (object) the custom object supplied to addListener
* adjust: (boolean|object) whether or not to adjust the default context
* context: (boolean) the derived context based on the adjust parameter
* index: (int) its position in the Event util listener cache
* @static
*/
var results=[], searchLists;
if (!sType) {
} else if (sType === "unload") {
} else {
searchLists = [listeners];
}
var searchList = searchLists[j];
var l = searchList[i];
index: i
});
}
}
}
}
},
/**
* Removes all listeners registered by pe.event. Called
* automatically during the unload event.
* @method _unload
* @static
* @private
*/
_unload: function(e) {
// execute and clear stored unload listeners
l = unloadListeners[i];
if (l) {
var context = Y;
} else {
}
}
unloadListeners[i] = null;
l=null;
context=null;
}
}
unloadListeners = null;
// Remove listeners to handle IE memory leaks
//if (Y.env.ua.ie && listeners && listeners.length > 0) {
// 2.5.0 listeners are removed for all browsers again. FireFox preserves
// at least some listeners between page refreshes, potentially causing
// errors during page load (mouseover listeners firing before they
// should if the user moves the mouse at the correct moment).
while (j) {
index = j-1;
if (l) {
}
j--;
}
l=null;
}
legacyEvents = null;
},
/**
* Returns scrollLeft
* @method _getScrollLeft
* @static
* @private
*/
_getScrollLeft: function() {
return this._getScroll()[1];
},
/**
* Returns scrollTop
* @method _getScrollTop
* @static
* @private
*/
_getScrollTop: function() {
return this._getScroll()[0];
},
/**
* Returns the scrollTop and scrollLeft. Used to calculate the
* pageX and pageY in Internet Explorer
* @method _getScroll
* @static
* @private
*/
_getScroll: function() {
} else if (db) {
} else {
return [0, 0];
}
},
/**
* Adds a DOM event directly without the caching, cleanup, context adj, etc
*
* @method _simpleAdd
* @param {HTMLElement} el the element to bind the handler to
* @param {string} sType the type of event handler
* @param {function} fn the callback to invoke
* @param {boolen} capture capture or bubble phase
* @static
* @private
*/
_simpleAdd: function () {
if (window.addEventListener) {
};
} else if (window.attachEvent) {
};
} else {
return function(){};
}
}(),
/**
* Basic remove listener
*
* @method _simpleRemove
* @param {HTMLElement} el the element to bind the handler to
* @param {string} sType the type of event handler
* @param {function} fn the callback to invoke
* @param {boolen} capture capture or bubble phase
* @static
* @private
*/
_simpleRemove: function() {
if (window.removeEventListener) {
};
} else if (window.detachEvent) {
};
} else {
return function(){};
}
}()
};
}();
(function() {
/**
* Y.Event.on is an alias for addListener
* @method on
* @see addListener
* @static
*/
};
};
// only execute DOMReady once
if (Y !== YUI) {
} else {
/////////////////////////////////////////////////////////////
// DOMReady
// Internet Explorer: use the readyState of a defered script.
// This isolates what appears to be a safe moment to manipulate
// the DOM prior to when the document's readyState suggests
// it is safe to do so.
// Process onAvailable/onContentReady items when when the
// DOM is ready.
Y.Event.onDOMReady(
Y.Event, true);
try {
// throws an error if doc is not ready
n.doScroll('left');
n = null;
} catch (ex) {
n = null;
}
}, EU.POLL_INTERVAL);
// The document's readyState in Safari currently will
}
}, EU.POLL_INTERVAL);
// FireFox and Opera: These browsers provide a event for this
// moment. The latest WebKit releases now support this event.
} else {
}
/////////////////////////////////////////////////////////////
}
})();
}
/**
* Event.Target is designed to be used with Y.augment to wrap
* Event.Custom in an interface that allows events to be subscribed to
* and fired by name. This makes it possible for implementing code to
* subscribe to an event that either has not been created yet, or will
* not be created at all.
*
* @Class Event.Target
*/
/**
* Private storage of custom events
* @property __yui_events
* @type Object[]
* @private
*/
__yui_events: null,
/**
* Private storage of custom event subscribers
* @property __yui_subscribers
* @type Object[]
* @private
*/
__yui_subscribers: null,
/**
* Subscribe to a Event.Custom by event type
*
* @method subscribe
* @param p_type {string} the type, or name of the event
* @param p_fn {function} the function to exectute when the event fires
* @param p_obj {Object} An object to be passed along when the event
* fires
* @param p_override {boolean} If true, the obj passed in becomes the
* execution context of the listener
*/
this.__yui_events = this.__yui_events || {};
if (ce) {
} else {
this.__yui_subscribers = this.__yui_subscribers || {};
var subs = this.__yui_subscribers;
}
}
},
/**
* Unsubscribes one or more listeners the from the specified event
* @method unsubscribe
* @param p_type {string} The type, or name of the event. If the type
* is not specified, it will attempt to remove
* the listener from all hosted events.
* @param p_fn {Function} The subscribed function to unsubscribe, if not
* supplied, all subscribers will be removed.
* @param p_obj {Object} The custom object passed to subscribe. This is
* optional, but if supplied will be used to
* disambiguate multiple listeners that are the same
* (e.g., you subscribe many object using a function
* that lives on the prototype)
* @return {boolean} true if the subscriber was found and detached.
*/
this.__yui_events = this.__yui_events || {};
var evts = this.__yui_events;
if (p_type) {
if (ce) {
}
} else {
var ret = true;
for (var i in evts) {
}
}
return ret;
}
return false;
},
/**
* Removes all listeners from the specified event. If the event type
* is not specified, all listeners from all hosted custom events will
* be removed.
* @method unsubscribeAll
* @param p_type {string} The type, or name of the event
*/
unsubscribeAll: function(p_type) {
return this.unsubscribe(p_type);
},
/**
* Creates a new custom event of the specified type. If a custom event
* by that name already exists, it will not be re-created. In either
* case the custom event is returned.
*
* @method publish
*
* @param p_type {string} the type, or name of the event
* @param p_config {object} optional config params. Valid properties are:
*
* <ul>
* <li>
* context: defines the default execution context. If not defined
* the default context will be this instance.
* </li>
* <li>
* silent: if true, the custom event will not generate log messages.
* This is false by default.
* </li>
* <li>
* onSubscribeCallback: specifies a callback to execute when the
* event has a new subscriber. This will fire immediately for
* each queued subscriber if any exist prior to the creation of
* the event.
* </li>
* </ul>
*
* @return {Event.Custom} the custom event
*
*/
this.__yui_events = this.__yui_events || {};
var events = this.__yui_events;
} else {
if (opts.onSubscribeCallback) {
}
this.__yui_subscribers = this.__yui_subscribers || {};
if (qs) {
}
}
}
},
/**
* Fire a custom event by name. The callback functions will be executed
* from the context specified when the event was created, and with the
* following parameters:
* <ul>
* <li>The first argument fire() was executed with</li>
* <li>The custom object (if any) that was passed into the subscribe()
* method</li>
* </ul>
* If the custom event has not been explicitly created, it will be
* created now with the default config, context to the host object
* @method fireEvent
* @param p_type {string} the type, or name of the event
* @param arguments {Object*} an arbitrary set of parameters to pass to
* the handler.
* @return {boolean} the return value from Event.Custom.fire
*
*/
this.__yui_events = this.__yui_events || {};
if (!ce) {
// Y.log(p_type + "event fired before it was created.");
// return null;
}
var args = [];
}
},
/**
* Returns true if the custom event of the provided type has been created
* with publish.
* @method hasEvent
* @param type {string} the type, or name of the event
*/
if (this.__yui_events) {
if (this.__yui_events[type]) {
return true;
}
}
return false;
},
/**
* Executes the callback before the given event or
* method hosted on this object.
*
* The signature differs based upon the type of
* item that is being wrapped.
*
* Custom Event: type, callback, context, 1-n additional arguments
* to append to the callback's argument list.
*
* Method: callback, object, methodName, context, 1-n additional
* arguments to append to the callback's argument list.
*
* @method before
* @return the detach handle
*/
before: function() {
// insert this object as method target
// Y.log('ET:before- ' + Y.lang.dump(a));
},
/**
* Executes the callback after the given event or
* method hosted on this object.
*
* The signature differs based upon the type of
* item that is being wrapped.
*
* Custom Event: type, callback, context, 1-n additional arguments
* to append to the callback's argument list.
*
* Method: callback, object, methodName, context, 1-n additional
* arguments to append to the callback's argument list.
*
* @method after
* @return the detach handle
*/
after: function() {
}
};
// TODO **************** KeyListener needs to be completely redone
(function() {
var whitelist = {
"altKey" : 1,
"button" : 1, // we supply
"bubbles" : 1,
"cancelable" : 1,
"charCode" : 1, // we supply
"cancelBubble" : 1,
"currentTarget" : 1,
"ctrlKey" : 1,
"clientX" : 1,
"clientY" : 1,
"detail" : 1, // not fully implemented
// "fromElement" : 1,
"keyCode" : 1,
"height" : 1,
"initEvent" : 1, // need the init events?
"initMouseEvent" : 1,
"initUIEvent" : 1,
"layerX" : 1,
"layerY" : 1,
"metaKey" : 1,
"modifiers" : 1,
"offsetX" : 1,
"offsetY" : 1,
"preventDefault" : 1, // we supply
// "reason" : 1, // IE proprietary
// "relatedTarget" : 1,
"returnValue" : 1,
"shiftKey" : 1,
// "srcUrn" : 1, // IE proprietary
// "srcElement" : 1,
// "srcFilter" : 1, IE proprietary
"stopPropagation" : 1, // we supply
// "target" : 1,
"timeStamp" : 1,
// "toElement" : 1,
"type" : 1,
// "view" : 1,
"which" : 1, // we supply
"width" : 1,
"x" : 1,
"y" : 1
};
var webkitKeymap = {
63232: 38, // up
63233: 40, // down
63234: 37, // left
63235: 39, // right
63276: 33, // page up
63277: 34, // page down
25: 9 // SHIFT-TAB (Safari provides a different key code in
// this case, even though the shiftKey modifier is set)
};
// return the element facade
var wrapNode = function(n) {
return n;
};
var resolve = function(n) {
try {
if (n && 3 == n.nodeType) {
n = n.parentNode;
}
} catch(ex) { }
return wrapNode(n);
};
// provide a single event with browser abstractions resolved
//
// include all properties for both browers?
// include only DOM2 spec properties?
// provide browser-specific facade?
// @TODO the document should be the target's owner document
for (var i in whitelist) {
this[i] = e[i];
}
}
//////////////////////////////////////////////////////
// pageX pageY
if (!x && 0 !== x) {
x = e.clientX || 0;
y = e.clientX || 0;
x += b.scrollLeft;
y += b.scrollTop;
}
}
this.pageX = x;
this.pageY = y;
//////////////////////////////////////////////////////
// keyCode
c = webkitKeymap[c];
}
this.keyCode = c;
this.charCode = c;
//////////////////////////////////////////////////////
// time
//////////////////////////////////////////////////////
// targets
var t = e.relatedTarget;
if (!t) {
if (e.type == "mouseout") {
t = e.toElement;
} else if (e.type == "mouseover") {
t = e.fromElement;
}
}
this.relatedTarget = resolve(t);
//////////////////////////////////////////////////////
// methods
this.stopPropagation = function() {
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
};
this.preventDefault = function() {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
};
// stop event
this.halt = function() {
this.stopPropagation();
this.preventDefault();
};
};
})();
// YUI is an event provider
// Y.augment(Y, Y.Event.Target);
// var T = Y.Event.Target;
// T.prototype.createEvent = T.prototype.publish;
// T.prototype.fireEvent = T.prototype.fire;
}, "3.0.0");