mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 17:14:04 +02:00
Clean up, move stringQs to util
This commit is contained in:
@@ -4,16 +4,8 @@ iD.Hash = function() {
|
||||
lat = 90 - 1e-8, // allowable latitude range
|
||||
map;
|
||||
|
||||
function qs(str) {
|
||||
return str.split('&').reduce(function(obj, pair){
|
||||
var parts = pair.split('=');
|
||||
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
var parser = function(map, s) {
|
||||
var q = qs(s);
|
||||
var q = iD.util.stringQs(s);
|
||||
var args = (q.map || '').split("/").map(Number);
|
||||
if (args.length < 3 || args.some(isNaN)) {
|
||||
return true; // replace bogus hash
|
||||
|
||||
@@ -6,7 +6,6 @@ iD.Map = function() {
|
||||
selection = null,
|
||||
translateStart,
|
||||
keybinding,
|
||||
apiTilesLoaded = {},
|
||||
projection = d3.geo.mercator(),
|
||||
zoom = d3.behavior.zoom()
|
||||
.translate(projection.translate())
|
||||
|
||||
@@ -50,6 +50,14 @@ iD.util.tagText = function(entity) {
|
||||
}).join('\n');
|
||||
};
|
||||
|
||||
iD.util.stringQs = function(str) {
|
||||
return str.split('&').reduce(function(obj, pair){
|
||||
var parts = pair.split('=');
|
||||
obj[parts[0]] = (null === parts[1]) ? '' : decodeURIComponent(parts[1]);
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
iD.util.qsString = function(obj) {
|
||||
return Object.keys(obj).sort().map(function(key) {
|
||||
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
|
||||
|
||||
+2
-4
@@ -39,15 +39,13 @@ describe('Util', function() {
|
||||
it('correctly says that a node is in an extent', function() {
|
||||
expect(iD.util.geo.nodeIntersect({
|
||||
lat: 0, lon: 0
|
||||
}, [
|
||||
[-180, 90],
|
||||
}, [[-180, 90],
|
||||
[180, -90]])).to.be.true;
|
||||
});
|
||||
it('correctly says that a node is outside of an extent', function() {
|
||||
expect(iD.util.geo.nodeIntersect({
|
||||
lat: 0, lon: 0
|
||||
}, [
|
||||
[100, 90],
|
||||
}, [[100, 90],
|
||||
[180, -90]])).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user