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