lib/leaflet/src/core/Util.js in leaflet-js-0.6.beta4 vs lib/leaflet/src/core/Util.js in leaflet-js-0.7.0
- old
+ new
@@ -24,12 +24,13 @@
return fn.apply(obj, args || arguments);
};
},
stamp: (function () {
- var lastId = 0, key = '_leaflet_id';
- return function (/*Object*/ obj) {
+ var lastId = 0,
+ key = '_leaflet_id';
+ return function (obj) {
obj[key] = obj[key] || ++lastId;
return obj[key];
};
}()),
@@ -94,30 +95,34 @@
setOptions: function (obj, options) {
obj.options = L.extend({}, obj.options, options);
return obj.options;
},
- getParamString: function (obj, existingUrl) {
+ getParamString: function (obj, existingUrl, uppercase) {
var params = [];
for (var i in obj) {
- params.push(encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]));
+ params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]));
}
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
},
- template: function (str, data) {
- return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
- var value = data[key];
- if (value === undefined) {
- throw new Error('No value provided for variable ' + str);
- } else if (typeof value === 'function') {
- value = value(data);
- }
- return value;
+ compileTemplate: function (str, data) {
+ // based on https://gist.github.com/padolsey/6008842
+ str = str.replace(/"/g, '\\\"');
+ str = str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
+ return '" + o["' + key + '"]' + (typeof data[key] === 'function' ? '(o)' : '') + ' + "';
});
+ // jshint evil: true
+ return new Function('o', 'return "' + str + '";');
},
- isArray: function (obj) {
+ template: function (str, data) {
+ var cache = L.Util._templateCache = L.Util._templateCache || {};
+ cache[str] = cache[str] || L.Util.compileTemplate(str, data);
+ return cache[str](data);
+ },
+
+ isArray: Array.isArray || function (obj) {
return (Object.prototype.toString.call(obj) === '[object Array]');
},
emptyImageUrl: 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
};