Browse Source

Category, Index: Improve open/close

master
parent
commit
bb646c90f6
  1. 10
      src/OpenStreetBrowserCategory.js
  2. 32
      src/OpenStreetBrowserIndex.js

10
src/OpenStreetBrowserCategory.js

@ -17,6 +17,9 @@ OpenStreetBrowserCategory.prototype.setParentDom = function (parentDom) {
}
OpenStreetBrowserCategory.prototype.open = function () {
if (this.isOpen)
return
if (typeof this.parentDom === 'string') {
this.parentDom = document.getElementById(this.parentDom)
}
@ -30,7 +33,10 @@ OpenStreetBrowserCategory.prototype.open = function () {
this.isOpen = true
}
OpenStreetBrowserCategory.prototype.remove = function () {
OpenStreetBrowserCategory.prototype.close = function () {
if (!this.isOpen)
return
this.layer.remove()
this.list.remove()
@ -39,7 +45,7 @@ OpenStreetBrowserCategory.prototype.remove = function () {
OpenStreetBrowserCategory.prototype.toggle = function () {
if (this.isOpen) {
this.remove()
this.close()
} else {
this.open()
}

32
src/OpenStreetBrowserIndex.js

@ -5,7 +5,7 @@ function OpenStreetBrowserIndex (id, data) {
this.data = data
this.isOpen = false
this.childrenDoms = {}
this.childrenCategories = {}
this.childrenCategories = null
}
OpenStreetBrowserIndex.prototype.setMap = function (map) {
@ -17,6 +17,17 @@ OpenStreetBrowserIndex.prototype.setParentDom = function (parentDom) {
}
OpenStreetBrowserIndex.prototype.open = function () {
if (this.isOpen)
return
if (this.childrenCategories !== null) {
this.parentDom.style.display = 'block'
this.isOpen = true
return
}
this.childrenCategories = {}
if (typeof this.parentDom === 'string') {
this.parentDom = document.getElementById(this.parentDom)
}
@ -51,11 +62,28 @@ OpenStreetBrowserIndex.prototype.open = function () {
}.bind(this))
}
}
this.isOpen = true
}
OpenStreetBrowserIndex.prototype.close = function () {
if (!this.isOpen)
return
for (var k in this.childrenCategories) {
if (this.childrenCategories[k]) {
this.childrenCategories[k].close()
}
}
this.parentDom.style.display = 'none'
this.isOpen = false
}
OpenStreetBrowserIndex.prototype.toggle = function () {
if (this.isOpen) {
// this.remove()
this.close()
} else {
this.open()
}

Loading…
Cancel
Save