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

mousemove event listener added to contentDocument when element is an iframe #38

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/hoverintent.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ module.exports = function(el, onOver, onOut) {
}
}

function addMouseMoveEventListener(element) {
const target = element.tagName.toLowerCase() === 'iframe' && element.contentDocument
? element.contentDocument
: element;

target.addEventListener('mousemove', tracker, false);
}

function removeMouseMoveEventListener(element) {
const target = element.tagName.toLowerCase() === 'iframe' && element.contentDocument
? element.contentDocument
: element;

target.removeEventListener('mousemove', tracker, false);
}

// Public methods
h.options = function(opt) {
var focusOptionChanged = opt.handleFocus !== options.handleFocus;
Expand All @@ -53,13 +69,13 @@ module.exports = function(el, onOver, onOut) {
function dispatchOver(e) {
mouseOver = true;
if (timer) timer = clearTimeout(timer);
el.removeEventListener('mousemove', tracker, false);
removeMouseMoveEventListener(el);

if (state !== 1) {
pX = e.clientX;
pY = e.clientY;

el.addEventListener('mousemove', tracker, false);
addMouseMoveEventListener(el);

timer = setTimeout(function() {
compare(el, e);
Expand All @@ -72,7 +88,7 @@ module.exports = function(el, onOver, onOut) {
function dispatchOut(e) {
mouseOver = false;
if (timer) timer = clearTimeout(timer);
el.removeEventListener('mousemove', tracker, false);
removeMouseMoveEventListener(el);

if (state === 1) {
timer = setTimeout(function() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hoverintent",
"version": "2.2.1",
"version": "2.2.2",
"repository": "[email protected]:tristen/hoverintent.git",
"description": "Fire mouse events when the user intends it",
"main": "index.js",
Expand Down