From 0814fd0e9b8fa3262a49ef050b2c2c61de8dd6c0 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 13:54:27 +0300 Subject: [PATCH] Implement MappedElement as extension of Element --- app/assets/javascripts/index/element.js | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/index/element.js b/app/assets/javascripts/index/element.js index 4f2ec8ff4..413b512a0 100644 --- a/app/assets/javascripts/index/element.js +++ b/app/assets/javascripts/index/element.js @@ -1,28 +1,31 @@ (function () { - OSM.Element = function () { - const page = {}; - - page.pushstate = page.popstate = function (path) { - OSM.loadSidebarContent(path); - }; - - return page; - }; - - OSM.MappedElement = function (map, type) { + OSM.Element = function (map, type) { const page = {}; page.pushstate = page.popstate = function (path, id, version) { OSM.loadSidebarContent(path, function () { - addObject(type, id, version); + page._addObject(type, id, version); }); }; page.load = function (path, id, version) { - addObject(type, id, version, true); + page._addObject(type, id, version, true); }; - function addObject(type, id, version, center) { + page.unload = function () { + page._removeObject(); + }; + + page._addObject = function () {}; + page._removeObject = function () {}; + + return page; + }; + + OSM.MappedElement = function (map, type) { + const page = OSM.Element(map, type); + + page._addObject = function (type, id, version, center) { const hashParams = OSM.parseHash(); map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) { if (!hashParams.center && bounds.isValid() && @@ -32,9 +35,9 @@ }); } }); - } + }; - page.unload = function () { + page._removeObject = function () { map.removeObject(); }; -- 2.39.5