[Pkg-javascript-commits] [leaflet] 09/40: Backported 9a2399ee500cfa24efd320e44c68ebf1c4109d78

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:33:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 0317a73dd3bf0593911e92384ae3bcc17350d668
Author: Per Liedman <per at liedman.net>
Date:   Tue Apr 15 21:05:48 2014 +0200

    Backported 9a2399ee500cfa24efd320e44c68ebf1c4109d78
---
 src/core/Util.js                  | 38 ++++++++++++++++++++++++++++++++++++++
 src/map/anim/Map.ZoomAnimation.js | 18 ++++++++++--------
 2 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/src/core/Util.js b/src/core/Util.js
index b903098..22c8d40 100644
--- a/src/core/Util.js
+++ b/src/core/Util.js
@@ -175,6 +175,44 @@ L.Util = {
 
 }());
 
+(function () {
+	// inspired by http://paulirish.com/2011/requestanimationframe-for-smart-animating/
+
+	function getPrefixed(name) {
+		return window['webkit' + name] || window['moz' + name] || window['ms' + name];
+	}
+
+	var lastTime = 0;
+
+	// fallback for IE 7-8
+	function timeoutDefer(fn) {
+		var time = +new Date(),
+		    timeToCall = Math.max(0, 16 - (time - lastTime));
+
+		lastTime = time + timeToCall;
+		return window.setTimeout(fn, timeToCall);
+	}
+
+	var requestFn = window.requestAnimationFrame || getPrefixed('RequestAnimationFrame') || timeoutDefer,
+	    cancelFn = window.cancelAnimationFrame || getPrefixed('CancelAnimationFrame') ||
+	               getPrefixed('CancelRequestAnimationFrame') || function (id) { window.clearTimeout(id); };
+
+
+	L.Util.requestAnimFrame = function (fn, context, immediate, element) {
+		if (immediate && requestFn === timeoutDefer) {
+			fn.call(context);
+		} else {
+			return requestFn.call(window, L.bind(fn, context), element);
+		}
+	};
+
+	L.Util.cancelAnimFrame = function (id) {
+		if (id) {
+			cancelFn.call(window, id);
+		}
+	};
+})();
+
 // shortcuts for most used utility functions
 L.extend = L.Util.extend;
 L.bind = L.Util.bind;
diff --git a/src/map/anim/Map.ZoomAnimation.js b/src/map/anim/Map.ZoomAnimation.js
index 709dd43..8b7d3f5 100644
--- a/src/map/anim/Map.ZoomAnimation.js
+++ b/src/map/anim/Map.ZoomAnimation.js
@@ -79,14 +79,16 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
 			L.Draggable._disabled = true;
 		}
 
-		this.fire('zoomanim', {
-			center: center,
-			zoom: zoom,
-			origin: origin,
-			scale: scale,
-			delta: delta,
-			backwards: backwards
-		});
+		L.Util.requestAnimFrame(function () {
+			this.fire('zoomanim', {
+				center: center,
+				zoom: zoom,
+				origin: origin,
+				scale: scale,
+				delta: delta,
+				backwards: backwards
+			});
+		}, this);
 	},
 
 	_onZoomTransitionEnd: function () {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list