Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper window object for iframe in enter/leave #803

Merged
merged 1 commit into from
Jan 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/eventPlugins/EnterLeaveEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
64 changes: 64 additions & 0 deletions src/eventPlugins/__tests__/EnterLeaveEventPlugin-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});