]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.sidebar.js
Only one pane visible at a time
[rails.git] / app / assets / javascripts / leaflet.sidebar.js
diff --git a/app/assets/javascripts/leaflet.sidebar.js b/app/assets/javascripts/leaflet.sidebar.js
new file mode 100644 (file)
index 0000000..a6529ad
--- /dev/null
@@ -0,0 +1,35 @@
+L.OSM.sidebar = function(selector) {
+  var control = {},
+    sidebar = $(selector),
+    current = $();
+
+  control.addPane = function(pane) {
+    pane
+      .hide()
+      .appendTo(sidebar);
+  };
+
+  control.togglePane = function(pane) {
+    var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
+
+    current
+      .hide()
+      .trigger('hide');
+
+    if (current === pane) {
+      $(sidebar).hide();
+      controlContainer.css({paddingRight: '0'});
+      current = $();
+    } else {
+      $(sidebar).show();
+      controlContainer.css({paddingRight: '200px'});
+      current = pane;
+    }
+
+    current
+      .show()
+      .trigger('show');
+  };
+
+  return control;
+};