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);
116 onAvailStack.remove(v);
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((lis = unloadListeners[el.id]) !== undefined){
212 for(i = 0, len = lis.length; i < len; i++){
213 if((li = lis[i]) && li[TYPE] == eventName && li[FN] == fn){
214 unloadListeners[el.id].splice(i, 1);
220 doRemove(el, eventName, fn, false);
224 getTarget : function(ev) {
225 ev = ev.browserEvent || ev;
226 return this.resolveTextNode(ev.target || ev.srcElement);
229 resolveTextNode : Ext.isGecko ? function(node){
233 // work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
234 var s = HTMLElement.prototype.toString.call(node);
235 if(s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]'){
238 return node.nodeType == 3 ? node.parentNode : node;
240 return node && node.nodeType == 3 ? node.parentNode : node;
243 getRelatedTarget : function(ev) {
244 ev = ev.browserEvent || ev;
245 return this.resolveTextNode(ev.relatedTarget ||
246 (ev.type == MOUSEOUT ? ev.toElement :
247 ev.type == MOUSEOVER ? ev.fromElement : null));
250 getPageX : function(ev) {
251 return getPageCoord(ev, "X");
254 getPageY : function(ev) {
255 return getPageCoord(ev, "Y");
259 getXY : function(ev) {
260 return [this.getPageX(ev), this.getPageY(ev)];
263 stopEvent : function(ev) {
264 this.stopPropagation(ev);
265 this.preventDefault(ev);
268 stopPropagation : function(ev) {
269 ev = ev.browserEvent || ev;
270 if (ev.stopPropagation) {
271 ev.stopPropagation();
273 ev.cancelBubble = true;
277 preventDefault : function(ev) {
278 ev = ev.browserEvent || ev;
279 if (ev.preventDefault) {
282 ev.returnValue = false;
286 getEvent : function(e) {
289 var c = this.getEvent.caller;
292 if (e && Event == e.constructor) {
301 getCharCode : function(ev) {
302 ev = ev.browserEvent || ev;
303 return ev.charCode || ev.keyCode || 0;
306 //clearCache: function() {},
307 // deprecated, call from EventManager
308 getListeners : function(el, eventName) {
309 Ext.EventManager.getListeners(el, eventName);
312 // deprecated, call from EventManager
313 purgeElement : function(el, recurse, eventName) {
314 Ext.EventManager.purgeElement(el, recurse, eventName);
317 _load : function(e) {
319 var EU = Ext.lib.Event;
320 if (Ext.isIE && e !== true) {
321 // IE8 complains that _load is null or not an object
322 // so lets remove self via arguments.callee
323 doRemove(win, "load", arguments.callee);
327 _unload : function(e) {
328 var EU = Ext.lib.Event,
329 i, j, l, v, ul, id, len, index, scope;
332 for (id in unloadListeners) {
333 ul = unloadListeners[id];
334 for (i = 0, len = ul.length; i < len; i++) {
338 scope = v[ADJ_SCOPE] ? (v[ADJ_SCOPE] === true ? v[OBJ] : v[ADJ_SCOPE]) : win;
339 v[FN].call(scope, EU.getEvent(e), v[OBJ]);
345 unloadListeners = null;
346 Ext.EventManager._unload();
348 doRemove(win, UNLOAD, EU._unload);
353 pub.on = pub.addListener;
354 pub.un = pub.removeListener;
355 if (doc && doc.body) {
358 doAdd(win, "load", pub._load);
360 doAdd(win, UNLOAD, pub._unload);