3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">Ext.lib.Event = function() {
10 var loadComplete = false,
28 SCROLLLEFT = 'scrollLeft',
29 SCROLLTOP = 'scrollTop',
31 MOUSEOVER = 'mouseover',
32 MOUSEOUT = 'mouseout',
36 if (win.addEventListener) {
37 ret = function(el, eventName, fn, capture) {
38 if (eventName == 'mouseenter') {
39 fn = fn.createInterceptor(checkRelatedTarget);
40 el.addEventListener(MOUSEOVER, fn, (capture));
41 } else if (eventName == 'mouseleave') {
42 fn = fn.createInterceptor(checkRelatedTarget);
43 el.addEventListener(MOUSEOUT, fn, (capture));
45 el.addEventListener(eventName, fn, (capture));
49 } else if (win.attachEvent) {
50 ret = function(el, eventName, fn, capture) {
51 el.attachEvent("on" + eventName, fn);
60 doRemove = function(){
62 if (win.removeEventListener) {
63 ret = function (el, eventName, fn, capture) {
64 if (eventName == 'mouseenter') {
65 eventName = MOUSEOVER;
66 } else if (eventName == 'mouseleave') {
69 el.removeEventListener(eventName, fn, (capture));
71 } else if (win.detachEvent) {
72 ret = function (el, eventName, fn) {
73 el.detachEvent("on" + eventName, fn);
81 function checkRelatedTarget(e) {
82 return !elContains(e.currentTarget, pub.getRelatedTarget(e));
85 function elContains(parent, child) {
86 if(parent && parent.firstChild){
88 if(child === parent) {
91 child = child.parentNode;
92 if(child && (child.nodeType != 1)) {
101 function _tryPreloadAttach() {
105 tryAgain = !loadComplete || (retryCount > 0);
110 for (i = 0, len = onAvailStack.length; i < len; i++) {
112 if(v && (element = doc.getElementById(v.id))){
113 if(!v.checkReady || loadComplete || element.nextSibling || (doc && doc.body)) {
114 element = v.override ? (v.override === true ? v.obj : v.override) : element;
115 v.fn.call(element, v.obj);
123 retryCount = (notAvail.length === 0) ? 0 : retryCount - 1;
128 clearInterval(_interval);
132 ret = !(locked = false);
138 function startInterval() {
140 var callback = function() {
143 _interval = setInterval(callback, POLL_INTERVAL);
148 function getScroll() {
149 var dd = doc.documentElement,
151 if(dd && (dd[SCROLLTOP] || dd[SCROLLLEFT])){
152 return [dd[SCROLLLEFT], dd[SCROLLTOP]];
154 return [db[SCROLLLEFT], db[SCROLLTOP]];
161 function getPageCoord (ev, xy) {
162 ev = ev.browserEvent || ev;
163 var coord = ev['page' + xy];
164 if (!coord && coord !== 0) {
165 coord = ev['client' + xy] || 0;
168 coord += getScroll()[xy == "X" ? 0 : 1];
177 onAvailable : function(p_id, p_fn, p_obj, p_override) {
182 override: p_override,
183 checkReady: false });
185 retryCount = POLL_RETRYS;
189 // This function should ALWAYS be called from Ext.EventManager
190 addListener: function(el, eventName, fn) {
193 if (eventName == UNLOAD) {
194 if (unloadListeners[el.id] === undefined) {
195 unloadListeners[el.id] = [];
197 unloadListeners[el.id].push([eventName, fn]);
200 return doAdd(el, eventName, fn, false);
205 // This function should ALWAYS be called from Ext.EventManager
206 removeListener: function(el, eventName, fn) {
210 if (eventName == UNLOAD) {
211 if (unloadListeners[id] !== undefined) {
212 for (i = 0, len = unloadListeners[id].length; i < len; i++) {
213 li = unloadListeners[id][i];
214 if (li && li[TYPE] == eventName && li[FN] == fn) {
215 unloadListeners[id].splice(i, 1);
221 doRemove(el, eventName, fn, false);
225 getTarget : function(ev) {
226 ev = ev.browserEvent || ev;
227 return this.resolveTextNode(ev.target || ev.srcElement);
230 resolveTextNode : Ext.isGecko ? function(node){
234 // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
235 var s = HTMLElement.prototype.toString.call(node);
236 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
239 return node.nodeType == 3 ? node.parentNode : node;
241 return node && node.nodeType == 3 ? node.parentNode : node;
244 getRelatedTarget : function(ev) {
245 ev = ev.browserEvent || ev;
246 return this.resolveTextNode(ev.relatedTarget ||
247 (ev.type == MOUSEOUT ? ev.toElement :
248 ev.type == MOUSEOVER ? ev.fromElement : null));
251 getPageX : function(ev) {
252 return getPageCoord(ev, "X");
255 getPageY : function(ev) {
256 return getPageCoord(ev, "Y");
260 getXY : function(ev) {
261 return [this.getPageX(ev), this.getPageY(ev)];
264 stopEvent : function(ev) {
265 this.stopPropagation(ev);
266 this.preventDefault(ev);
269 stopPropagation : function(ev) {
270 ev = ev.browserEvent || ev;
271 if (ev.stopPropagation) {
272 ev.stopPropagation();
274 ev.cancelBubble = true;
278 preventDefault : function(ev) {
279 ev = ev.browserEvent || ev;
280 if (ev.preventDefault) {
283 ev.returnValue = false;
287 getEvent : function(e) {
290 var c = this.getEvent.caller;
293 if (e && Event == e.constructor) {
302 getCharCode : function(ev) {
303 ev = ev.browserEvent || ev;
304 return ev.charCode || ev.keyCode || 0;
307 //clearCache: function() {},
308 // deprecated, call from EventManager
309 getListeners : function(el, eventName) {
310 Ext.EventManager.getListeners(el, eventName);
313 // deprecated, call from EventManager
314 purgeElement : function(el, recurse, eventName) {
315 Ext.EventManager.purgeElement(el, recurse, eventName);
318 _load : function(e) {
320 var EU = Ext.lib.Event;
321 if (Ext.isIE && e !== true) {
322 // IE8 complains that _load is null or not an object
323 // so lets remove self via arguments.callee
324 doRemove(win, "load", arguments.callee);
328 _unload : function(e) {
329 var EU = Ext.lib.Event,
330 i, j, l, v, ul, id, len, index, scope;
333 for (id in unloadListeners) {
334 ul = unloadListeners[id];
335 for (i = 0, len = ul.length; i < len; i++) {
339 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
340 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
346 unloadListeners = null;
347 Ext.EventManager._unload();
349 doRemove(win, UNLOAD, EU._unload);
354 pub.on = pub.addListener;
355 pub.un = pub.removeListener;
356 if (doc && doc.body) {
359 doAdd(win, "load", pub._load);
361 doAdd(win, UNLOAD, pub._unload);