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

More visibility to when an element is zoomed and made it easier to remove a zoom object #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 20 additions & 12 deletions jquery.zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@

// If a url wasn't specified, look for an image element.
if (!settings.url) {
settings.url = $(source).find('img').attr('src');

if($(source).data('zoom')) {
settings.url = $(source).data('zoom');
} else {
settings.url = $(source).find('img').attr('src');
}
if (!settings.url) {
return;
}
Expand All @@ -90,6 +95,8 @@
zoom.init();
zoom.move(e);

$(target).addClass('zoomed');

// Skip the fade-in for IE8 and lower since it chokes on fading-in
// and changing position based on mousemovement at the same time.
$img.stop()
Expand All @@ -99,12 +106,13 @@
function stop() {
$img.stop()
.fadeTo(settings.duration, 0);
$(target).removeClass('zoomed');
}

if (settings.on === 'grab') {
$(source).on('mousedown',
$(source).on('mousedown' + '.zoom',
function (e) {
$(document).one('mouseup',
$(document).one('mouseup' + '.zoom',
function () {
stop();

Expand All @@ -114,34 +122,34 @@

start(e);

$(document).on(mousemove, zoom.move);
$(document).on(mousemove + '.zoom', zoom.move);

e.preventDefault();
}
);
} else if (settings.on === 'click') {
$(source).on('click',
$(source).on('click' + '.zoom',
function (e) {
if (clicked) {
// bubble the event up to the document to trigger the unbind.
return;
} else {
clicked = true;
start(e);
$(document).on(mousemove, zoom.move);
$(document).one('click',
$(document).on(mousemove + '.zoom', zoom.move);
$(document).one('click' + '.zoom',
function () {
stop();
clicked = false;
$(document).off(mousemove, zoom.move);
$(document).off(mousemove + '.zoom', zoom.move);
}
);
return false;
}
}
);
} else if (settings.on === 'toggle') {
$(source).on('click',
$(source).on('click' + '.zoom',
function (e) {
if (clicked) {
stop();
Expand All @@ -155,9 +163,9 @@
zoom.init(); // Pre-emptively call init because IE7 will fire the mousemove handler before the hover handler.

$(source)
.on('mouseenter', start)
.on('mouseleave', stop)
.on(mousemove, zoom.move);
.on('mouseenter' + '.zoom', start)
.on('mouseleave' + '.zoom', stop)
.on(mousemove + '.zoom', zoom.move);
}

if ($.isFunction(settings.callback)) {
Expand Down