]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/event/event-base-ie.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / event / event-base-ie.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 (function() {
9
10 var stateChangeListener,
11     GLOBAL_ENV   = YUI.Env,
12     config       = YUI.config,
13     doc          = config.doc,
14     docElement   = doc && doc.documentElement,
15     EVENT_NAME   = 'onreadystatechange',
16     pollInterval = config.pollInterval || 40;
17
18 if (docElement.doScroll && !GLOBAL_ENV._ieready) {
19     GLOBAL_ENV._ieready = function() {
20         GLOBAL_ENV._ready();
21     };
22
23 /*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller/Diego Perini */
24 // Internet Explorer: use the doScroll() method on the root element.
25 // This isolates what appears to be a safe moment to manipulate the
26 // DOM prior to when the document's readyState suggests it is safe to do so.
27     if (self !== self.top) {
28         stateChangeListener = function() {
29             if (doc.readyState == 'complete') {
30                 GLOBAL_ENV.remove(doc, EVENT_NAME, stateChangeListener);
31                 GLOBAL_ENV.ieready();
32             }
33         };
34         GLOBAL_ENV.add(doc, EVENT_NAME, stateChangeListener);
35     } else {
36         GLOBAL_ENV._dri = setInterval(function() {
37             try {
38                 docElement.doScroll('left');
39                 clearInterval(GLOBAL_ENV._dri);
40                 GLOBAL_ENV._dri = null;
41                 GLOBAL_ENV._ieready();
42             } catch (domNotReady) { }
43         }, pollInterval);
44     }
45 }
46
47 })();
48 YUI.add('event-base-ie', function(Y) {
49
50 /*
51  * Custom event engine, DOM event listener abstraction layer, synthetic DOM
52  * events.
53  * @module event
54  * @submodule event-base
55  */
56
57 var IEEventFacade = function() {
58         // IEEventFacade.superclass.constructor.apply(this, arguments);
59         Y.DOM2EventFacade.apply(this, arguments);
60     };
61
62 Y.extend(IEEventFacade, Y.DOM2EventFacade, {
63
64     init: function() {
65
66         IEEventFacade.superclass.init.apply(this, arguments);
67
68         var e = this._event,
69             resolve = Y.DOM2EventFacade.resolve,
70             x, y, d, b, de, t;
71
72         this.target = resolve(e.srcElement);
73
74         if (('clientX' in e) && (!x) && (0 !== x)) {
75             x = e.clientX;
76             y = e.clientY;
77
78             d = Y.config.doc;
79             b = d.body;
80             de = d.documentElement;
81
82             x += (de.scrollLeft || (b && b.scrollLeft) || 0);
83             y += (de.scrollTop  || (b && b.scrollTop)  || 0);
84
85             this.pageX = x;
86             this.pageY = y;
87         }
88
89         if (e.type == "mouseout") {
90             t = e.toElement;
91         } else if (e.type == "mouseover") {
92             t = e.fromElement;
93         }
94
95         this.relatedTarget = resolve(t);
96
97         // which should contain the unicode key code if this is a key event
98         // if (e.charCode) {
99         //     this.which = e.charCode;
100         // }
101
102         // for click events, which is normalized for which mouse button was
103         // clicked.
104         if (e.button) {
105             switch (e.button) {
106                 case 2:
107                     this.which = 3;
108                     break;
109                 case 4:
110                     this.which = 2;
111                     break;
112                 default:
113                     this.which = e.button;
114             }
115
116             this.button = this.which;
117         }
118
119     },
120
121     stopPropagation: function() {
122         var e = this._event;
123         e.cancelBubble = true;
124         this._wrapper.stopped = 1;
125         this.stopped = 1;
126     },
127
128     stopImmediatePropagation: function() {
129         this.stopPropagation();
130         this._wrapper.stopped = 2;
131         this.stopped = 2;
132     },
133
134     preventDefault: function(returnValue) {
135         this._event.returnValue = returnValue || false;
136         this._wrapper.prevented = 1;
137         this.prevented = 1;
138     }
139
140 });
141
142 var imp = Y.config.doc && Y.config.doc.implementation;
143
144 if (imp && (!imp.hasFeature('Events', '2.0'))) {
145     Y.DOMEventFacade = IEEventFacade;
146 }
147
148
149
150 }, '3.3.0' );