Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / src / core / Util.js
blob28daa2846530b21189b18c12219a663aca1ba1c9
1 /*
2 * L.Util is a namespace for various utility functions.
3 */
5 L.Util = {
6 extend: function(/*Object*/ dest) /*-> Object*/ { // merge src properties into dest
7 var sources = Array.prototype.slice.call(arguments, 1);
8 for (var j = 0, len = sources.length, src; j < len; j++) {
9 src = sources[j] || {};
10 for (var i in src) {
11 if (src.hasOwnProperty(i)) {
12 dest[i] = src[i];
16 return dest;
19 bind: function(/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
20 return function() {
21 return fn.apply(obj, arguments);
25 stamp: (function() {
26 var lastId = 0, key = '_leaflet_id';
27 return function(/*Object*/ obj) {
28 obj[key] = obj[key] || ++lastId;
29 return obj[key];
31 })(),
33 requestAnimFrame: (function() {
34 function timeoutDefer(callback) {
35 window.setTimeout(callback, 1000 / 60);
38 var requestFn = window.requestAnimationFrame ||
39 window.webkitRequestAnimationFrame ||
40 window.mozRequestAnimationFrame ||
41 window.oRequestAnimationFrame ||
42 window.msRequestAnimationFrame ||
43 timeoutDefer;
45 return function(callback, context, immediate) {
46 callback = context ? L.Util.bind(callback, context) : context;
47 if (immediate && requestFn === timeoutDefer) {
48 callback();
49 } else {
50 requestFn(callback);
53 })(),
55 limitExecByInterval: function(fn, time, context) {
56 var lock, execOnUnlock, args;
57 function exec(){
58 lock = false;
59 if (execOnUnlock) {
60 args.callee.apply(context, args);
61 execOnUnlock = false;
64 return function() {
65 args = arguments;
66 if (!lock) {
67 lock = true;
68 setTimeout(exec, time);
69 fn.apply(context, args);
70 } else {
71 execOnUnlock = true;
76 falseFn: function() { return false; },
78 formatNum: function(num, digits) {
79 var pow = Math.pow(10, digits || 5);
80 return Math.round(num * pow) / pow;
83 setOptions: function(obj, options) {
84 obj.options = L.Util.extend({}, obj.options, options);
87 getParamString: function(obj) {
88 var params = [];
89 for (var i in obj) {
90 if (obj.hasOwnProperty(i)) {
91 params.push(i + '=' + obj[i]);
94 return '?' + params.join('&');