import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -1,8 +1,8 @@
/*
Copyright (c) 2008, 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.6.0
version: 2.7.0
*/
/**
@ -11,7 +11,7 @@ version: 2.6.0
*
* @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 @@ version: 2.6.0
* @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 @@ YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
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,11 +100,12 @@ YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
* @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);
@ -150,22 +151,22 @@ YAHOO.util.CustomEvent.prototype = {
* @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) );
},
/**
@ -200,7 +201,7 @@ throw new Error("Invalid callback for subscriber to '" + this.type + "'");
/**
* 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:
* <ul>
* <li>The type of event</li>
@ -299,13 +300,14 @@ YAHOO.log("Event stopped, sub " + i + " of " + len, "info", "Event");
* @return {int} The number of listeners unsubscribed
*/
unsubscribeAll: function() {
for (var i=this.subscribers.length-1; i>-1; i--) {
var l = this.subscribers.length, i;
for (i=l-1; i>-1; i--) {
this._delete(i);
}
this.subscribers=[];
return i;
return l;
},
/**
@ -328,7 +330,7 @@ YAHOO.log("Event stopped, sub " + i + " of " + len, "info", "Event");
*/
toString: function() {
return "CustomEvent: " + "'" + this.type + "', " +
"scope: " + this.scope;
"context: " + this.scope;
}
};
@ -339,12 +341,12 @@ YAHOO.log("Event stopped, sub " + i + " of " + len, "info", "Event");
* 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
@ -362,32 +364,32 @@ YAHOO.util.Subscriber = function(fn, obj, override) {
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;
@ -416,7 +418,7 @@ YAHOO.util.Subscriber.prototype.contains = function(fn, obj) {
*/
YAHOO.util.Subscriber.prototype.toString = function() {
return "Subscriber { obj: " + this.obj +
", override: " + (this.override || "no") + " }";
", overrideContext: " + (this.overrideContext || "no") + " }";
};
/**
@ -599,7 +601,7 @@ if (!YAHOO.util.Event) {
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
@ -619,7 +621,7 @@ if (!YAHOO.util.Event) {
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
@ -638,7 +640,7 @@ if (!YAHOO.util.Event) {
OBJ: 5,
/**
* The original scope parameter passed into addListener
* The original context parameter passed into addListener
* @property OVERRIDE
* @type int
* @static
@ -646,16 +648,6 @@ if (!YAHOO.util.Event) {
*/
OVERRIDE: 6,
/**
* The original capture parameter passed into _addListener
* @property CAPTURE
* @type int
* @static
* @final
*/
CAPTURE: 7,
/**
* addListener/removeListener can throw errors in unexpected scenarios.
* These errors are suppressed, the method returns false, and this property
@ -755,26 +747,26 @@ if (!YAHOO.util.Event) {
*
* @method onAvailable
*
* @param {string||string[]} p_id the id of the element, or an array
* @param {string||string[]} 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 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
* @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
onAvailable: function(p_id, p_fn, p_obj, p_override, checkContent) {
onAvailable: function(id, fn, obj, overrideContext, checkContent) {
var a = (YAHOO.lang.isString(p_id)) ? [p_id] : p_id;
var a = (YAHOO.lang.isString(id)) ? [id] : id;
for (var i=0; i<a.length; i=i+1) {
onAvailStack.push({id: a[i],
fn: p_fn,
obj: p_obj,
override: p_override,
fn: fn,
obj: obj,
overrideContext: overrideContext,
checkReady: checkContent });
}
@ -793,18 +785,18 @@ if (!YAHOO.util.Event) {
*
* @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
* @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(p_id, p_fn, p_obj, p_override) {
this.onAvailable(p_id, p_fn, p_obj, p_override, true);
onContentReady: function(id, fn, obj, overrideContext) {
this.onAvailable(id, fn, obj, overrideContext, true);
},
/**
@ -830,30 +822,30 @@ if (!YAHOO.util.Event) {
*
* @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) {
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);
}
},
@ -870,10 +862,10 @@ if (!YAHOO.util.Event) {
* @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
@ -882,7 +874,7 @@ if (!YAHOO.util.Event) {
* @private
* @static
*/
_addListener: function(el, sType, fn, obj, override, capture) {
_addListener: function(el, sType, fn, obj, overrideContext, bCapture) {
if (!fn || !fn.call) {
YAHOO.log(sType + " addListener failed, invalid callback", "error", "Event");
@ -893,12 +885,11 @@ if (!YAHOO.util.Event) {
if ( this._isValidCollection(el)) {
var ok = true;
for (var i=0,len=el.length; i<len; ++i) {
ok = this._addListener(el[i],
ok = this.on(el[i],
sType,
fn,
obj,
override,
capture) && ok;
overrideContext) && ok;
}
return ok;
@ -916,7 +907,7 @@ if (!YAHOO.util.Event) {
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
YAHOO.util.Event._addListener(el, sType, fn, obj, override, capture);
YAHOO.util.Event.on(el, sType, fn, obj, overrideContext);
});
return true;
@ -936,32 +927,32 @@ if (!YAHOO.util.Event) {
// handles explicitly during our one unload event.
if ("unload" == sType && obj !== this) {
unloadListeners[unloadListeners.length] =
[el, sType, fn, obj, override, capture];
[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, el),
return fn.call(context, YAHOO.util.Event.getEvent(e, el),
obj);
};
var li = [el, sType, fn, wrappedFn, scope, obj, override, capture];
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;
@ -997,12 +988,12 @@ if (!YAHOO.util.Event) {
} else {
try {
this._simpleAdd(el, sType, wrappedFn, capture);
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
this.lastError = ex;
this._removeListener(el, sType, fn, capture);
this.removeListener(el, sType, fn);
return false;
}
}
@ -1024,23 +1015,23 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, sType, fn, obj, override, false);
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, and Gecko.)
* the focus, capture-event for Opera, WebKit.)
*
* @method addFocusListener
*
@ -1050,25 +1041,25 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, _FOCUS, fn, obj, override, true);
addFocusListener: function (el, fn, obj, overrideContext) {
return this._addListener(el, _FOCUS, fn, obj, overrideContext, true);
},
/**
* Removes a focus event listener
*
* @method removeFocusListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1081,12 +1072,12 @@ if (!YAHOO.util.Event) {
* @static
*/
removeFocusListener: function (el, fn) {
return this._removeListener(el, _FOCUS, fn, true);
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, and Gecko.)
* the focusout, capture-event for Opera, WebKit.)
*
* @method addBlurListener
*
@ -1096,24 +1087,24 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, _BLUR, fn, obj, override, true);
addBlurListener: function (el, fn, obj, overrideContext) {
return this._addListener(el, _BLUR, fn, obj, overrideContext, true);
},
/**
* Removes a blur event listener
*
* @method removeBlurListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1127,7 +1118,7 @@ if (!YAHOO.util.Event) {
*/
removeBlurListener: function (el, fn) {
return this._removeListener(el, _BLUR, fn, true);
return this.removeListener(el, _BLUR, fn);
},
@ -1140,15 +1131,15 @@ if (!YAHOO.util.Event) {
*/
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].slice();
for (var i=0, len=lh.length; i<len; ++i) {
// for (var i in lh.length) {
li = lh[i];
if ( li && li[this.WFN] ) {
scope = li[this.ADJ_SCOPE];
ret = li[this.WFN].call(scope, e);
context = li[this.ADJ_SCOPE];
ret = li[this.WFN].call(context, e);
ok = (ok && ret);
}
}
@ -1196,7 +1187,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
/**
* Removes an event listener
*
* @method _removeListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1205,13 +1196,11 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
* @param {Function} fn the method the event invokes. If fn is
* undefined, then all event handlers for the type of event are
* removed.
* @param {boolen} capture capture or bubble phase
* @return {boolean} true if the unbind was successful, false
* otherwise.
* @static
* @private
*/
_removeListener: function(el, sType, fn, capture) {
removeListener: function(el, sType, fn) {
var i, len, li;
// The el argument can be a string
@ -1221,7 +1210,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
} else if ( this._isValidCollection(el)) {
var ok = true;
for (i=el.length-1; i>-1; i--) {
ok = ( this._removeListener(el[i], sType, fn, capture) && ok );
ok = ( this.removeListener(el[i], sType, fn) && ok );
}
return ok;
}
@ -1254,7 +1243,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
// 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.
var index = arguments[4];
var index = arguments[3];
if ("undefined" === typeof index) {
index = this._getCacheIndex(el, sType, fn);
@ -1291,7 +1280,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
} else {
try {
this._simpleRemove(el, sType, cacheItem[this.WFN], capture);
this._simpleRemove(el, sType, cacheItem[this.WFN], false);
} catch(ex) {
this.lastError = ex;
return false;
@ -1308,30 +1297,6 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
},
/**
* Removes an 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 {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
*/
removeListener: function(el, sType, fn) {
return this._removeListener(el, sType, fn, false);
},
/**
* Returns the event's target element. Safari sometimes provides
* a text node, and this is automatically resolved to the text
@ -1710,8 +1675,10 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
if (onAvailStack.length === 0) {
retryCount = 0;
clearInterval(this._interval);
this._interval = null;
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
return;
}
@ -1746,15 +1713,15 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
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, ready=[];
@ -1799,8 +1766,10 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
this.startInterval();
} else {
clearInterval(this._interval);
this._interval = null;
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
}
this.locked = false;
@ -1825,7 +1794,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
if (elListeners) {
for (i=elListeners.length-1; i>-1; i--) {
var l = elListeners[i];
this._removeListener(oEl, l.type, l.fn, l.capture);
this.removeListener(oEl, l.type, l.fn);
}
}
@ -1847,9 +1816,8 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
* &nbsp;&nbsp;type: (string) the type of event
* &nbsp;&nbsp;fn: (function) the callback supplied to addListener
* &nbsp;&nbsp;obj: (object) the custom object supplied to addListener
* &nbsp;&nbsp;adjust: (boolean|object) whether or not to adjust the default scope
* &nbsp;&nbsp;scope: (boolean) the derived scope based on the adjust parameter
* &nbsp;&nbsp;scope: (capture) the capture parameter supplied to addListener
* &nbsp;&nbsp;adjust: (boolean|object) whether or not to adjust the default context
* &nbsp;&nbsp;scope: (boolean) the derived context based on the adjust parameter
* &nbsp;&nbsp;index: (int) its position in the Event util listener cache
* @static
*/
@ -1878,7 +1846,6 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
obj: l[this.OBJ],
adjust: l[this.OVERRIDE],
scope: l[this.ADJ_SCOPE],
capture: l[this.CAPTURE],
index: i
});
}
@ -1899,27 +1866,27 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
_unload: function(e) {
var EU = YAHOO.util.Event, i, j, l, len, index,
ul = unloadListeners.slice();
ul = unloadListeners.slice(), context;
// execute and clear stored unload listeners
for (i=0,len=unloadListeners.length; i<len; ++i) {
for (i=0, len=unloadListeners.length; i<len; ++i) {
l = ul[i];
if (l) {
var scope = window;
context = window;
if (l[EU.ADJ_SCOPE]) {
if (l[EU.ADJ_SCOPE] === true) {
scope = l[EU.UNLOAD_OBJ];
context = l[EU.UNLOAD_OBJ];
} else {
scope = l[EU.ADJ_SCOPE];
context = l[EU.ADJ_SCOPE];
}
}
l[EU.FN].call(scope, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
l[EU.FN].call(context, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
ul[i] = null;
l=null;
scope=null;
}
}
l = null;
context = null;
unloadListeners = null;
// Remove listeners to handle IE memory leaks
@ -1933,7 +1900,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
for (j=listeners.length-1; j>-1; j--) {
l = listeners[j];
if (l) {
EU._removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], l[EU.CAPTURE], j);
EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j);
}
}
l=null;
@ -1996,7 +1963,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
},
/**
* Adds a DOM event directly without the caching, cleanup, scope adj, etc
* Adds a DOM event directly without the caching, cleanup, context adj, etc
*
* @method _simpleAdd
* @param {HTMLElement} el the element to bind the handler to
@ -2171,16 +2138,16 @@ YAHOO.util.EventProvider.prototype = {
* @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;
@ -2188,7 +2155,7 @@ YAHOO.util.EventProvider.prototype = {
subs[p_type] = [];
}
subs[p_type].push(
{ fn: p_fn, obj: p_obj, override: p_override } );
{ fn: p_fn, obj: p_obj, overrideContext: overrideContext } );
}
},
@ -2295,7 +2262,7 @@ YAHOO.log("EventProvider createEvent skipped: '"+p_type+"' already exists");
if (qs) {
for (var i=0; i<qs.length; ++i) {
ce.subscribe(qs[i].fn, qs[i].obj, qs[i].override);
ce.subscribe(qs[i].fn, qs[i].obj, qs[i].overrideContext);
}
}
}
@ -2354,9 +2321,9 @@ YAHOO.log(p_type + "event fired before it was created.");
};
//@TODO optimize
//@TODO use event utility, lang abstractions
//@TODO replace
(function() {
var Event = YAHOO.util.Event, Lang = YAHOO.lang;
/**
* KeyListener is a utility that provides an easy interface for listening for
@ -2434,11 +2401,11 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
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);
@ -2467,26 +2434,22 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
e.altKey == keyData.alt &&
e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
var dataItem;
var dataItem, keys = keyData.keys, key;
if (keyData.keys instanceof Array) {
for (var i=0;i<keyData.keys.length;i++) {
dataItem = keyData.keys[i];
if (YAHOO.lang.isArray(keys)) {
for (var i=0;i<keys.length;i++) {
dataItem = keys[i];
key = Event.getCharCode(e);
if (dataItem == e.charCode ) {
keyEvent.fire(e.charCode, e);
break;
} else if (dataItem == e.keyCode) {
keyEvent.fire(e.keyCode, e);
if (dataItem == key) {
keyEvent.fire(key, e);
break;
}
}
} else {
dataItem = keyData.keys;
if (dataItem == e.charCode ) {
keyEvent.fire(e.charCode, e);
} else if (dataItem == e.keyCode) {
keyEvent.fire(e.keyCode, e);
key = Event.getCharCode(e);
if (keys == key ) {
keyEvent.fire(key, e);
}
}
}
@ -2499,7 +2462,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
this.enable = function() {
if (! this.enabled) {
YAHOO.util.Event.addListener(attachTo, event, handleKeyPress);
Event.on(attachTo, event, handleKeyPress);
this.enabledEvent.fire(keyData);
}
/**
@ -2517,7 +2480,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
this.disable = function() {
if (this.enabled) {
YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress);
Event.removeListener(attachTo, event, handleKeyPress);
this.disabledEvent.fire(keyData);
}
this.enabled = false;
@ -2535,6 +2498,8 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
};
var KeyListener = YAHOO.util.KeyListener;
/**
* Constant representing the DOM "keydown" event.
* @property YAHOO.util.KeyListener.KEYDOWN
@ -2542,7 +2507,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
* @final
* @type String
*/
YAHOO.util.KeyListener.KEYDOWN = "keydown";
KeyListener.KEYDOWN = "keydown";
/**
* Constant representing the DOM "keyup" event.
@ -2551,7 +2516,7 @@ YAHOO.util.KeyListener.KEYDOWN = "keydown";
* @final
* @type String
*/
YAHOO.util.KeyListener.KEYUP = "keyup";
KeyListener.KEYUP = "keyup";
/**
* keycode constants for a subset of the special keys
@ -2559,7 +2524,7 @@ YAHOO.util.KeyListener.KEYUP = "keyup";
* @static
* @final
*/
YAHOO.util.KeyListener.KEY = {
KeyListener.KEY = {
ALT : 18,
BACK_SPACE : 8,
CAPS_LOCK : 20,
@ -2584,4 +2549,6 @@ YAHOO.util.KeyListener.KEY = {
TAB : 9,
UP : 38
};
YAHOO.register("event", YAHOO.util.Event, {version: "2.6.0", build: "1321"});
})();
YAHOO.register("event", YAHOO.util.Event, {version: "2.7.0", build: "1799"});

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
/*
Copyright (c) 2008, 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.6.0
version: 2.7.0
*/
/**
@ -11,7 +11,7 @@ version: 2.6.0
*
* @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 @@ version: 2.6.0
* @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 @@ YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
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
@ -99,11 +99,12 @@ YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
* @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);
@ -149,22 +150,22 @@ YAHOO.util.CustomEvent.prototype = {
* @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) );
},
/**
@ -199,7 +200,7 @@ throw new Error("Invalid callback for subscriber to '" + this.type + "'");
/**
* 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:
* <ul>
* <li>The type of event</li>
@ -288,13 +289,14 @@ throw new Error("Invalid callback for subscriber to '" + this.type + "'");
* @return {int} The number of listeners unsubscribed
*/
unsubscribeAll: function() {
for (var i=this.subscribers.length-1; i>-1; i--) {
var l = this.subscribers.length, i;
for (i=l-1; i>-1; i--) {
this._delete(i);
}
this.subscribers=[];
return i;
return l;
},
/**
@ -317,7 +319,7 @@ throw new Error("Invalid callback for subscriber to '" + this.type + "'");
*/
toString: function() {
return "CustomEvent: " + "'" + this.type + "', " +
"scope: " + this.scope;
"context: " + this.scope;
}
};
@ -328,12 +330,12 @@ throw new Error("Invalid callback for subscriber to '" + this.type + "'");
* 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
@ -351,32 +353,32 @@ YAHOO.util.Subscriber = function(fn, obj, override) {
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;
@ -405,7 +407,7 @@ YAHOO.util.Subscriber.prototype.contains = function(fn, obj) {
*/
YAHOO.util.Subscriber.prototype.toString = function() {
return "Subscriber { obj: " + this.obj +
", override: " + (this.override || "no") + " }";
", overrideContext: " + (this.overrideContext || "no") + " }";
};
/**
@ -588,7 +590,7 @@ if (!YAHOO.util.Event) {
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
@ -608,7 +610,7 @@ if (!YAHOO.util.Event) {
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
@ -627,7 +629,7 @@ if (!YAHOO.util.Event) {
OBJ: 5,
/**
* The original scope parameter passed into addListener
* The original context parameter passed into addListener
* @property OVERRIDE
* @type int
* @static
@ -635,16 +637,6 @@ if (!YAHOO.util.Event) {
*/
OVERRIDE: 6,
/**
* The original capture parameter passed into _addListener
* @property CAPTURE
* @type int
* @static
* @final
*/
CAPTURE: 7,
/**
* addListener/removeListener can throw errors in unexpected scenarios.
* These errors are suppressed, the method returns false, and this property
@ -744,26 +736,26 @@ if (!YAHOO.util.Event) {
*
* @method onAvailable
*
* @param {string||string[]} p_id the id of the element, or an array
* @param {string||string[]} 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 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
* @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
onAvailable: function(p_id, p_fn, p_obj, p_override, checkContent) {
onAvailable: function(id, fn, obj, overrideContext, checkContent) {
var a = (YAHOO.lang.isString(p_id)) ? [p_id] : p_id;
var a = (YAHOO.lang.isString(id)) ? [id] : id;
for (var i=0; i<a.length; i=i+1) {
onAvailStack.push({id: a[i],
fn: p_fn,
obj: p_obj,
override: p_override,
fn: fn,
obj: obj,
overrideContext: overrideContext,
checkReady: checkContent });
}
@ -782,18 +774,18 @@ if (!YAHOO.util.Event) {
*
* @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
* @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(p_id, p_fn, p_obj, p_override) {
this.onAvailable(p_id, p_fn, p_obj, p_override, true);
onContentReady: function(id, fn, obj, overrideContext) {
this.onAvailable(id, fn, obj, overrideContext, true);
},
/**
@ -819,30 +811,30 @@ if (!YAHOO.util.Event) {
*
* @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) {
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);
}
},
@ -859,10 +851,10 @@ if (!YAHOO.util.Event) {
* @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
@ -871,7 +863,7 @@ if (!YAHOO.util.Event) {
* @private
* @static
*/
_addListener: function(el, sType, fn, obj, override, capture) {
_addListener: function(el, sType, fn, obj, overrideContext, bCapture) {
if (!fn || !fn.call) {
return false;
@ -881,12 +873,11 @@ if (!YAHOO.util.Event) {
if ( this._isValidCollection(el)) {
var ok = true;
for (var i=0,len=el.length; i<len; ++i) {
ok = this._addListener(el[i],
ok = this.on(el[i],
sType,
fn,
obj,
override,
capture) && ok;
overrideContext) && ok;
}
return ok;
@ -904,7 +895,7 @@ if (!YAHOO.util.Event) {
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
YAHOO.util.Event._addListener(el, sType, fn, obj, override, capture);
YAHOO.util.Event.on(el, sType, fn, obj, overrideContext);
});
return true;
@ -923,31 +914,31 @@ if (!YAHOO.util.Event) {
// handles explicitly during our one unload event.
if ("unload" == sType && obj !== this) {
unloadListeners[unloadListeners.length] =
[el, sType, fn, obj, override, capture];
[el, sType, fn, obj, overrideContext];
return true;
}
// 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, el),
return fn.call(context, YAHOO.util.Event.getEvent(e, el),
obj);
};
var li = [el, sType, fn, wrappedFn, scope, obj, override, capture];
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;
@ -983,12 +974,12 @@ if (!YAHOO.util.Event) {
} else {
try {
this._simpleAdd(el, sType, wrappedFn, capture);
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
this.lastError = ex;
this._removeListener(el, sType, fn, capture);
this.removeListener(el, sType, fn);
return false;
}
}
@ -1010,23 +1001,23 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, sType, fn, obj, override, false);
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, and Gecko.)
* the focus, capture-event for Opera, WebKit.)
*
* @method addFocusListener
*
@ -1036,25 +1027,25 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, _FOCUS, fn, obj, override, true);
addFocusListener: function (el, fn, obj, overrideContext) {
return this._addListener(el, _FOCUS, fn, obj, overrideContext, true);
},
/**
* Removes a focus event listener
*
* @method removeFocusListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1067,12 +1058,12 @@ if (!YAHOO.util.Event) {
* @static
*/
removeFocusListener: function (el, fn) {
return this._removeListener(el, _FOCUS, fn, true);
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, and Gecko.)
* the focusout, capture-event for Opera, WebKit.)
*
* @method addBlurListener
*
@ -1082,24 +1073,24 @@ if (!YAHOO.util.Event) {
* @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.
* @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, override) {
return this._addListener(el, _BLUR, fn, obj, override, true);
addBlurListener: function (el, fn, obj, overrideContext) {
return this._addListener(el, _BLUR, fn, obj, overrideContext, true);
},
/**
* Removes a blur event listener
*
* @method removeBlurListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1113,7 +1104,7 @@ if (!YAHOO.util.Event) {
*/
removeBlurListener: function (el, fn) {
return this._removeListener(el, _BLUR, fn, true);
return this.removeListener(el, _BLUR, fn);
},
@ -1125,15 +1116,15 @@ if (!YAHOO.util.Event) {
* @private
*/
fireLegacyEvent: function(e, legacyIndex) {
var ok=true, le, lh, li, scope, ret;
var ok=true, le, lh, li, context, ret;
lh = legacyHandlers[legacyIndex].slice();
for (var i=0, len=lh.length; i<len; ++i) {
// for (var i in lh.length) {
li = lh[i];
if ( li && li[this.WFN] ) {
scope = li[this.ADJ_SCOPE];
ret = li[this.WFN].call(scope, e);
context = li[this.ADJ_SCOPE];
ret = li[this.WFN].call(context, e);
ok = (ok && ret);
}
}
@ -1181,7 +1172,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
/**
* Removes an event listener
*
* @method _removeListener
* @method removeListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to remove
@ -1190,13 +1181,11 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
* @param {Function} fn the method the event invokes. If fn is
* undefined, then all event handlers for the type of event are
* removed.
* @param {boolen} capture capture or bubble phase
* @return {boolean} true if the unbind was successful, false
* otherwise.
* @static
* @private
*/
_removeListener: function(el, sType, fn, capture) {
removeListener: function(el, sType, fn) {
var i, len, li;
// The el argument can be a string
@ -1206,7 +1195,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
} else if ( this._isValidCollection(el)) {
var ok = true;
for (i=el.length-1; i>-1; i--) {
ok = ( this._removeListener(el[i], sType, fn, capture) && ok );
ok = ( this.removeListener(el[i], sType, fn) && ok );
}
return ok;
}
@ -1238,7 +1227,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
// 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.
var index = arguments[4];
var index = arguments[3];
if ("undefined" === typeof index) {
index = this._getCacheIndex(el, sType, fn);
@ -1273,7 +1262,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
} else {
try {
this._simpleRemove(el, sType, cacheItem[this.WFN], capture);
this._simpleRemove(el, sType, cacheItem[this.WFN], false);
} catch(ex) {
this.lastError = ex;
return false;
@ -1290,30 +1279,6 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
},
/**
* Removes an 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 {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
*/
removeListener: function(el, sType, fn) {
return this._removeListener(el, sType, fn, false);
},
/**
* Returns the event's target element. Safari sometimes provides
* a text node, and this is automatically resolved to the text
@ -1691,8 +1656,10 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
if (onAvailStack.length === 0) {
retryCount = 0;
clearInterval(this._interval);
this._interval = null;
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
return;
}
@ -1726,15 +1693,15 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
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, ready=[];
@ -1779,8 +1746,10 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
this.startInterval();
} else {
clearInterval(this._interval);
this._interval = null;
if (this._interval) {
clearInterval(this._interval);
this._interval = null;
}
}
this.locked = false;
@ -1805,7 +1774,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
if (elListeners) {
for (i=elListeners.length-1; i>-1; i--) {
var l = elListeners[i];
this._removeListener(oEl, l.type, l.fn, l.capture);
this.removeListener(oEl, l.type, l.fn);
}
}
@ -1827,9 +1796,8 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
* &nbsp;&nbsp;type: (string) the type of event
* &nbsp;&nbsp;fn: (function) the callback supplied to addListener
* &nbsp;&nbsp;obj: (object) the custom object supplied to addListener
* &nbsp;&nbsp;adjust: (boolean|object) whether or not to adjust the default scope
* &nbsp;&nbsp;scope: (boolean) the derived scope based on the adjust parameter
* &nbsp;&nbsp;scope: (capture) the capture parameter supplied to addListener
* &nbsp;&nbsp;adjust: (boolean|object) whether or not to adjust the default context
* &nbsp;&nbsp;scope: (boolean) the derived context based on the adjust parameter
* &nbsp;&nbsp;index: (int) its position in the Event util listener cache
* @static
*/
@ -1858,7 +1826,6 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
obj: l[this.OBJ],
adjust: l[this.OVERRIDE],
scope: l[this.ADJ_SCOPE],
capture: l[this.CAPTURE],
index: i
});
}
@ -1879,27 +1846,27 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
_unload: function(e) {
var EU = YAHOO.util.Event, i, j, l, len, index,
ul = unloadListeners.slice();
ul = unloadListeners.slice(), context;
// execute and clear stored unload listeners
for (i=0,len=unloadListeners.length; i<len; ++i) {
for (i=0, len=unloadListeners.length; i<len; ++i) {
l = ul[i];
if (l) {
var scope = window;
context = window;
if (l[EU.ADJ_SCOPE]) {
if (l[EU.ADJ_SCOPE] === true) {
scope = l[EU.UNLOAD_OBJ];
context = l[EU.UNLOAD_OBJ];
} else {
scope = l[EU.ADJ_SCOPE];
context = l[EU.ADJ_SCOPE];
}
}
l[EU.FN].call(scope, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
l[EU.FN].call(context, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
ul[i] = null;
l=null;
scope=null;
}
}
l = null;
context = null;
unloadListeners = null;
// Remove listeners to handle IE memory leaks
@ -1913,7 +1880,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
for (j=listeners.length-1; j>-1; j--) {
l = listeners[j];
if (l) {
EU._removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], l[EU.CAPTURE], j);
EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j);
}
}
l=null;
@ -1976,7 +1943,7 @@ return (this.webkit && this.webkit < 419 && ("click"==sType || "dblclick"==sType
},
/**
* Adds a DOM event directly without the caching, cleanup, scope adj, etc
* Adds a DOM event directly without the caching, cleanup, context adj, etc
*
* @method _simpleAdd
* @param {HTMLElement} el the element to bind the handler to
@ -2151,16 +2118,16 @@ YAHOO.util.EventProvider.prototype = {
* @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;
@ -2168,7 +2135,7 @@ YAHOO.util.EventProvider.prototype = {
subs[p_type] = [];
}
subs[p_type].push(
{ fn: p_fn, obj: p_obj, override: p_override } );
{ fn: p_fn, obj: p_obj, overrideContext: overrideContext } );
}
},
@ -2274,7 +2241,7 @@ YAHOO.util.EventProvider.prototype = {
if (qs) {
for (var i=0; i<qs.length; ++i) {
ce.subscribe(qs[i].fn, qs[i].obj, qs[i].override);
ce.subscribe(qs[i].fn, qs[i].obj, qs[i].overrideContext);
}
}
}
@ -2332,9 +2299,9 @@ YAHOO.util.EventProvider.prototype = {
};
//@TODO optimize
//@TODO use event utility, lang abstractions
//@TODO replace
(function() {
var Event = YAHOO.util.Event, Lang = YAHOO.lang;
/**
* KeyListener is a utility that provides an easy interface for listening for
@ -2409,11 +2376,11 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
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);
@ -2442,26 +2409,22 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
e.altKey == keyData.alt &&
e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
var dataItem;
var dataItem, keys = keyData.keys, key;
if (keyData.keys instanceof Array) {
for (var i=0;i<keyData.keys.length;i++) {
dataItem = keyData.keys[i];
if (YAHOO.lang.isArray(keys)) {
for (var i=0;i<keys.length;i++) {
dataItem = keys[i];
key = Event.getCharCode(e);
if (dataItem == e.charCode ) {
keyEvent.fire(e.charCode, e);
break;
} else if (dataItem == e.keyCode) {
keyEvent.fire(e.keyCode, e);
if (dataItem == key) {
keyEvent.fire(key, e);
break;
}
}
} else {
dataItem = keyData.keys;
if (dataItem == e.charCode ) {
keyEvent.fire(e.charCode, e);
} else if (dataItem == e.keyCode) {
keyEvent.fire(e.keyCode, e);
key = Event.getCharCode(e);
if (keys == key ) {
keyEvent.fire(key, e);
}
}
}
@ -2474,7 +2437,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
this.enable = function() {
if (! this.enabled) {
YAHOO.util.Event.addListener(attachTo, event, handleKeyPress);
Event.on(attachTo, event, handleKeyPress);
this.enabledEvent.fire(keyData);
}
/**
@ -2492,7 +2455,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
*/
this.disable = function() {
if (this.enabled) {
YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress);
Event.removeListener(attachTo, event, handleKeyPress);
this.disabledEvent.fire(keyData);
}
this.enabled = false;
@ -2510,6 +2473,8 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
};
var KeyListener = YAHOO.util.KeyListener;
/**
* Constant representing the DOM "keydown" event.
* @property YAHOO.util.KeyListener.KEYDOWN
@ -2517,7 +2482,7 @@ YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
* @final
* @type String
*/
YAHOO.util.KeyListener.KEYDOWN = "keydown";
KeyListener.KEYDOWN = "keydown";
/**
* Constant representing the DOM "keyup" event.
@ -2526,7 +2491,7 @@ YAHOO.util.KeyListener.KEYDOWN = "keydown";
* @final
* @type String
*/
YAHOO.util.KeyListener.KEYUP = "keyup";
KeyListener.KEYUP = "keyup";
/**
* keycode constants for a subset of the special keys
@ -2534,7 +2499,7 @@ YAHOO.util.KeyListener.KEYUP = "keyup";
* @static
* @final
*/
YAHOO.util.KeyListener.KEY = {
KeyListener.KEY = {
ALT : 18,
BACK_SPACE : 8,
CAPS_LOCK : 20,
@ -2559,4 +2524,6 @@ YAHOO.util.KeyListener.KEY = {
TAB : 9,
UP : 38
};
YAHOO.register("event", YAHOO.util.Event, {version: "2.6.0", build: "1321"});
})();
YAHOO.register("event", YAHOO.util.Event, {version: "2.7.0", build: "1799"});