webgui/www/extras/yui/docs/event/overview-summary-Event.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

847 lines
37 KiB
HTML

<html>
<head>
<title>JavaScript Documentation - Event.js</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1>JavaScript Documentation</h1>
<h3><a href="./index.html">Yui Event Utility</a></h3>
<div class="breadcrumbs">
<a href="./index.html">Yui Event Utility</a>
&gt;
<strong>Event.js</strong>
</div>
</div>
<div id="body">
<div class="nav">
<div class="module resources">
<ul class="content">
<li><a href="overview-tree.html">Tree View</a></li>
<li><a href="index-all.html">Element Index</a></li>
</ul>
</div>
<div class="module">
<h4><a href="./allclasses-noframe.html">Classes</a></h4>
<ul class="content">
<li>
<a href="YAHOO.util.html">
YAHOO.util</a>
</li>
<li>
<a href="YAHOO.util.CustomEvent.html">
YAHOO.util.CustomEvent</a>
</li>
<li>
<a href="YAHOO.util.Event.html">
YAHOO.util.Event</a>
</li>
<li>
<a href="YAHOO.util.Subscriber.html">
YAHOO.util.Subscriber</a>
</li>
</ul>
</div>
<div class="module">
<h4><a href="./overview-summary.html">Files</a></h4>
<ul class="content">
<li>
<a href="overview-summary-CustomEvent.js.html">
CustomEvent.js</a>
</li>
<li>
<a href="overview-summary-Event.js.html">
Event.js</a>
</li>
</ul>
</div>
</div>
<div class="main">
<h2>Event.js</h2>
<div class="meta">
</div>
<div class="quick-links">
<strong>Quick Links:</strong>&nbsp;
<a href="#classSummary">Class Summary</a> |
<a href="#source">Source Code</a>
</div>
<div class="section class summaries">
<h3><a name="classSummary">Class Summary</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<div class="content">
<table border="1" cellpadding="3" cellspacing="0">
<tr>
<td class="name">
<a href="YAHOO.util.Event.html">YAHOO.util.Event</a>
</td>
<td class="overview">The event utility provides functions to add and remove event listeners, event cleansing.</td>
</tr>
</table>
</div>
</div>
<div class="section source">
<h3><a name="source">Souce Code</a> <span class="top">[<a href="#top">top</a>]</span></h3>
<pre class="sourceview"><span class="comment">// Only load this library once. If it is loaded a second time, existing</span>
<span class="comment">// events cannot be detached.</span>
<span class="reserved">if</span> (!YAHOO.util.Event) {
<span class="comment">/**
* <span class="attrib">@class</span>
* The event utility provides functions to add and remove event listeners,
* event cleansing. It also tries to automatically remove listeners it
* registers during the unload event.
* <span class="attrib">@constructor</span>
*/</span>
YAHOO.util.Event = <span class="reserved">function</span>() {
YAHOO.util.Event.<span class="reserved">prototype</span> = {
<span class="comment">/**
* 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 200<span class="attrib">@50</span> ms, so it will poll
* for 10 seconds or until all outstanding handlers are bound
* (whichever comes first).
* <span class="attrib">@type</span> int
*/</span>
POLL_RETRYS: 200,
<span class="comment">/**
* The poll interval in milliseconds
* <span class="attrib">@type</span> int
*/</span>
POLL_INTERVAL: 50,
<span class="comment">/**
* Element to bind, int constant
* <span class="attrib">@type</span> int
*/</span>
EL: 0,
<span class="comment">/**
* Type of event, int constant
* <span class="attrib">@type</span> int
*/</span>
TYPE: 1,
<span class="comment">/**
* Function to execute, int constant
* <span class="attrib">@type</span> int
*/</span>
FN: 2,
<span class="comment">/**
* Function wrapped for scope correction and cleanup, int constant
* <span class="attrib">@type</span> int
*/</span>
WFN: 3,
<span class="comment">/**
* Object passed in by the user that will be returned as a
* parameter to the callback, int constant
* <span class="attrib">@type</span> int
*/</span>
SCOPE: 3,
<span class="comment">/**
* Adjusted scope, either the element we are registering the event
* on or the custom object passed in by the listener, int constant
* <span class="attrib">@type</span> int
*/</span>
ADJ_SCOPE: 4,
<span class="comment">/**
* Executes the supplied callback when the item with the supplied
* id is found. This is meant to be used to execute behavior as
* soon as possible as the page loads. If you use this after the
* initial page load it will poll for a fixed time for the element.
* The number of times it will poll and the frequency are
* configurable. By default it will poll for 10 seconds.
* <span class="attrib">@param</span> {string} p_id the id of the element to look for.
* <span class="attrib">@param</span> {function} p_fn what to execute when the element is found.
* <span class="attrib">@param</span> {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* <span class="attrib">@param</span> {boolean} p_override If set to true, p_fn will execute
* in the scope of p_obj
*
*/</span>
onAvailable: <span class="reserved">function</span>(p_id, p_fn, p_obj, p_override) {
onAvailStack.push( { id: p_id,
fn: p_fn,
obj: p_obj,
override: p_override } );
retryCount = <span class="reserved">this</span>.POLL_RETRYS;
<span class="reserved">this</span>.startTimeout(0);
<span class="comment"> // this._tryPreloadAttach();</span>
},
<span class="comment">/**
* Appends an event handler
*
* <span class="attrib">@param</span> {Object} el The html element to assign the
* event to
* <span class="attrib">@param</span> {String} sType The type of event to append
* <span class="attrib">@param</span> {Function} fn The method the event invokes
* <span class="attrib">@param</span> {Object} oScope An arbitrary object that will be
* passed as a parameter to the handler
* <span class="attrib">@param</span> {boolean} bOverride If true, the obj passed in becomes
* the execution scope of the listener
* <span class="attrib">@return</span> {boolean} True if the action was successful or defered,
* false if one or more of the elements
* could not have the event bound to it.
*/</span>
addListener: <span class="reserved">function</span>(el, sType, fn, oScope, bOverride) {
<span class="reserved">if</span> (!fn || !fn.call) {
<span class="comment"> // this.logger.debug("Error, function is not valid " + fn);</span>
<span class="reserved">return</span> false;
}
<span class="comment">
// The el argument can be an array of elements or element ids.</span>
<span class="reserved">if</span> ( <span class="reserved">this</span>._isValidCollection(el)) {
var ok = true;
<span class="reserved">for</span> (var i=0,len=el.length; i&lt;len; ++i) {
ok = ( <span class="reserved">this</span>.on(el[i],
sType,
fn,
oScope,
bOverride) &amp;&amp; ok );
}
<span class="reserved">return</span> ok;
} <span class="reserved">else</span> <span class="reserved">if</span> (typeof el == <span class="literal">"string"</span>) {
var oEl = <span class="reserved">this</span>.getEl(el);
<span class="comment"> // If the el argument is a string, we assume it is </span>
<span class="comment"> // actually the id of the element. If the page is loaded</span>
<span class="comment"> // we convert el to the actual element, otherwise we </span>
<span class="comment"> // defer attaching the event until onload event fires</span>
<span class="comment">
// check to see if we need to delay hooking up the event </span>
<span class="comment"> // until after the page loads.</span>
<span class="reserved">if</span> (loadComplete &amp;&amp; oEl) {
el = oEl;
} <span class="reserved">else</span> {
<span class="comment"> // defer adding the event until onload fires</span>
<span class="reserved">this</span>.addDelayedListener(el,
sType,
fn,
oScope,
bOverride);
<span class="reserved">return</span> true;
}
}
<span class="comment">
// Element should be an html element or an array if we get </span>
<span class="comment"> // here.</span>
<span class="reserved">if</span> (!el) {
<span class="comment"> // this.logger.debug("unable to attach event " + sType);</span>
<span class="reserved">return</span> false;
}
<span class="comment">
// we need to make sure we fire registered unload events </span>
<span class="comment"> // prior to automatically unhooking them. So we hang on to </span>
<span class="comment"> // these instead of attaching them to the window and fire the</span>
<span class="comment"> // handles explicitly during our one unload event.</span>
<span class="reserved">if</span> (<span class="literal">"unload"</span> == sType &amp;&amp; oScope !== <span class="reserved">this</span>) {
unloadListeners[unloadListeners.length] =
[el, sType, fn, oScope, bOverride];
<span class="reserved">return</span> true;
}
<span class="comment">
// this.logger.debug("Adding handler: " + el + ", " + sType);</span>
<span class="comment">
// if the user chooses to override the scope, we use the custom</span>
<span class="comment"> // object passed in, otherwise the executing scope will be the</span>
<span class="comment"> // HTML element that the event is registered on</span>
var scope = (bOverride) ? oScope : el;
<span class="comment">
// wrap the function so we can return the oScope object when</span>
<span class="comment"> // the event fires;</span>
var wrappedFn = <span class="reserved">function</span>(e) {
<span class="reserved">return</span> fn.call(scope, YAHOO.util.Event.getEvent(e),
oScope);
};
var li = [el, sType, fn, wrappedFn, scope];
var index = listeners.length;
<span class="comment"> // cache the listener so we can try to automatically unload</span>
listeners[index] = li;
<span class="reserved">if</span> (<span class="reserved">this</span>.useLegacyEvent(el, sType)) {
var legacyIndex = <span class="reserved">this</span>.getLegacyIndex(el, sType);
<span class="reserved">if</span> (legacyIndex == -1) {
legacyIndex = legacyEvents.length;
legacyMap[el.id + sType] = legacyIndex;
<span class="comment">
// cache the signature for the DOM0 event, and </span>
<span class="comment"> // include the existing handler for the event, if any</span>
legacyEvents[legacyIndex] =
[el, sType, el[<span class="literal">"on"</span> + sType]];
legacyHandlers[legacyIndex] = [];
el[<span class="literal">"on"</span> + sType] =
<span class="reserved">function</span>(e) {
YAHOO.util.Event.fireLegacyEvent(
YAHOO.util.Event.getEvent(e), legacyIndex);
};
}
<span class="comment">
// add a reference to the wrapped listener to our custom</span>
<span class="comment"> // stack of events</span>
legacyHandlers[legacyIndex].push(index);
<span class="comment">
// DOM2 Event model</span>
} <span class="reserved">else</span> <span class="reserved">if</span> (el.addEventListener) {
<span class="comment"> // this.logger.debug("adding DOM event: " + el.id + </span>
<span class="comment"> // ", " + sType);</span>
el.addEventListener(sType, wrappedFn, false);
<span class="comment"> // IE</span>
} <span class="reserved">else</span> <span class="reserved">if</span> (el.attachEvent) {
el.attachEvent(<span class="literal">"on"</span> + sType, wrappedFn);
}
<span class="reserved">return</span> true;
},
<span class="comment">/**
* Removes an event handler
*
* <span class="attrib">@param</span> {Object} el the html element or the id of the element to
* assign the event to.
* <span class="attrib">@param</span> {String} sType the type of event to remove
* <span class="attrib">@param</span> {Function} fn the method the event invokes
* <span class="attrib">@return</span> {boolean} true if the unbind was successful, false
* otherwise
*/</span>
removeListener: <span class="reserved">function</span>(el, sType, fn, index) {
<span class="reserved">if</span> (!fn || !fn.call) {
<span class="comment"> // this.logger.debug("Error, function is not valid " + fn);</span>
<span class="reserved">return</span> false;
}
<span class="comment">
// The el argument can be a string</span>
<span class="reserved">if</span> (typeof el == <span class="literal">"string"</span>) {
el = <span class="reserved">this</span>.getEl(el);
<span class="comment"> // The el argument can be an array of elements or element ids.</span>
} <span class="reserved">else</span> <span class="reserved">if</span> ( <span class="reserved">this</span>._isValidCollection(el)) {
var ok = true;
<span class="reserved">for</span> (var i=0,len=el.length; i&lt;len; ++i) {
ok = ( <span class="reserved">this</span>.removeListener(el[i], sType, fn) &amp;&amp; ok );
}
<span class="reserved">return</span> ok;
}
<span class="reserved">if</span> (<span class="literal">"unload"</span> == sType) {
<span class="reserved">for</span> (i=0, len=unloadListeners.length; i&lt;len; i++) {
var li = unloadListeners[i];
<span class="reserved">if</span> (li &amp;&amp;
li[0] == el &amp;&amp;
li[1] == sType &amp;&amp;
li[2] == fn) {
delete unloadListeners[i];
<span class="reserved">return</span> true;
}
}
<span class="reserved">return</span> false;
}
var cacheItem = null;
<span class="reserved">if</span> (<span class="literal">"undefined"</span> == typeof index) {
index = <span class="reserved">this</span>._getCacheIndex(el, sType, fn);
}
<span class="reserved">if</span> (index &gt;= 0) {
cacheItem = listeners[index];
}
<span class="reserved">if</span> (!el || !cacheItem) {
<span class="comment"> // this.logger.debug("cached listener not found");</span>
<span class="reserved">return</span> false;
}
<span class="comment">
// this.logger.debug("Removing handler: " + el + ", " + sType);</span>
<span class="reserved">if</span> (el.removeEventListener) {
el.removeEventListener(sType, cacheItem[<span class="reserved">this</span>.WFN], false);
<span class="comment"> // this.logger.debug("adsf");</span>
} <span class="reserved">else</span> <span class="reserved">if</span> (el.detachEvent) {
el.detachEvent(<span class="literal">"on"</span> + sType, cacheItem[<span class="reserved">this</span>.WFN]);
}
<span class="comment">
// removed the wrapped handler</span>
delete listeners[index][<span class="reserved">this</span>.WFN];
delete listeners[index][<span class="reserved">this</span>.FN];
delete listeners[index];
<span class="reserved">return</span> true;
},
<span class="comment">/**
* Returns the event's target element
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@param</span> {boolean} resolveTextNode when set to true the target's
* parent will be returned if the target is a
* text node. <span class="attrib">@deprecated</span>, the text node is
* now resolved automatically
* <span class="attrib">@return</span> {HTMLElement} the event's target
*/</span>
getTarget: <span class="reserved">function</span>(ev, resolveTextNode) {
var t = ev.target || ev.srcElement;
<span class="reserved">return</span> <span class="reserved">this</span>.resolveTextNode(t);
},
<span class="comment">/**
* In some cases, some browsers will return a text node inside
* the actual element that was targeted. This normalizes the
* return value for getTarget and getRelatedTarget.
* <span class="attrib">@param</span> {HTMLElement} node to resolve
* <span class="attrib">@return</span> the normized node
*/</span>
resolveTextNode: <span class="reserved">function</span>(node) {
<span class="reserved">if</span> (node &amp;&amp; node.nodeName &amp;&amp;
<span class="literal">"#TEXT"</span> == node.nodeName.toUpperCase()) {
<span class="reserved">return</span> node.parentNode;
} <span class="reserved">else</span> {
<span class="reserved">return</span> node;
}
},
<span class="comment">/**
* Returns the event's pageX
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@return</span> {int} the event's pageX
*/</span>
getPageX: <span class="reserved">function</span>(ev) {
var x = ev.pageX;
<span class="reserved">if</span> (!x &amp;&amp; 0 !== x) {
x = ev.clientX || 0;
<span class="reserved">if</span> ( <span class="reserved">this</span>.isIE ) {
x += <span class="reserved">this</span>._getScrollLeft();
}
}
<span class="reserved">return</span> x;
},
<span class="comment">/**
* Returns the event's pageY
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@return</span> {int} the event's pageY
*/</span>
getPageY: <span class="reserved">function</span>(ev) {
var y = ev.pageY;
<span class="reserved">if</span> (!y &amp;&amp; 0 !== y) {
y = ev.clientY || 0;
<span class="reserved">if</span> ( <span class="reserved">this</span>.isIE ) {
y += <span class="reserved">this</span>._getScrollTop();
}
}
<span class="reserved">return</span> y;
},
<span class="comment">/**
* Returns the pageX and pageY properties as an indexed array.
* <span class="attrib">@type</span> int[]
*/</span>
getXY: <span class="reserved">function</span>(ev) {
<span class="reserved">return</span> [<span class="reserved">this</span>.getPageX(ev), <span class="reserved">this</span>.getPageY(ev)];
},
<span class="comment">/**
* Returns the event's related target
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@return</span> {HTMLElement} the event's relatedTarget
*/</span>
getRelatedTarget: <span class="reserved">function</span>(ev) {
var t = ev.relatedTarget;
<span class="reserved">if</span> (!t) {
<span class="reserved">if</span> (ev.type == <span class="literal">"mouseout"</span>) {
t = ev.toElement;
} <span class="reserved">else</span> <span class="reserved">if</span> (ev.type == <span class="literal">"mouseover"</span>) {
t = ev.fromElement;
}
}
<span class="reserved">return</span> <span class="reserved">this</span>.resolveTextNode(t);
},
<span class="comment">/**
* Returns the time of the event. If the time is not included, the
* event is modified using the current time.
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@return</span> {Date} the time of the event
*/</span>
getTime: <span class="reserved">function</span>(ev) {
<span class="reserved">if</span> (!ev.time) {
var t = new Date().getTime();
try {
ev.time = t;
} catch(e) {
<span class="comment"> // can't set the time property </span>
<span class="reserved">return</span> t;
}
}
<span class="reserved">return</span> ev.time;
},
<span class="comment">/**
* Convenience method for stopPropagation + preventDefault
* <span class="attrib">@param</span> {Event} ev the event
*/</span>
stopEvent: <span class="reserved">function</span>(ev) {
<span class="reserved">this</span>.stopPropagation(ev);
<span class="reserved">this</span>.preventDefault(ev);
},
<span class="comment">/**
* Stops event propagation
* <span class="attrib">@param</span> {Event} ev the event
*/</span>
stopPropagation: <span class="reserved">function</span>(ev) {
<span class="reserved">if</span> (ev.stopPropagation) {
ev.stopPropagation();
} <span class="reserved">else</span> {
ev.cancelBubble = true;
}
},
<span class="comment">/**
* Prevents the default behavior of the event
* <span class="attrib">@param</span> {Event} ev the event
*/</span>
preventDefault: <span class="reserved">function</span>(ev) {
<span class="reserved">if</span> (ev.preventDefault) {
ev.preventDefault();
} <span class="reserved">else</span> {
ev.returnValue = false;
}
},
<span class="comment">/**
* Finds the event in the window object, the caller's arguments, or
* in the arguments of another method in the callstack. This is
* executed automatically for events registered through the event
* manager, so the implementer should not normally need to execute
* this function at all.
* <span class="attrib">@param</span> {Event} the event parameter from the handler
* <span class="attrib">@return</span> {Event} the event
*/</span>
getEvent: <span class="reserved">function</span>(e) {
var ev = e || window.event;
<span class="reserved">if</span> (!ev) {
var c = <span class="reserved">this</span>.getEvent.caller;
<span class="reserved">while</span> (c) {
ev = c.arguments[0];
<span class="reserved">if</span> (ev &amp;&amp; Event == ev.constructor) {
break;
}
c = c.caller;
}
}
<span class="reserved">return</span> ev;
},
<span class="comment">/**
* Returns the charcode for an event
* <span class="attrib">@param</span> {Event} ev the event
* <span class="attrib">@return</span> {int} the event's charCode
*/</span>
getCharCode: <span class="reserved">function</span>(ev) {
<span class="reserved">return</span> ev.charCode || ((ev.type == <span class="literal">"keypress"</span>) ? ev.keyCode : 0);
},
<span class="comment">/**
* Generates an unique ID for the element if it does not already
* have one.
* <span class="attrib">@param</span> el the element
* <span class="attrib">@return</span> {string} the id of the element
*/</span>
generateId: <span class="reserved">function</span>(el) {
var id = el.id;
<span class="reserved">if</span> (!id) {
id = <span class="literal">"yuievtautoid-"</span> + counter;
++counter;
el.id = id;
}
<span class="reserved">return</span> id;
},
<span class="comment">/**
* Removes all listeners attached to the given element via addListener.
* Optionally, the node's children can also be purged.
* Optionally, you can specify a specific type of event to remove.
* <span class="attrib">@param</span> {HTMLElement} el the element to purge
* <span class="attrib">@param</span> {boolean} recurse recursively purge this element's children
* as well. Use with caution.
* <span class="attrib">@param</span> {string} sType optional type of listener to purge. If
* left out, all listeners will be removed
*/</span>
purgeElement: <span class="reserved">function</span>(el, recurse, sType) {
var elListeners = <span class="reserved">this</span>.getListeners(el, sType);
<span class="reserved">if</span> (elListeners) {
<span class="reserved">for</span> (var i=0,len=elListeners.length; i&lt;len ; ++i) {
var l = elListeners[i];
<span class="reserved">this</span>.removeListener(el, l.type, l.fn, l.index);
}
}
<span class="reserved">if</span> (recurse &amp;&amp; el &amp;&amp; el.childNodes) {
<span class="reserved">for</span> (i=0,len=el.childNodes.length; i&lt;len ; ++i) {
<span class="reserved">this</span>.purgeElement(el.childNodes[i], recurse, sType);
}
}
},
<span class="comment">/**
* Returns all listeners attached to the given element via addListener.
* Optionally, you can specify a specific type of event to return.
* <span class="attrib">@param</span> el {HTMLElement} the element to inspect
* <span class="attrib">@param</span> sType {string} optional type of listener to return. If
* left out, all listeners will be returned
* <span class="attrib">@return</span> {Object} the listener. Contains the following fields:
* type: (string) the type of event
* fn: (function) the callback supplied to addListener
* obj: (object) the custom object supplied to addListener
* adjust: (boolean) whether or not to adjust the default scope
* index: (int) its position in the Event util listener cache
*/</span>
getListeners: <span class="reserved">function</span>(el, sType) {
var elListeners = [];
<span class="reserved">if</span> (listeners &amp;&amp; listeners.length &gt; 0) {
<span class="reserved">for</span> (var i=0,len=listeners.length; i&lt;len ; ++i) {
var l = listeners[i];
<span class="reserved">if</span> ( l &amp;&amp; l[<span class="reserved">this</span>.EL] === el &amp;&amp;
(!sType || sType === l[<span class="reserved">this</span>.TYPE]) ) {
elListeners.push({
type: l[<span class="reserved">this</span>.TYPE],
fn: l[<span class="reserved">this</span>.FN],
obj: l[<span class="reserved">this</span>.SCOPE],
adjust: l[<span class="reserved">this</span>.ADJ_SCOPE],
index: i
});
}
}
}
<span class="reserved">return</span> (elListeners.length) ? elListeners : null;
},
<span class="comment">/**
* Removes all listeners registered by pe.event. Called
* automatically during the unload event.
* <span class="attrib">@private</span>
*/</span>
_unload: <span class="reserved">function</span>(e, me) {
<span class="reserved">for</span> (var i=0,len=unloadListeners.length; i&lt;len; ++i) {
var l = unloadListeners[i];
<span class="reserved">if</span> (l) {
var scope = (l[<span class="reserved">this</span>.ADJ_SCOPE]) ? l[<span class="reserved">this</span>.SCOPE]: window;
l[<span class="reserved">this</span>.FN].call(scope, <span class="reserved">this</span>.getEvent(e), l[<span class="reserved">this</span>.SCOPE] );
}
}
<span class="reserved">if</span> (listeners &amp;&amp; listeners.length &gt; 0) {
<span class="reserved">for</span> (i=0,len=listeners.length; i&lt;len ; ++i) {
l = listeners[i];
<span class="reserved">if</span> (l) {
<span class="reserved">this</span>.removeListener(l[<span class="reserved">this</span>.EL], l[<span class="reserved">this</span>.TYPE],
l[<span class="reserved">this</span>.FN], i);
}
}
<span class="reserved">this</span>.clearCache();
}
<span class="reserved">for</span> (i=0,len=customEvents.length; i&lt;len; ++i) {
customEvents[i].unsubscribeAll();
delete customEvents[i];
}
<span class="reserved">for</span> (i=0,len=legacyEvents.length; i&lt;len; ++i) {
<span class="comment"> // dereference the element</span>
delete legacyEvents[i][0];
<span class="comment"> // delete the array item</span>
delete legacyEvents[i];
}
},
<span class="comment">/**
* Returns scrollLeft
* <span class="attrib">@private</span>
*/</span>
_getScrollLeft: <span class="reserved">function</span>() {
<span class="reserved">return</span> <span class="reserved">this</span>._getScroll()[1];
},
<span class="comment">/**
* Returns scrollTop
* <span class="attrib">@private</span>
*/</span>
_getScrollTop: <span class="reserved">function</span>() {
<span class="reserved">return</span> <span class="reserved">this</span>._getScroll()[0];
},
<span class="comment">/**
* Returns the scrollTop and scrollLeft. Used to calculate the
* pageX and pageY in Internet Explorer
* <span class="attrib">@private</span>
*/</span>
_getScroll: <span class="reserved">function</span>() {
var dd = document.documentElement; db = document.body;
<span class="reserved">if</span> (dd &amp;&amp; dd.scrollTop) {
<span class="reserved">return</span> [dd.scrollTop, dd.scrollLeft];
} <span class="reserved">else</span> <span class="reserved">if</span> (db) {
<span class="reserved">return</span> [db.scrollTop, db.scrollLeft];
} <span class="reserved">else</span> {
<span class="reserved">return</span> [0, 0];
}
}
};
} ();
<span class="comment">/**
* <span class="attrib">@private</span>
*/</span>
YAHOO.util.Event.on = YAHOO.util.Event.addListener;
<span class="reserved">if</span> (document &amp;&amp; document.body) {
YAHOO.util.Event._load();
} <span class="reserved">else</span> {
YAHOO.util.Event.on(window, <span class="literal">"load"</span>, YAHOO.util.Event._load,
YAHOO.util.Event, true);
}
YAHOO.util.Event.on(window, <span class="literal">"unload"</span>, YAHOO.util.Event._unload,
YAHOO.util.Event, true);
YAHOO.util.Event._tryPreloadAttach();
}
</pre>
</div>
</div>
</div>
<div id="footer">
<hr />
Copyright &copy; 2004 - 2006 Yahoo! Inc. All rights reserved.
</div>
</body>
</html>