Index: openacs-4/packages/ajaxhelper/www/resources/yui/event/event-debug.js
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/www/resources/yui/event/event-debug.js,v
diff -u -N -r1.3 -r1.4
--- openacs-4/packages/ajaxhelper/www/resources/yui/event/event-debug.js 8 Sep 2007 14:22:05 -0000 1.3
+++ openacs-4/packages/ajaxhelper/www/resources/yui/event/event-debug.js 9 Apr 2009 23:15:48 -0000 1.4
@@ -1,8 +1,8 @@
/*
-Copyright (c) 2007, Yahoo! Inc. All rights reserved.
+Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
-version: 2.3.0
+version: 2.7.0
*/
/**
@@ -11,7 +11,7 @@
*
* @param {String} type The type of event, which is passed to the callback
* when the event fires
- * @param {Object} oScope The context the event will fire from. "this" will
+ * @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
@@ -24,7 +24,7 @@
* @class CustomEvent
* @constructor
*/
-YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
+YAHOO.util.CustomEvent = function(type, context, silent, signature) {
/**
* The type of event, returned to subscribers when the event fires
@@ -34,12 +34,12 @@
this.type = type;
/**
- * The scope the the event will fire from by default. Defaults to the window
+ * The context the the event will fire from by default. Defaults to the window
* obj
* @property scope
* @type object
*/
- this.scope = oScope || window;
+ this.scope = context || window;
/**
* By default all custom events are logged in the debug build, set silent
@@ -100,16 +100,27 @@
* @type YAHOO.util.CustomEvent
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
- * fires
+ * fires defaults to the custom event
* @param {boolean|Object} override If true, the obj passed in becomes
- * the execution scope of the listener.
+ * the execution context of the listener.
* if an object, that object becomes the
- * the execution scope.
+ * the execution context. defaults to
+ * the custom event
*/
this.subscribeEvent =
new YAHOO.util.CustomEvent(onsubscribeType, this, true);
}
+
+
+ /**
+ * 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;
};
/**
@@ -140,22 +151,22 @@
* @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 scope of the listener.
+ * @param {boolean|Object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener.
* if an object, that object becomes the
- * the execution scope.
+ * the execution context.
*/
- subscribe: function(fn, obj, override) {
+ subscribe: function(fn, obj, overrideContext) {
if (!fn) {
throw new Error("Invalid callback for subscriber to '" + this.type + "'");
}
if (this.subscribeEvent) {
- this.subscribeEvent.fire(fn, obj, override);
+ this.subscribeEvent.fire(fn, obj, overrideContext);
}
- this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, override) );
+ this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, overrideContext) );
},
/**
@@ -190,7 +201,7 @@
/**
* Notifies the subscribers. The callback functions will be executed
- * from the scope specified when the event was created, and with the
+ * from the context specified when the event was created, and with the
* following parameters:
*
*
The type of event
@@ -205,34 +216,38 @@
* true otherwise
*/
fire: function() {
- var len=this.subscribers.length;
+
+ this.lastError = null;
+
+ var errors = [],
+ len=this.subscribers.length;
+
if (!len && this.silent) {
+ //YAHOO.log('DEBUG no subscribers');
return true;
}
- var args=[], ret=true, i, rebuild=false;
+ var args=[].slice.call(arguments, 0), ret=true, i, rebuild=false;
- for (i=0; i" + (i+1) + ": " + s,
- "info", "Event" );
+YAHOO.log( this.type + "->" + (i+1) + ": " + s, "info", "Event" );
}
var scope = s.getScope(this.scope);
@@ -242,33 +257,41 @@
if (args.length > 0) {
param = args[0];
}
- ret = s.fn.call(scope, param, s.obj);
+
+ try {
+ ret = s.fn.call(scope, param, s.obj);
+ } catch(e) {
+ this.lastError = e;
+ // errors.push(e);
+YAHOO.log(this + " subscriber exception: " + e, "error", "Event");
+ if (throwErrors) {
+ throw e;
+ }
+ }
} else {
- ret = s.fn.call(scope, this.type, args, s.obj);
+ try {
+ ret = s.fn.call(scope, this.type, args, s.obj);
+ } catch(ex) {
+ this.lastError = ex;
+YAHOO.log(this + " subscriber exception: " + ex, "error", "Event");
+ if (throwErrors) {
+ throw ex;
+ }
+ }
}
+
if (false === ret) {
if (!this.silent) {
- YAHOO.log("Event cancelled, subscriber " + i +
- " of " + len, "info", "Event");
+YAHOO.log("Event stopped, sub " + i + " of " + len, "info", "Event");
}
- //break;
- return false;
+ break;
+ // return false;
}
}
}
- if (rebuild) {
- var newlist=[],subs=this.subscribers;
- for (i=0,len=subs.length; i-1; i--) {
+ this._delete(i);
}
this.subscribers=[];
- return i;
+ return l;
},
/**
@@ -297,15 +321,16 @@
delete s.obj;
}
- this.subscribers[index]=null;
+ // this.subscribers[index]=null;
+ this.subscribers.splice(index, 1);
},
/**
* @method toString
*/
toString: function() {
return "CustomEvent: " + "'" + this.type + "', " +
- "scope: " + this.scope;
+ "context: " + this.scope;
}
};
@@ -316,12 +341,12 @@
* 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
- * scope of the listener
+ * @param {boolean} overrideContext If true, the obj passed in becomes the execution
+ * context of the listener
* @class Subscriber
* @constructor
*/
-YAHOO.util.Subscriber = function(fn, obj, override) {
+YAHOO.util.Subscriber = function(fn, obj, overrideContext) {
/**
* The callback that will be execute when the event fires
@@ -339,32 +364,32 @@
this.obj = YAHOO.lang.isUndefined(obj) ? null : obj;
/**
- * The default execution scope for the event listener is defined when the
+ * 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 scope becomes the custom
- * object passed in by the subscriber. If override is an object, that
- * object becomes the scope.
- * @property override
+ * By setting overrideContext to true, the execution context becomes the custom
+ * object passed in by the subscriber. If overrideContext is an object, that
+ * object becomes the context.
+ * @property overrideContext
* @type boolean|object
*/
- this.override = override;
+ this.overrideContext = overrideContext;
};
/**
- * Returns the execution scope for this listener. If override was set to true
- * the custom obj will be the scope. If override is an object, that is the
- * scope, otherwise the default scope will be used.
+ * Returns the execution context for this listener. If overrideContext was set to true
+ * the custom obj will be the context. If overrideContext is an object, that is the
+ * context, otherwise the default context will be used.
* @method getScope
- * @param {Object} defaultScope the scope to use if this listener does not
+ * @param {Object} defaultScope the context to use if this listener does not
* override it.
*/
YAHOO.util.Subscriber.prototype.getScope = function(defaultScope) {
- if (this.override) {
- if (this.override === true) {
+ if (this.overrideContext) {
+ if (this.overrideContext === true) {
return this.obj;
} else {
- return this.override;
+ return this.overrideContext;
}
}
return defaultScope;
@@ -393,7 +418,7 @@
*/
YAHOO.util.Subscriber.prototype.toString = function() {
return "Subscriber { obj: " + this.obj +
- ", override: " + (this.override || "no") + " }";
+ ", overrideContext: " + (this.overrideContext || "no") + " }";
};
/**
@@ -432,15 +457,6 @@
var loadComplete = false;
/**
- * True when the document is initially usable
- * @property DOMReady
- * @type boolean
- * @static
- * @private
- */
- var DOMReady = false;
-
- /**
* Cache of wrapped listeners
* @property listeners
* @type array
@@ -522,23 +538,31 @@
63232: 38, // up
63233: 40, // down
63234: 37, // left
- 63235: 39 // right
+ 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)
};
+
+ // String constants used by the addFocusListener and removeFocusListener methods
+ var _FOCUS = YAHOO.env.ua.ie ? "focusin" : "focus";
+ var _BLUR = YAHOO.env.ua.ie ? "focusout" : "blur";
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 4000@amp;10 ms, so it will poll
+ * 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: 4000,
+ POLL_RETRYS: 2000,
/**
* The poll interval in milliseconds
@@ -547,7 +571,7 @@
* @static
* @final
*/
- POLL_INTERVAL: 10,
+ POLL_INTERVAL: 20,
/**
* Element to bind, int constant
@@ -577,7 +601,7 @@
FN: 2,
/**
- * Function wrapped for scope correction and cleanup, int constant
+ * Function wrapped for context correction and cleanup, int constant
* @property WFN
* @type int
* @static
@@ -587,16 +611,17 @@
/**
* Object passed in by the user that will be returned as a
- * parameter to the callback, int constant
+ * parameter to the callback, int constant. Specific to
+ * unload listeners
* @property OBJ
* @type int
* @static
* @final
*/
- OBJ: 3,
+ UNLOAD_OBJ: 3,
/**
- * Adjusted scope, either the element we are registering the event
+ * 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
@@ -606,6 +631,24 @@
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
@@ -652,6 +695,33 @@
_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,
+
+ /**
+ * Errors thrown by subscribers of custom events are caught
+ * and the error message is written to the debug console. If
+ * this property is set to true, it will also re-throw the
+ * error.
+ * @property throwErrors
+ * @type boolean
+ * @default false
+ */
+ throwErrors: false,
+
+ /**
* @method startInterval
* @static
* @private
@@ -677,27 +747,59 @@
*
* @method onAvailable
*
- * @param {string} p_id the id of the element 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 scope of p_obj, if set to an object it
- * will execute in the scope of that object
- *
+ * @param {string||string[]} id the id of the element, or an array
+ * of ids to look for.
+ * @param {function} fn what to execute when the element is found.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj, if set to an object it
+ * will execute in the context of that object
+ * @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
- onAvailable: function(p_id, p_fn, p_obj, p_override) {
- onAvailStack.push( { id: p_id,
- fn: p_fn,
- obj: p_obj,
- override: p_override,
- checkReady: false } );
+ onAvailable: function(id, fn, obj, overrideContext, checkContent) {
+
+ var a = (YAHOO.lang.isString(id)) ? [id] : id;
+
+ for (var i=0; iThe callback is executed with a single parameter:
+ * the custom object parameter, if provided.
+ *
+ * @method onContentReady
+ *
+ * @param {string} id the id of the element to look for.
+ * @param {function} fn what to execute when the element is ready.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj. If an object, fn will
+ * exectute in the context of that object
+ *
+ * @static
+ */
+ onContentReady: function(id, fn, obj, overrideContext) {
+ this.onAvailable(id, fn, obj, overrideContext, true);
+ },
+
+ /**
* 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
@@ -712,76 +814,46 @@
* to it when it did so?
*
*
The callback is a CustomEvent, so the signature is:
- *
type , args , customobject
+ *
type <string>, args <array>, customobject <object>
*
For DOMReady events, there are no fire argments, so the
* signature is:
*
"DOMReady", [], obj
*
*
* @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_scope If set to true, p_fn will execute
- * in the scope of p_obj, if set to an object it
- * will execute in the scope of that object
+ * @param {function} fn what to execute when the element is found.
+ * @param {object} obj an optional object to be passed back as
+ * a parameter to fn.
+ * @param {boolean|object} overrideContext If set to true, fn will execute
+ * in the context of obj, if set to an object it
+ * will execute in the context of that object
*
* @static
*/
- onDOMReady: function(p_fn, p_obj, p_override) {
- if (DOMReady) {
+ onDOMReady: function(fn, obj, overrideContext) {
+ if (this.DOMReady) {
setTimeout(function() {
var s = window;
- if (p_override) {
- if (p_override === true) {
- s = p_obj;
+ if (overrideContext) {
+ if (overrideContext === true) {
+ s = obj;
} else {
- s = p_override;
+ s = overrideContext;
}
}
- p_fn.call(s, "DOMReady", [], p_obj);
+ fn.call(s, "DOMReady", [], obj);
}, 0);
} else {
- this.DOMReadyEvent.subscribe(p_fn, p_obj, p_override);
+ this.DOMReadyEvent.subscribe(fn, obj, overrideContext);
}
},
- /**
- * 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.
- *
- *
The callback is executed with a single parameter:
- * the custom object parameter, if provided.
- *
- * @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 scope of p_obj. If an object, p_fn will
- * exectute in the scope of that object
- *
- * @static
- */
- onContentReady: function(p_id, p_fn, p_obj, p_override) {
- onAvailStack.push( { id: p_id,
- fn: p_fn,
- obj: p_obj,
- override: p_override,
- checkReady: true } );
- retryCount = this.POLL_RETRYS;
- this.startInterval();
- },
-
/**
* Appends an event handler
*
- * @method addListener
+ * @method _addListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to assign the
@@ -790,21 +862,22 @@
* @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 scope of the listener. If an
+ * @param {Boolean|object} overrideContext If true, the obj passed in becomes
+ * the execution context of the listener. If an
* object, this object becomes the execution
- * scope.
+ * context.
+ * @param {boolen} capture capture or bubble phase
* @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.
+ * @private
* @static
*/
- addListener: function(el, sType, fn, obj, override) {
+ _addListener: function(el, sType, fn, obj, overrideContext, bCapture) {
if (!fn || !fn.call) {
-// throw new TypeError(sType + " addListener call failed, callback undefined");
-YAHOO.log(sType + " addListener call failed, invalid callback", "error", "Event");
+ YAHOO.log(sType + " addListener failed, invalid callback", "error", "Event");
return false;
}
@@ -816,7 +889,7 @@
sType,
fn,
obj,
- override) && ok;
+ overrideContext) && ok;
}
return ok;
@@ -834,7 +907,7 @@
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
- YAHOO.util.Event.on(el, sType, fn, obj, override);
+ YAHOO.util.Event.on(el, sType, fn, obj, overrideContext);
});
return true;
@@ -854,32 +927,32 @@
// handles explicitly during our one unload event.
if ("unload" == sType && obj !== this) {
unloadListeners[unloadListeners.length] =
- [el, sType, fn, obj, override];
+ [el, sType, fn, obj, overrideContext];
return true;
}
// this.logger.debug("Adding handler: " + el + ", " + sType);
- // if the user chooses to override the scope, we use the custom
- // object passed in, otherwise the executing scope will be the
+ // 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
- var scope = el;
- if (override) {
- if (override === true) {
- scope = obj;
+ var context = el;
+ if (overrideContext) {
+ if (overrideContext === true) {
+ context = obj;
} else {
- scope = override;
+ context = overrideContext;
}
}
// wrap the function so we can return the obj object when
// the event fires;
var wrappedFn = function(e) {
- return fn.call(scope, YAHOO.util.Event.getEvent(e),
+ return fn.call(context, YAHOO.util.Event.getEvent(e, el),
obj);
};
- var li = [el, sType, fn, wrappedFn, scope];
+ var li = [el, sType, fn, wrappedFn, context, obj, overrideContext];
var index = listeners.length;
// cache the listener so we can try to automatically unload
listeners[index] = li;
@@ -915,7 +988,7 @@
} else {
try {
- this._simpleAdd(el, sType, wrappedFn, false);
+ this._simpleAdd(el, sType, wrappedFn, bCapture);
} catch(ex) {
// handle an error trying to attach an event. If it fails
// we need to clean up the cache
@@ -929,7 +1002,127 @@
},
+
/**
+ * Appends an event handler
+ *
+ * @method addListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * 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} overrideContext 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
+ */
+ addListener: function (el, sType, fn, obj, overrideContext) {
+ return this._addListener(el, sType, fn, obj, overrideContext, false);
+ },
+
+ /**
+ * Appends a focus event handler. (The focusin event is used for Internet Explorer,
+ * the focus, capture-event for Opera, WebKit.)
+ *
+ * @method addFocusListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * listener to.
+ * @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} overrideContext 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
+ */
+ addFocusListener: function (el, fn, obj, overrideContext) {
+ return this._addListener(el, _FOCUS, fn, obj, overrideContext, true);
+ },
+
+
+ /**
+ * Removes a focus event listener
+ *
+ * @method removeListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to remove
+ * the listener from.
+ * @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
+ */
+ removeFocusListener: function (el, fn) {
+ return this.removeListener(el, _FOCUS, fn);
+ },
+
+ /**
+ * Appends a blur event handler. (The focusout event is used for Internet Explorer,
+ * the focusout, capture-event for Opera, WebKit.)
+ *
+ * @method addBlurListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to assign the
+ * listener to.
+ * @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} overrideContext 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
+ */
+ addBlurListener: function (el, fn, obj, overrideContext) {
+ return this._addListener(el, _BLUR, fn, obj, overrideContext, true);
+ },
+
+ /**
+ * Removes a blur event listener
+ *
+ * @method removeListener
+ *
+ * @param {String|HTMLElement|Array|NodeList} el An id, an element
+ * reference, or a collection of ids and/or elements to remove
+ * the listener from.
+ * @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
+ */
+ removeBlurListener: function (el, fn) {
+
+ return this.removeListener(el, _BLUR, fn);
+
+ },
+
+ /**
* When using legacy events, the handler is routed to this object
* so we can fire our custom listener stack.
* @method fireLegacyEvent
@@ -938,14 +1131,15 @@
*/
fireLegacyEvent: function(e, legacyIndex) {
// this.logger.debug("fireLegacyEvent " + legacyIndex);
- var ok=true,le,lh,li,scope,ret;
+ var ok=true, le, lh, li, context, ret;
- lh = legacyHandlers[legacyIndex];
- for (var i=0,len=lh.length; i-1; i--) {
ok = ( this.removeListener(el[i], sType, fn) && ok );
}
return ok;
@@ -1035,14 +1223,14 @@
if ("unload" == sType) {
- for (i=0, len=unloadListeners.length; i-1; i--) {
+ li = unloadListeners[i];
if (li &&
li[0] == el &&
li[1] == sType &&
li[2] == fn) {
- //unloadListeners.splice(i, 1);
- unloadListeners[i]=null;
+ unloadListeners.splice(i, 1);
+ // unloadListeners[i]=null;
return true;
}
}
@@ -1057,7 +1245,7 @@
// try and take advantage of it, which is not possible.
var index = arguments[3];
- if ("undefined" == typeof index) {
+ if ("undefined" === typeof index) {
index = this._getCacheIndex(el, sType, fn);
}
@@ -1077,13 +1265,14 @@
var llist = legacyHandlers[legacyIndex];
if (llist) {
for (i=0, len=llist.length; i 0);
+ tryAgain = (retryCount > 0 && onAvailStack.length > 0);
}
// onAvailable
var notAvail = [];
var executeItem = function (el, item) {
- var scope = el;
- if (item.override) {
- if (item.override === true) {
- scope = item.obj;
+ var context = el;
+ if (item.overrideContext) {
+ if (item.overrideContext === true) {
+ context = item.obj;
} else {
- scope = item.override;
+ context = item.overrideContext;
}
}
- item.fn.call(scope, item.obj);
+ item.fn.call(context, item.obj);
};
- var i,len,item,el;
+ var i, len, item, el, ready=[];
- // onAvailable
- for (i=0,len=onAvailStack.length; i-1; i--) {
+ item = onAvailStack[i];
+ if (!item || !item.id) {
+ onAvailStack.splice(i, 1);
+ }
+ }
+
this.startInterval();
} else {
- clearInterval(this._interval);
- this._interval = null;
+ if (this._interval) {
+ clearInterval(this._interval);
+ this._interval = null;
+ }
}
this.locked = false;
- return true;
-
},
/**
@@ -1594,19 +1789,18 @@
* @static
*/
purgeElement: function(el, recurse, sType) {
- var elListeners = this.getListeners(el, sType);
+ var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el;
+ var elListeners = this.getListeners(oEl, sType), i, len;
if (elListeners) {
- for (var i=0,len=elListeners.length; i-1; i--) {
var l = elListeners[i];
- // can't use the index on the changing collection
- this.removeListener(el, l.type, l.fn, l.index);
- //this.removeListener(el, l.type, l.fn);
+ this.removeListener(oEl, l.type, l.fn);
}
}
- if (recurse && el && el.childNodes) {
- for (i=0,len=el.childNodes.length; i 0) {
+ if (searchList) {
for (var i=0,len=searchList.length; i 0) {
- j = listeners.length;
- while (j) {
- index = j-1;
- l = listeners[index];
+ // Remove listeners to handle IE memory leaks
+ //if (YAHOO.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).
+ if (listeners) {
+ for (j=listeners.length-1; j>-1; j--) {
+ l = listeners[j];
if (l) {
- EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], index);
+ EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j);
}
- j = j - 1;
}
l=null;
-
- EU.clearCache();
}
- for (i=0,len=legacyEvents.length; i<'+'/script>');
- el=document.getElementById("_yui_eu_dr");
- }
+ var n = document.createElement('p');
- if (el) {
- el.onreadystatechange = function() {
- //YAHOO.log(";comp-" + this.readyState + ";");
- if ("complete" === this.readyState) {
- this.parentNode.removeChild(this);
- YAHOO.util.Event._ready();
- }
- };
- } else {
- // The library was likely injected into the page
- // rendering onDOMReady unreliable
- // YAHOO.util.Event._ready();
- }
+ EU._dri = setInterval(function() {
+ try {
+ // throws an error if doc is not ready
+ n.doScroll('left');
+ clearInterval(EU._dri);
+ EU._dri = null;
+ EU._ready();
+ n = null;
+ } catch (ex) {
+ }
+ }, EU.POLL_INTERVAL);
- el=null;
-
- // Safari: The document's readyState in Safari currently will
+ // The document's readyState in Safari currently will
// change to loaded/complete before images are loaded.
- //} else if (EU.webkit) {
- } else if (EU.webkit) {
+ } else if (EU.webkit && EU.webkit < 525) {
- EU._drwatch = setInterval(function(){
+ EU._dri = setInterval(function() {
var rs=document.readyState;
if ("loaded" == rs || "complete" == rs) {
- clearInterval(EU._drwatch);
- EU._drwatch = null;
+ clearInterval(EU._dri);
+ EU._dri = null;
EU._ready();
}
}, EU.POLL_INTERVAL);
// FireFox and Opera: These browsers provide a event for this
- // moment.
+ // moment. The latest WebKit releases now support this event.
} else {
- // @todo will this fire when the library is injected?
-
EU._simpleAdd(document, "DOMContentLoaded", EU._ready);
}
@@ -1967,24 +2138,24 @@
* @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
+ * @param overrideContext {boolean} If true, the obj passed in becomes the
* execution scope of the listener
*/
- subscribe: function(p_type, p_fn, p_obj, p_override) {
+ subscribe: function(p_type, p_fn, p_obj, overrideContext) {
this.__yui_events = this.__yui_events || {};
var ce = this.__yui_events[p_type];
if (ce) {
- ce.subscribe(p_fn, p_obj, p_override);
+ ce.subscribe(p_fn, p_obj, overrideContext);
} else {
this.__yui_subscribers = this.__yui_subscribers || {};
var subs = this.__yui_subscribers;
if (!subs[p_type]) {
subs[p_type] = [];
}
subs[p_type].push(
- { fn: p_fn, obj: p_obj, override: p_override } );
+ { fn: p_fn, obj: p_obj, overrideContext: overrideContext } );
}
},
@@ -2012,8 +2183,8 @@
return ce.unsubscribe(p_fn, p_obj);
}
} else {
+ var ret = true;
for (var i in evts) {
- var ret = true;
if (YAHOO.lang.hasOwnProperty(evts, i)) {
ret = ret && evts[i].unsubscribe(p_fn, p_obj);
}
@@ -2091,7 +2262,7 @@
if (qs) {
for (var i=0; iThe custom object (if any) that was passed into the subscribe()
* method
*
- * If the custom event has not been explicitly created, it will be
- * created now with the default config, scoped 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
@@ -2152,6 +2321,10 @@
};
+(function() {
+
+ var Event = YAHOO.util.Event, Lang = YAHOO.lang;
+
/**
* KeyListener is a utility that provides an easy interface for listening for
* keydown/keyup events fired against DOM elements.
@@ -2228,11 +2401,11 @@
*/
this.disabledEvent = new YAHOO.util.CustomEvent("disabled");
- if (typeof attachTo == 'string') {
- attachTo = document.getElementById(attachTo);
+ if (Lang.isString(attachTo)) {
+ attachTo = document.getElementById(attachTo); // No Dom util
}
- if (typeof handler == 'function') {
+ if (Lang.isFunction(handler)) {
keyEvent.subscribe(handler);
} else {
keyEvent.subscribe(handler.fn, handler.scope, handler.correctScope);
@@ -2261,27 +2434,22 @@
e.altKey == keyData.alt &&
e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
- var dataItem;
- var keyPressed;
+ var dataItem, keys = keyData.keys, key;
- if (keyData.keys instanceof Array) {
- for (var i=0;i