3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
9 var stateChangeListener,
13 docElement = doc && doc.documentElement,
14 EVENT_NAME = 'onreadystatechange',
15 pollInterval = config.pollInterval || 40;
17 if (docElement.doScroll && !GLOBAL_ENV._ieready) {
18 GLOBAL_ENV._ieready = function() {
22 /*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller/Diego Perini */
23 // Internet Explorer: use the doScroll() method on the root element.
24 // This isolates what appears to be a safe moment to manipulate the
25 // DOM prior to when the document's readyState suggests it is safe to do so.
26 if (self !== self.top) {
27 stateChangeListener = function() {
28 if (doc.readyState == 'complete') {
29 GLOBAL_ENV.remove(doc, EVENT_NAME, stateChangeListener);
33 GLOBAL_ENV.add(doc, EVENT_NAME, stateChangeListener);
35 GLOBAL_ENV._dri = setInterval(function() {
37 docElement.doScroll('left');
38 clearInterval(GLOBAL_ENV._dri);
39 GLOBAL_ENV._dri = null;
40 GLOBAL_ENV._ieready();
41 } catch (domNotReady) { }
47 YUI.add('event-base-ie', function (Y, NAME) {
50 * Custom event engine, DOM event listener abstraction layer, synthetic DOM
53 * @submodule event-base
56 function IEEventFacade() {
57 // IEEventFacade.superclass.constructor.apply(this, arguments);
58 Y.DOM2EventFacade.apply(this, arguments);
62 * (intentially left out of API docs)
63 * Alternate Facade implementation that is based on Object.defineProperty, which
64 * is partially supported in IE8. Properties that involve setup work are
65 * deferred to temporary getters using the static _define method.
67 function IELazyFacade(e) {
68 var proxy = Y.config.doc.createEventObject(e),
69 proto = IELazyFacade.prototype;
72 proxy.hasOwnProperty = function () { return true; };
74 proxy.init = proto.init;
75 proxy.halt = proto.halt;
76 proxy.preventDefault = proto.preventDefault;
77 proxy.stopPropagation = proto.stopPropagation;
78 proxy.stopImmediatePropagation = proto.stopImmediatePropagation;
80 Y.DOM2EventFacade.apply(proxy, arguments);
86 var imp = Y.config.doc && Y.config.doc.implementation,
87 useLazyFacade = Y.config.lazyEventFacade,
95 mouseout: 'toElement',
96 mouseover: 'fromElement'
99 resolve = Y.DOM2EventFacade.resolve,
104 IEEventFacade.superclass.init.apply(this, arguments);
109 this.target = resolve(e.srcElement);
111 if (('clientX' in e) && (!x) && (0 !== x)) {
117 de = d.documentElement;
119 x += (de.scrollLeft || (b && b.scrollLeft) || 0);
120 y += (de.scrollTop || (b && b.scrollTop) || 0);
126 if (e.type == "mouseout") {
128 } else if (e.type == "mouseover") {
132 // fallback to t.relatedTarget to support simulated events.
133 // IE doesn't support setting toElement or fromElement on generic
134 // events, so Y.Event.simulate sets relatedTarget instead.
135 this.relatedTarget = resolve(t || e.relatedTarget);
137 // which should contain the unicode key code if this is a key event.
138 // For click events, which is normalized for which mouse button was
140 this.which = // chained assignment
141 this.button = e.keyCode || buttonMap[e.button] || e.button;
144 stopPropagation: function() {
145 this._event.cancelBubble = true;
146 this._wrapper.stopped = 1;
150 stopImmediatePropagation: function() {
151 this.stopPropagation();
152 this._wrapper.stopped = 2;
156 preventDefault: function(returnValue) {
157 this._event.returnValue = returnValue || false;
158 this._wrapper.prevented = 1;
163 Y.extend(IEEventFacade, Y.DOM2EventFacade, proto);
165 Y.extend(IELazyFacade, Y.DOM2EventFacade, proto);
166 IELazyFacade.prototype.init = function () {
168 overrides = this._wrapper.overrides,
169 define = IELazyFacade._define,
170 lazyProperties = IELazyFacade._lazyProperties,
173 this.altKey = e.altKey;
174 this.ctrlKey = e.ctrlKey;
175 this.metaKey = e.metaKey;
176 this.shiftKey = e.shiftKey;
177 this.type = (overrides && overrides.type) || e.type;
178 this.clientX = e.clientX;
179 this.clientY = e.clientY;
180 this.keyCode = // chained assignment
181 this.charCode = e.keyCode;
182 this.which = // chained assignment
183 this.button = e.keyCode || buttonMap[e.button] || e.button;
185 for (prop in lazyProperties) {
186 if (lazyProperties.hasOwnProperty(prop)) {
187 define(this, prop, lazyProperties[prop]);
192 this._touch(e, this._currentTarget, this._wrapper);
196 IELazyFacade._lazyProperties = {
197 target: function () {
198 return resolve(this._event.srcElement);
200 relatedTarget: function () {
202 targetProp = relatedTargetMap[e.type] || 'relatedTarget';
204 // fallback to t.relatedTarget to support simulated events.
205 // IE doesn't support setting toElement or fromElement on generic
206 // events, so Y.Event.simulate sets relatedTarget instead.
207 return resolve(e[targetProp] || e.relatedTarget);
209 currentTarget: function () {
210 return resolve(this._currentTarget);
213 wheelDelta: function () {
216 if (e.type === "mousewheel" || e.type === "DOMMouseScroll") {
219 // wheelDelta between -80 and 80 result in -1 or 1
220 Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
227 doc, bodyScroll, docScroll;
229 if (val === undefined) {
231 bodyScroll = doc.body && doc.body.scrollLeft;
232 docScroll = doc.documentElement.scrollLeft;
234 val = e.clientX + (docScroll || bodyScroll || 0);
242 doc, bodyScroll, docScroll;
244 if (val === undefined) {
246 bodyScroll = doc.body && doc.body.scrollTop;
247 docScroll = doc.documentElement.scrollTop;
249 val = e.clientY + (docScroll || bodyScroll || 0);
258 * Wrapper function for Object.defineProperty that creates a property whose
259 * value will be calulated only when asked for. After calculating the value,
260 * the getter wll be removed, so it will behave as a normal property beyond that
261 * point. A setter is also assigned so assigning to the property will clear
262 * the getter, so foo.prop = 'a'; foo.prop; won't trigger the getter,
263 * overwriting value 'a'.
265 * Used only by the DOMEventFacades used by IE8 when the YUI configuration
266 * <code>lazyEventFacade</code> is set to true.
269 * @param o {DOMObject} A DOM object to add the property to
270 * @param prop {String} The name of the new property
271 * @param valueFn {Function} The function that will return the initial, default
272 * value for the property.
276 IELazyFacade._define = function (o, prop, valueFn) {
278 var ret = (arguments.length) ? v : valueFn.call(this);
281 Object.defineProperty(o, prop, {
288 Object.defineProperty(o, prop, {
295 if (imp && (!imp.hasFeature('Events', '2.0'))) {
297 // Make sure we can use the lazy facade logic
299 Object.defineProperty(Y.config.doc.createEventObject(), 'z', {});
301 useLazyFacade = false;
305 Y.DOMEventFacade = (useLazyFacade) ? IELazyFacade : IEEventFacade;
309 }, '3.7.1', {"requires": ["node-base"]});