Clean up, move stringQs to util

This commit is contained in:
Tom MacWright
2012-12-04 18:28:22 -05:00
parent 7828fa34c1
commit 22fe35723f
4 changed files with 11 additions and 14 deletions
+1 -9
View File
@@ -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
-1
View File
@@ -6,7 +6,6 @@ iD.Map = function() {
selection = null,
translateStart,
keybinding,
apiTilesLoaded = {},
projection = d3.geo.mercator(),
zoom = d3.behavior.zoom()
.translate(projection.translate())
+8
View File
@@ -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
View File
@@ -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;
});
});