aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/core/Util.js
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2012-01-10 01:54:37 +0100
committerJoar Wandborg <git@wandborg.com>2012-01-25 23:42:04 +0100
commitc5ba5b0456a711d157e317f220e9c739226e7f50 (patch)
tree2800568ac8e484649a978e0fe7e682a8bcfe20d4 /extlib/leaflet/src/core/Util.js
parentc47a03b909ecd97cab5b144d0cab007b62b92a90 (diff)
downloadmediagoblin-c5ba5b0456a711d157e317f220e9c739226e7f50.tar.lz
mediagoblin-c5ba5b0456a711d157e317f220e9c739226e7f50.tar.xz
mediagoblin-c5ba5b0456a711d157e317f220e9c739226e7f50.zip
Installed leaflet in extlib
Diffstat (limited to 'extlib/leaflet/src/core/Util.js')
-rw-r--r--extlib/leaflet/src/core/Util.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/extlib/leaflet/src/core/Util.js b/extlib/leaflet/src/core/Util.js
new file mode 100644
index 00000000..28daa284
--- /dev/null
+++ b/extlib/leaflet/src/core/Util.js
@@ -0,0 +1,96 @@
+/*
+ * L.Util is a namespace for various utility functions.
+ */
+
+L.Util = {
+ extend: function(/*Object*/ dest) /*-> Object*/ { // merge src properties into dest
+ var sources = Array.prototype.slice.call(arguments, 1);
+ for (var j = 0, len = sources.length, src; j < len; j++) {
+ src = sources[j] || {};
+ for (var i in src) {
+ if (src.hasOwnProperty(i)) {
+ dest[i] = src[i];
+ }
+ }
+ }
+ return dest;
+ },
+
+ bind: function(/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
+ return function() {
+ return fn.apply(obj, arguments);
+ };
+ },
+
+ stamp: (function() {
+ var lastId = 0, key = '_leaflet_id';
+ return function(/*Object*/ obj) {
+ obj[key] = obj[key] || ++lastId;
+ return obj[key];
+ };
+ })(),
+
+ requestAnimFrame: (function() {
+ function timeoutDefer(callback) {
+ window.setTimeout(callback, 1000 / 60);
+ }
+
+ var requestFn = window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ timeoutDefer;
+
+ return function(callback, context, immediate) {
+ callback = context ? L.Util.bind(callback, context) : context;
+ if (immediate && requestFn === timeoutDefer) {
+ callback();
+ } else {
+ requestFn(callback);
+ }
+ };
+ })(),
+
+ limitExecByInterval: function(fn, time, context) {
+ var lock, execOnUnlock, args;
+ function exec(){
+ lock = false;
+ if (execOnUnlock) {
+ args.callee.apply(context, args);
+ execOnUnlock = false;
+ }
+ }
+ return function() {
+ args = arguments;
+ if (!lock) {
+ lock = true;
+ setTimeout(exec, time);
+ fn.apply(context, args);
+ } else {
+ execOnUnlock = true;
+ }
+ };
+ },
+
+ falseFn: function() { return false; },
+
+ formatNum: function(num, digits) {
+ var pow = Math.pow(10, digits || 5);
+ return Math.round(num * pow) / pow;
+ },
+
+ setOptions: function(obj, options) {
+ obj.options = L.Util.extend({}, obj.options, options);
+ },
+
+ getParamString: function(obj) {
+ var params = [];
+ for (var i in obj) {
+ if (obj.hasOwnProperty(i)) {
+ params.push(i + '=' + obj[i]);
+ }
+ }
+ return '?' + params.join('&');
+ }
+};