From 3ba2277ab461ec9e53db38012b3dca20638630ed Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 13:35:15 +0300 Subject: [PATCH] Move Browse and OldBrowse to their own file --- app/assets/javascripts/index.js | 43 +------------------------ app/assets/javascripts/index/element.js | 43 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 app/assets/javascripts/index/element.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index fd6ef9d92..733bfab7e 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -21,6 +21,7 @@ //= require index/changeset //= require index/query //= require index/home +//= require index/element //= require router $(function () { @@ -286,48 +287,6 @@ $(function () { return page; }; - OSM.Browse = function (map, type) { - const page = {}; - - page.pushstate = page.popstate = function (path, id, version) { - OSM.loadSidebarContent(path, function () { - addObject(type, id, version); - }); - }; - - page.load = function (path, id, version) { - addObject(type, id, version, true); - }; - - function addObject(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() && - (center || !map.getBounds().contains(bounds))) { - OSM.router.withoutMoveListener(function () { - map.fitBounds(bounds); - }); - } - }); - } - - page.unload = function () { - map.removeObject(); - }; - - return page; - }; - - OSM.OldBrowse = function () { - const page = {}; - - page.pushstate = page.popstate = function (path) { - OSM.loadSidebarContent(path); - }; - - return page; - }; - const history = OSM.History(map); OSM.router = OSM.Router(map, { diff --git a/app/assets/javascripts/index/element.js b/app/assets/javascripts/index/element.js new file mode 100644 index 000000000..b0b2b6faa --- /dev/null +++ b/app/assets/javascripts/index/element.js @@ -0,0 +1,43 @@ +(function () { + OSM.OldBrowse = function () { + const page = {}; + + page.pushstate = page.popstate = function (path) { + OSM.loadSidebarContent(path); + }; + + return page; + }; + + OSM.Browse = function (map, type) { + const page = {}; + + page.pushstate = page.popstate = function (path, id, version) { + OSM.loadSidebarContent(path, function () { + addObject(type, id, version); + }); + }; + + page.load = function (path, id, version) { + addObject(type, id, version, true); + }; + + function addObject(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() && + (center || !map.getBounds().contains(bounds))) { + OSM.router.withoutMoveListener(function () { + map.fitBounds(bounds); + }); + } + }); + } + + page.unload = function () { + map.removeObject(); + }; + + return page; + }; +}()); -- 2.39.5