Permalink
Browse files

Use Y.config.doc instead of a cached document reference.

This is related to ticket #2531223, which was fixed by caching a
reference to Y.config.doc when the module is attached to the YUI
instance.  This works fine most of the time, as long as the document
doesn't go away.  I am using this to run tests across a multi-page
experience, updating Y.config.doc to the new valid document along the
way -- so the cached reference doesn't work for me.
  • Loading branch information...
1 parent 5d8637f commit 03b866ec8ce21ab7bb72990ae95bbffc79ebbf2b @ClanMan ClanMan committed Jun 30, 2012
@@ -10,13 +10,11 @@ YUI.add('event-simulate', function(Y) {
//shortcuts
var L = Y.Lang,
- array = Y.Array,
isFunction = L.isFunction,
isString = L.isString,
isBoolean = L.isBoolean,
isObject = L.isObject,
isNumber = L.isNumber,
- doc = Y.config.doc,
//mouse events supported
mouseEvents = {
@@ -161,12 +159,12 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
try {
//try to create key event
- customEvent = doc.createEvent("KeyEvents");
+ customEvent = Y.config.doc.createEvent("KeyEvents");
/*
* Interesting problem: Firefox implemented a non-standard
@@ -194,12 +192,12 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
try {
//try to create generic event - will fail in Safari 2.x
- customEvent = doc.createEvent("Events");
+ customEvent = Y.config.doc.createEvent("Events");
} catch (uierror /*:Error*/){
//the above failed, so create a UIEvent for Safari 2.x
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
} finally {
@@ -221,10 +219,10 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
@@ -375,9 +373,9 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
- customEvent = doc.createEvent("MouseEvents");
+ customEvent = Y.config.doc.createEvent("MouseEvents");
//Safari 2.x (WebKit 418) still doesn't implement initMouseEvent()
if (customEvent.initMouseEvent){
@@ -388,7 +386,7 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
} else { //Safari
//the closest thing available in Safari 2.x is UIEvents
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initEvent(type, bubbles, cancelable);
customEvent.view = view;
customEvent.detail = detail;
@@ -424,10 +422,10 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
@@ -540,19 +538,19 @@ function simulateUIEvent(target /*:HTMLElement*/, type /*:String*/,
}
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
//just a generic UI Event object is needed
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initUIEvent(type, bubbles, cancelable, view, detail);
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
Oops, something went wrong.
@@ -10,13 +10,11 @@ YUI.add('event-simulate', function(Y) {
//shortcuts
var L = Y.Lang,
- array = Y.Array,
isFunction = L.isFunction,
isString = L.isString,
isBoolean = L.isBoolean,
isObject = L.isObject,
isNumber = L.isNumber,
- doc = Y.config.doc,
//mouse events supported
mouseEvents = {
@@ -161,12 +159,12 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
try {
//try to create key event
- customEvent = doc.createEvent("KeyEvents");
+ customEvent = Y.config.doc.createEvent("KeyEvents");
/*
* Interesting problem: Firefox implemented a non-standard
@@ -194,12 +192,12 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
try {
//try to create generic event - will fail in Safari 2.x
- customEvent = doc.createEvent("Events");
+ customEvent = Y.config.doc.createEvent("Events");
} catch (uierror /*:Error*/){
//the above failed, so create a UIEvent for Safari 2.x
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
} finally {
@@ -221,10 +219,10 @@ function simulateKeyEvent(target /*:HTMLElement*/, type /*:String*/,
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
@@ -375,9 +373,9 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
var customEvent /*:MouseEvent*/ = null;
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
- customEvent = doc.createEvent("MouseEvents");
+ customEvent = Y.config.doc.createEvent("MouseEvents");
//Safari 2.x (WebKit 418) still doesn't implement initMouseEvent()
if (customEvent.initMouseEvent){
@@ -388,7 +386,7 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
} else { //Safari
//the closest thing available in Safari 2.x is UIEvents
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initEvent(type, bubbles, cancelable);
customEvent.view = view;
customEvent.detail = detail;
@@ -424,10 +422,10 @@ function simulateMouseEvent(target /*:HTMLElement*/, type /*:String*/,
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
@@ -540,19 +538,19 @@ function simulateUIEvent(target /*:HTMLElement*/, type /*:String*/,
}
//check for DOM-compliant browsers first
- if (isFunction(doc.createEvent)){
+ if (isFunction(Y.config.doc.createEvent)){
//just a generic UI Event object is needed
- customEvent = doc.createEvent("UIEvents");
+ customEvent = Y.config.doc.createEvent("UIEvents");
customEvent.initUIEvent(type, bubbles, cancelable, view, detail);
//fire the event
target.dispatchEvent(customEvent);
- } else if (isObject(doc.createEventObject)){ //IE
+ } else if (isObject(Y.config.doc.createEventObject)){ //IE
//create an IE event object
- customEvent = doc.createEventObject();
+ customEvent = Y.config.doc.createEventObject();
//assign available properties
customEvent.bubbles = bubbles;
Oops, something went wrong.

0 comments on commit 03b866e

Please sign in to comment.