Skip to content

Commit 0de87fa

Browse files
committed
Merge pull request Leaflet#1856 from rutkovsky/disable_animations_outside_dom
Disable animations outside dom
2 parents 5829963 + 0e34b8c commit 0de87fa

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

spec/suites/dom/PosAnimationSpec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
describe('PosAnimation', function() {
2+
var el;
3+
4+
beforeEach(function() {
5+
el = document.createElement('div');
6+
this.subject = new L.PosAnimation();
7+
this.subject._el = el;
8+
});
9+
10+
describe('#_onStep', function() {
11+
it("sets element position and fires step event if it is able to get current position", function() {
12+
var point = new L.Point(5, 5, true);
13+
sinon.stub(this.subject, '_getPos').returns(point);
14+
this.subject.fire = sinon.stub();
15+
this.subject._onStep();
16+
expect(this.subject.fire.withArgs('step').calledOnce).to.be(true);
17+
expect(this.subject._el._leaflet_pos).to.be(point);
18+
});
19+
20+
it('stops transition if a position returned', function() {
21+
sinon.stub(this.subject, '_onTransitionEnd');
22+
sinon.stub(this.subject, '_getPos').returns(undefined);
23+
this.subject._onStep();
24+
expect(this.subject._onTransitionEnd.calledOnce).to.be(true);
25+
});
26+
});
27+
});

src/dom/PosAnimation.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ L.PosAnimation = L.Class.extend({
3939
},
4040

4141
_onStep: function () {
42+
var stepPos = this._getPos();
43+
if (!stepPos) {
44+
this._onTransitionEnd();
45+
return;
46+
}
4247
// jshint camelcase: false
4348
// make L.DomUtil.getPosition return intermediate position value during animation
44-
this._el._leaflet_pos = this._getPos();
49+
this._el._leaflet_pos = stepPos;
4550

4651
this.fire('step');
4752
},
@@ -58,8 +63,9 @@ L.PosAnimation = L.Class.extend({
5863

5964
if (L.Browser.any3d) {
6065
matches = style[L.DomUtil.TRANSFORM].match(this._transformRe);
61-
left = matches ? parseFloat(matches[1]) : 0;
62-
top = matches ? parseFloat(matches[2]) : 0;
66+
if (!matches) { return; }
67+
left = parseFloat(matches[1]);
68+
top = parseFloat(matches[2]);
6369
} else {
6470
left = parseFloat(style.left);
6571
top = parseFloat(style.top);

0 commit comments

Comments
 (0)