]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/element.js
Follow redirects to suspended page in spammy tests
[rails.git] / app / assets / javascripts / index / element.js
1 (function () {
2   OSM.Element = function (map, type) {
3     const page = {};
4
5     page.pushstate = page.popstate = function (path, id, version) {
6       OSM.loadSidebarContent(path, function () {
7         page._addObject(type, id, version);
8       });
9     };
10
11     page.load = function (path, id, version) {
12       page._addObject(type, id, version, true);
13     };
14
15     page.unload = function () {
16       page._removeObject();
17     };
18
19     page._addObject = function () {};
20     page._removeObject = function () {};
21
22     return page;
23   };
24
25   OSM.MappedElement = function (map, type) {
26     const page = OSM.Element(map, type);
27
28     page._addObject = function (type, id, version, center) {
29       const hashParams = OSM.parseHash();
30       map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
31         if (!hashParams.center && bounds.isValid() &&
32             (center || !map.getBounds().contains(bounds))) {
33           OSM.router.withoutMoveListener(function () {
34             map.fitBounds(bounds);
35           });
36         }
37       });
38     };
39
40     page._removeObject = function () {
41       map.removeObject();
42     };
43
44     return page;
45   };
46 }());