Merge pull request #803 from spicyj/gh-788

Use proper window object for iframe in enter/leave
This commit is contained in:
Timothy Yung
2014-01-09 16:35:07 -08:00
2 changed files with 75 additions and 2 deletions
+11 -2
View File
@@ -81,14 +81,23 @@ var EnterLeaveEventPlugin = {
return null;
}
var win;
if (topLevelTarget != null && topLevelTarget.window === topLevelTarget) {
// topLevelTarget probably is a window object
win = topLevelTarget;
} else {
var doc = topLevelTarget.ownerDocument;
win = doc.defaultView || doc.parentWindow;
}
var from, to;
if (topLevelType === topLevelTypes.topMouseOut) {
from = topLevelTarget;
to =
getFirstReactDOM(nativeEvent.relatedTarget || nativeEvent.toElement) ||
window;
win;
} else {
from = window;
from = win;
to = topLevelTarget;
}
@@ -0,0 +1,64 @@
/**
* Copyright 2013 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @jsx React.DOM
* @emails react-core
*/
"use strict";
var EnterLeaveEventPlugin;
var EventConstants;
var React;
var ReactMount;
var topLevelTypes;
describe('EnterLeaveEventPlugin', function() {
beforeEach(function() {
require('mock-modules').dumpCache();
EnterLeaveEventPlugin = require('EnterLeaveEventPlugin');
EventConstants = require('EventConstants');
React = require('React');
ReactMount = require('ReactMount');
topLevelTypes = EventConstants.topLevelTypes;
});
it('should set relatedTarget properly in iframe', function() {
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var component = React.renderComponent(<div />, iframe.contentDocument.body);
var div = component.getDOMNode();
var extracted = EnterLeaveEventPlugin.extractEvents(
topLevelTypes.topMouseOver,
div,
ReactMount.getID(div),
{target: div}
);
expect(extracted.length).toBe(2);
var leave = extracted[0];
var enter = extracted[1];
expect(leave.target).toBe(iframe.contentWindow);
expect(leave.relatedTarget).toBe(div);
expect(enter.target).toBe(div);
expect(enter.relatedTarget).toBe(iframe.contentWindow);
});
});