Skip to content

Commit

Permalink
Close flyout if event is outside, closes i-like-robots#19
Browse files Browse the repository at this point in the history
  • Loading branch information
i-like-robots committed Jan 9, 2014
1 parent 94722a7 commit 0223b71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/easyzoom.js

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

12 changes: 8 additions & 4 deletions src/easyzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,20 @@
var xt = pt * rh;
var xl = pl * rw;

xt = (xt > dh) ? dh : xt;
xl = (xl > dw) ? dw : xl;
// xt = (xt > dh) ? dh : xt;
// xl = (xl > dw) ? dw : xl;

// Do not move the image if the event is outside
if (xl > 0 && xt > 0) {
// Close if outside
if (xl < 0 || xt < 0 || xl > dw || xt > dh) {
this.hide();
}
else {
this.$zoom.css({
top: '' + (Math.ceil(xt) * -1) + 'px',
left: '' + (Math.ceil(xl) * -1) + 'px'
});
}

};

/**
Expand Down
14 changes: 13 additions & 1 deletion test/spec/easyzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

asyncTest("_move(e)", function() {

expect(4);
expect(5);

var offset = api.$target.position();

Expand All @@ -167,6 +167,14 @@
pageY: offset.top + 100
};

var mock_3 = {
type: "mousemove",
pageX: offset.left - 10,
pageY: offset.top - 10
};

var spy = sinon.spy(api, "hide");

// Must open the flyout with a zoom image first
api.opts.onShow = function() {
var left, top;
Expand All @@ -187,6 +195,10 @@
equal(left, -200, "2x scale zoom image moved 200px left given 100px offset");
equal(top, -200, "2x scale zoom image moved 200px top given 100px offset");

api._move(mock_3);

equal(spy.calledOnce, true, ".hide() is called if event is outside");

start();
};

Expand Down

0 comments on commit 0223b71

Please sign in to comment.