]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/id.js
Don't try and modify policy if we don't have one
[rails.git] / app / assets / javascripts / id.js
1 //= require iD
2
3 document.addEventListener("DOMContentLoaded", function() {
4   var container = document.getElementById("id-container");
5
6   if (typeof iD === 'undefined' || !iD.Detect().support) {
7     container.innerHTML = 'This editor is supported ' +
8       'in Firefox, Chrome, Safari, Opera, Edge, and Internet Explorer 11. ' +
9       'Please upgrade your browser or use Potlatch 2 to edit the map.';
10     container.className = 'unsupported';
11   } else {
12     var id = iD.Context()
13       .embed(true)
14       .assetPath("iD/")
15       .assetMap(container.dataset.assetMap)
16       .locale(container.dataset.locale, container.dataset.localePath)
17       .preauth({
18         urlroot: location.protocol + "//" + location.host,
19         oauth_consumer_key: container.dataset.consumerKey,
20         oauth_secret: container.dataset.consumerSecret,
21         oauth_token: container.dataset.token,
22         oauth_token_secret: container.dataset.tokenSecret
23       });
24
25     id.map().on('move.embed', parent.$.throttle(250, function() {
26       if (id.inIntro()) return;
27       var zoom = ~~id.map().zoom(),
28         center = id.map().center(),
29         llz = { lon: center[0], lat: center[1], zoom: zoom };
30
31       parent.updateLinks(llz, zoom);
32
33       // Manually resolve URL to avoid iframe JS context weirdness.
34       // http://bl.ocks.org/jfirebaugh/5439412
35       var hash = parent.OSM.formatHash(llz);
36       if (hash !== parent.location.hash) {
37         parent.location.replace(parent.location.href.replace(/(#.*|$)/, hash));
38       }
39     }));
40
41     parent.$("body").on("click", "a.set_position", function (e) {
42       e.preventDefault();
43       var data = parent.$(this).data();
44
45       // 0ms timeout to avoid iframe JS context weirdness.
46       // http://bl.ocks.org/jfirebaugh/5439412
47       setTimeout(function() {
48         id.map().centerZoom(
49           [data.lon, data.lat],
50           Math.max(data.zoom || 15, 13));
51       }, 0);
52     });
53
54     id.ui()(container);
55   }
56 });