Refactor collapse handling into Elevation
as it's the only element it is intended for, sidebar uses separate handling.
This commit is contained in:
parent
fe6c0d784c
commit
b701a6f298
2 changed files with 30 additions and 29 deletions
31
js/index.js
31
js/index.js
|
|
@ -420,38 +420,11 @@
|
||||||
urlHash
|
urlHash
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// listener and initCollapse here and not in onAdd, as addBelow calls addTo (-> onAdd) on resize
|
||||||
$(window).resize(function() {
|
$(window).resize(function() {
|
||||||
elevation.addBelow(map);
|
elevation.addBelow(map);
|
||||||
});
|
});
|
||||||
|
elevation.initCollapse(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');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i18next.on('languageChanged', function(detectedLanguage) {
|
i18next.on('languageChanged', function(detectedLanguage) {
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,34 @@ BR.Elevation = L.Control.Elevation.extend({
|
||||||
setParent(this.getContainer(), document.getElementById('elevation-chart'));
|
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) {
|
update: function(track, layer) {
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue