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

Fix the 'Hover to Show' newtab option; Only add mouse move listener w… #138

Merged
merged 1 commit into from Oct 29, 2015
Merged
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
12 changes: 8 additions & 4 deletions data/newtabicons-content.js
Expand Up @@ -9,11 +9,13 @@
'use strict';

function mouseOverListener(e) {
e.target.style.backgroundImage = e.target.dataset.newPreview;
let thumb = e.target.previousElementSibling;
thumb.style.backgroundImage = thumb.dataset.newPreview;
}

function mouseOutListener(e) {
e.target.style.backgroundImage = e.target.dataset.oldPreview;
let thumb = e.target.previousElementSibling;
thumb.style.backgroundImage = thumb.dataset.oldPreview;
}

function mouseMoveListener (e) {
Expand Down Expand Up @@ -72,26 +74,28 @@ function updateThumbnails() {
thumb.style.backgroundImage = thumb.dataset.oldPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
thumb.removeEventListener('mouseout', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
break;
case 1:
thumb.style.backgroundImage = thumb.dataset.oldPreview;
thumb.addEventListener('mouseover', mouseOverListener);
thumb.addEventListener('mouseout', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
break;
case 2:
thumb.style.backgroundImage = thumb.dataset.newPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
thumb.removeEventListener('mouseout', mouseOutListener);
window.addEventListener('mousemove', mouseMoveListener);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove this in cases 1 and 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.. for the record, this switch statement doesn't match up with the 'toggle' one above for some reason. 'case 2' seems to be the 'Always On' option and I think that's the only case that needs the mousemove listener.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah, it doesn't match up because the toggle one is describing the next state.
And I agree it only needs the listener for case 2, so we should have "window.removeEventListener" in the other two cases, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I misunderstood what you meant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest commit.

break;
case 3:
thumb.style.backgroundImage = thumb.dataset.oldPreview;
thumb.removeEventListener('mouseover', mouseOverListener);
thumb.removeEventListener('mouseout', mouseOutListener);
window.removeEventListener('mousemove', mouseMoveListener);
}
}
}

window.addEventListener('mousemove', mouseMoveListener);
}

function addThumbnails(thumbnails) {
Expand Down