3
Copyright 2011 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) {
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
139
// this.which = e.charCode;
142
// for click events, which is normalized for which mouse button was
144
if (e.button !== undefined) {
145
this.which = this.button = buttonMap[e.button] || e.button;
150
stopPropagation: function() {
151
this._event.cancelBubble = true;
152
this._wrapper.stopped = 1;
156
stopImmediatePropagation: function() {
157
this.stopPropagation();
158
this._wrapper.stopped = 2;
162
preventDefault: function(returnValue) {
163
this._event.returnValue = returnValue || false;
164
this._wrapper.prevented = 1;
169
Y.extend(IEEventFacade, Y.DOM2EventFacade, proto);
171
Y.extend(IELazyFacade, Y.DOM2EventFacade, proto);
172
IELazyFacade.prototype.init = function () {
174
overrides = this._wrapper.overrides,
175
define = IELazyFacade._define,
176
lazyProperties = IELazyFacade._lazyProperties,
179
this.altKey = e.altKey;
180
this.ctrlKey = e.ctrlKey;
181
this.metaKey = e.metaKey;
182
this.shiftKey = e.shiftKey;
183
this.type = (overrides && overrides.type) || e.type;
184
this.clientX = e.clientX;
185
this.clientY = e.clientY;
187
for (prop in lazyProperties) {
188
if (lazyProperties.hasOwnProperty(prop)) {
189
define(this, prop, lazyProperties[prop]);
194
this._touch(e, this._currentTarget, this._wrapper);
198
IELazyFacade._lazyProperties = {
199
charCode: function () {
202
return e.keyCode || e.charCode;
204
keyCode: function () { return this.charCode; },
206
button: function () {
209
return (e.button !== undefined) ?
210
(buttonMap[e.button] || e.button) :
211
(e.which || e.charCode || this.charCode);
213
which: function () { return this.button; },
215
target: function () {
216
return resolve(this._event.srcElement);
218
relatedTarget: function () {
220
targetProp = relatedTargetMap[e.type] || 'relatedTarget';
222
// fallback to t.relatedTarget to support simulated events.
223
// IE doesn't support setting toElement or fromElement on generic
224
// events, so Y.Event.simulate sets relatedTarget instead.
225
return resolve(e[targetProp] || e.relatedTarget);
227
currentTarget: function () {
228
return resolve(this._currentTarget);
231
wheelDelta: function () {
234
if (e.type === "mousewheel" || e.type === "DOMMouseScroll") {
237
// wheelDelta between -80 and 80 result in -1 or 1
238
Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
245
doc, bodyScroll, docScroll;
247
if (val === undefined) {
249
bodyScroll = doc.body && doc.body.scrollLeft;
250
docScroll = doc.documentElement.scrollLeft;
252
val = e.clientX + (docScroll || bodyScroll || 0);
260
doc, bodyScroll, docScroll;
262
if (val === undefined) {
264
bodyScroll = doc.body && doc.body.scrollTop;
265
docScroll = doc.documentElement.scrollTop;
267
val = e.clientY + (docScroll || bodyScroll || 0);
276
* Wrapper function for Object.defineProperty that creates a property whose
277
* value will be calulated only when asked for. After calculating the value,
278
* the getter wll be removed, so it will behave as a normal property beyond that
279
* point. A setter is also assigned so assigning to the property will clear
280
* the getter, so foo.prop = 'a'; foo.prop; won't trigger the getter,
281
* overwriting value 'a'.
283
* Used only by the DOMEventFacades used by IE8 when the YUI configuration
284
* <code>lazyEventFacade</code> is set to true.
287
* @param o {DOMObject} A DOM object to add the property to
288
* @param prop {String} The name of the new property
289
* @param valueFn {Function} The function that will return the initial, default
290
* value for the property.
294
IELazyFacade._define = function (o, prop, valueFn) {
296
var ret = (arguments.length) ? v : valueFn.call(this);
299
Object.defineProperty(o, prop, {
306
Object.defineProperty(o, prop, {
313
if (imp && (!imp.hasFeature('Events', '2.0'))) {
315
// Make sure we can use the lazy facade logic
317
Object.defineProperty(Y.config.doc.createEventObject(), 'z', {});
319
useLazyFacade = false;
323
Y.DOMEventFacade = (useLazyFacade) ? IELazyFacade : IEEventFacade;
327
}, '3.4.1' ,{after:['event-base'], requires:['node-base']});