Code coverage report for src/dom/PosAnimation.Timer.js

Statements: 3.45% (1 / 29)      Branches: 10% (1 / 10)      Functions: 0% (0 / 7)      Lines: 3.57% (1 / 28)     

All files » src/dom/ » PosAnimation.Timer.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68          1                                                                                                                            
/*
 * L.PosAnimation fallback implementation that powers Leaflet pan animations
 * in browsers that don't support CSS3 Transitions.
 */
 
L.PosAnimation = L.DomUtil.TRANSITION ? L.PosAnimation : L.PosAnimation.extend({
 
	run: function (el, newPos, duration, easeLinearity) { // (HTMLElement, Point[, Number, Number])
		this.stop();
 
		this._el = el;
		this._inProgress = true;
		this._duration = duration || 0.25;
		this._easeOutPower = 1 / Math.max(easeLinearity || 0.5, 0.2);
 
		this._startPos = L.DomUtil.getPosition(el);
		this._offset = newPos.subtract(this._startPos);
		this._startTime = +new Date();
 
		this.fire('start');
 
		this._animate();
	},
 
	stop: function () {
		if (!this._inProgress) { return; }
 
		this._step();
		this._complete();
	},
 
	_animate: function () {
		// animation loop
		this._animId = L.Util.requestAnimFrame(this._animate, this);
		this._step();
	},
 
	_step: function () {
		var elapsed = (+new Date()) - this._startTime,
		    duration = this._duration * 1000;
 
		if (elapsed < duration) {
			this._runFrame(this._easeOut(elapsed / duration));
		} else {
			this._runFrame(1);
			this._complete();
		}
	},
 
	_runFrame: function (progress) {
		var pos = this._startPos.add(this._offset.multiplyBy(progress));
		L.DomUtil.setPosition(this._el, pos);
 
		this.fire('step');
	},
 
	_complete: function () {
		L.Util.cancelAnimFrame(this._animId);
 
		this._inProgress = false;
		this.fire('end');
	},
 
	_easeOut: function (t) {
		return 1 - Math.pow(1 - t, this._easeOutPower);
	}
});