Update hash on P2 and iD edit pages and throttle

This commit is contained in:
John Firebaugh 2013-07-24 12:21:13 -07:00
parent 3c22a53c93
commit 1a5f14d338
5 changed files with 277 additions and 6 deletions

View file

@ -2,6 +2,7 @@
//= require jquery_ujs
//= require jquery.timers
//= require jquery.cookie
//= require jquery.throttle-debounce
//= require augment
//= require leaflet
//= require leaflet.osm

View file

@ -85,7 +85,12 @@
});
});
function mapMoved(lon, lat, zoom, minlon, minlat, maxlon, maxlat) {
var mapMoved = $.throttle(250, function(lon, lat, zoom, minlon, minlat, maxlon, maxlat) {
updatelinks({ lon: lon, lat: lat }, zoom, null, [[minlat, minlon], [maxlat, maxlon]]);
}
var hash = OSM.formatHash({ lon: lon, lat: lat, zoom: zoom });
if (hash !== location.hash) {
location.replace(hash);
}
});
</script>

View file

@ -31,7 +31,7 @@
oauth_token_secret: "<%= token.secret %>"
});
id.map().on('move.embed', function() {
id.map().on('move.embed', parent.$.throttle(250, function() {
var extent = id.map().extent(),
zoom = ~~id.map().zoom(),
center = id.map().center();
@ -46,7 +46,16 @@
extent[0][0]],
[extent[1][1],
extent[1][0]]]);
});
// 0ms timeout to avoid iframe JS context weirdness.
// http://bl.ocks.org/jfirebaugh/5439412
parent.setTimeout(function() {
var hash = parent.OSM.formatHash({ lon: center[0], lat: center[1], zoom: zoom });
if (hash !== parent.location.hash) {
parent.location.replace(hash);
}
}, 0);
}));
parent.$("body").on("click", "a.set_position", function (e) {
e.preventDefault();
@ -54,7 +63,7 @@
// 0ms timeout to avoid iframe JS context weirdness.
// http://bl.ocks.org/jfirebaugh/5439412
setTimeout(function() {
parent.setTimeout(function() {
id.map().centerZoom(
[data.lon, data.lat],
Math.max(data.zoom || 15, 13));