Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature to make individual groups collapsable #46

Open
wants to merge 7 commits into
base: gh-pages
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixed interaction between collapsable groups and group checkboxes
Prevented event propagation from the label to the checkbox when group
checkboxes are enabled.  Cleaned up some code.
  • Loading branch information
ForgottenLords committed Mar 16, 2017
commit e29fa73de3badb555f043054a9a7f649fdc8339e
16 changes: 8 additions & 8 deletions src/leaflet.groupedlayercontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ L.Control.GroupedLayers = L.Control.extend({
// Create the group container if it doesn't exist
if (!groupContainer) {
groupContainer = document.createElement('div');
if (this.options.groupsCollapsable){
groupContainer.className = 'leaflet-control-layers-group group-collapsable collapsed';
}else{
groupContainer.className = 'leaflet-control-layers-group';
}
groupContainer.className = 'leaflet-control-layers-group';
groupContainer.id = 'leaflet-control-layers-group-' + obj.group.id;

var groupLabel = document.createElement('label');
Expand All @@ -284,6 +280,9 @@ L.Control.GroupedLayers = L.Control.extend({
}

if (this.options.groupsCollapsable){
groupContainer.classList.add("group-collapsable");
groupContainer.classList.add("collapsed");

var groupMin = document.createElement('span');
groupMin.className = 'leaflet-control-layers-group-collapse '+this.options.groupsCollapseClass;
groupLabel.appendChild(groupMin);
Expand Down Expand Up @@ -317,16 +316,17 @@ L.Control.GroupedLayers = L.Control.extend({
},

_onGroupCollapseToggle: function (event) {
event.stopPropagation();
L.DomEvent.stopPropagation(event);
L.DomEvent.preventDefault(event);
if (this.classList.contains("group-collapsable") && this.classList.contains("collapsed")){
this.classList.remove("collapsed");
}else if (this.classList.contains("group-collapsable") && this.classList.contains("collapsed")==false){
}else if (this.classList.contains("group-collapsable") && !this.classList.contains("collapsed")){
this.classList.add("collapsed");
}
},

_onGroupInputClick: function (event) {
event.stopPropagation();
L.DomEvent.stopPropagation(event);
var i, input, obj;

var this_legend = this.legend;
Expand Down