From b701a6f298923690104743587a64cffb88b0d16b Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Fri, 10 Jul 2020 10:53:14 +0200 Subject: [PATCH] Refactor collapse handling into Elevation as it's the only element it is intended for, sidebar uses separate handling. --- js/index.js | 31 ++----------------------------- js/plugin/Elevation.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/js/index.js b/js/index.js index e95444a..476e588 100644 --- a/js/index.js +++ b/js/index.js @@ -420,38 +420,11 @@ urlHash ); + // listener and initCollapse here and not in onAdd, as addBelow calls addTo (-> onAdd) on resize $(window).resize(function() { elevation.addBelow(map); }); - - $('#elevation-chart').on('show.bs.collapse', function() { - $('#elevation-btn').addClass('active'); - }); - $('#elevation-chart').on('hidden.bs.collapse', function() { - $('#elevation-btn').removeClass('active'); - // we must fetch tiles that are located behind elevation-chart - map._onResize(); - }); - - var onHide = function() { - if (this.id && BR.Util.localStorageAvailable()) { - localStorage.removeItem(this.id); - } - }; - var onShow = function() { - if (this.id && BR.Util.localStorageAvailable()) { - localStorage[this.id] = 'true'; - } - }; - // on page load, we want to restore collapsible elements from previous usage - $('.collapse') - .on('hidden.bs.collapse', onHide) - .on('shown.bs.collapse', onShow) - .each(function() { - if (this.id && BR.Util.localStorageAvailable() && localStorage[this.id] === 'true') { - $(this).collapse('show'); - } - }); + elevation.initCollapse(map); } i18next.on('languageChanged', function(detectedLanguage) { diff --git a/js/plugin/Elevation.js b/js/plugin/Elevation.js index 1c827f0..fe682dd 100644 --- a/js/plugin/Elevation.js +++ b/js/plugin/Elevation.js @@ -55,6 +55,34 @@ BR.Elevation = L.Control.Elevation.extend({ setParent(this.getContainer(), document.getElementById('elevation-chart')); }, + initCollapse: function(map) { + var onHide = function() { + $('#elevation-btn').removeClass('active'); + // we must fetch tiles that are located behind elevation-chart + map._onResize(); + + if (this.id && BR.Util.localStorageAvailable()) { + localStorage.removeItem(this.id); + } + }; + var onShow = function() { + $('#elevation-btn').addClass('active'); + + if (this.id && BR.Util.localStorageAvailable()) { + localStorage[this.id] = 'true'; + } + }; + // on page load, we want to restore collapse state from previous usage + $('#elevation-chart') + .on('hidden.bs.collapse', onHide) + .on('shown.bs.collapse', onShow) + .each(function() { + if (this.id && BR.Util.localStorageAvailable() && localStorage[this.id] === 'true') { + $(this).collapse('show'); + } + }); + }, + update: function(track, layer) { this.clear();