Skip to content

Instantly share code, notes, and snippets.

@parallaxisjones
Created January 5, 2016 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parallaxisjones/344a6781f045f4e15ca1 to your computer and use it in GitHub Desktop.
Save parallaxisjones/344a6781f045f4e15ca1 to your computer and use it in GitHub Desktop.
L.Control.Sidebar = L.Control.extend({
includes: L.Mixin.Events,
initialize: function (id, options) {
var i, child;
L.setOptions(this, options);
// Find sidebar HTMLElement
this._sidebar = L.DomUtil.get(id);
// Attach touch styling if necessary
if (L.Browser.touch)
L.DomUtil.addClass(this._sidebar, 'leaflet-touch');
// Find sidebar > ul.sidebar-tabs and sidebar > div.sidebar-content
for (i = this._sidebar.children.length - 1; i >= 0; i--) {
child = this._sidebar.children[i];
if (child.tagName == 'UL' &&
L.DomUtil.hasClass(child, 'sidebar-tabs'))
this._tabs = child;
else if (child.tagName == 'DIV' &&
L.DomUtil.hasClass(child, 'sidebar-content'))
this._container = child;
}
// Find sidebar > ul.sidebar-tabs > li
this._tabitems = [];
for (i = this._tabs.children.length - 1; i >= 0; i--) {
child = this._tabs.children[i];
if (child.tagName == 'LI') {
this._tabitems.push(child);
child._sidebar = this;
}
}
// Find sidebar > div.sidebar-content > div.sidebar-pane
this._panes = [];
for (i = this._container.children.length - 1; i >= 0; i--) {
child = this._container.children[i];
if (child.tagName == 'DIV' &&
L.DomUtil.hasClass(child, 'sidebar-pane'))
this._panes.push(child);
}
this._hasTouchStart = L.Browser.touch &&
('ontouchstart' in document.documentElement);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment