Skip to content

Commit

Permalink
Add collapsedOnInit to options.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaveh committed Jul 26, 2017
1 parent 7aee221 commit b0fd453
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.2.1 (2017-07-26)
* Add `collapsedOnInit` to `options`
- A new option that allows users to initialize an instance in expanded or collapsed mode.
7 changes: 6 additions & 1 deletion L.Control.HtmlLegend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ L.Control.HtmlLegend = L.Control.extend({
position: 'topright',
legends: [], // array of legend entries - see README for format
collapseSimple: false, // if true, legend entries that are from a simple renderer will use compact presentation
detectStretched: false, // if true, will test to see if legend entries look stretched. These are usually in sets of 3 with the middle element having no label.
detectStretched: false, // if true, will test to see if legend entries look stretched; these are usually in sets of 3 with the middle element having no label.
collapsedOnInit: false, // if true, legends will be collapsed when a new instance is initialized.
defaultOpacity: 1,
visibleIcon: 'leaflet-html-legend-icon-eye',
hiddenIcon: 'leaflet-html-legend-icon-eye-slash',
Expand Down Expand Up @@ -59,6 +60,10 @@ L.Control.HtmlLegend = L.Control.extend({
L.DomUtil.create('div', 'legend-caret', header);
L.DomUtil.create('span', null, header).innerHTML = legend.name;

if (this.options.collapsedOnInit) {
L.DomUtil.addClass(header, 'closed');
}

L.DomEvent.on(header, 'click', function () {
if (L.DomUtil.hasClass(header, 'closed')) {
L.DomUtil.removeClass(header, 'closed');
Expand Down
2 changes: 1 addition & 1 deletion L.Control.HtmlLegend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Options:
legends: [], // array of legend entries. see below for the structure
collapseSimple: false, // if true, legend entries that are from a simple renderer will use compact presentation
detectStretched: false, // if true, will test to see if legend entries look stretched. These are usually in sets of 3 with the middle element having no label.
collapsedOnInit: false, // if true, legends will be collapsed when a new instance is initialized.
defaultOpacity: 1, // default opacity for layers in specified in legends.
visibleIcon: 'leaflet-html-legend-icon-eye', // css class for the visible icon on opacity slider
hiddenIcon: 'leaflet-html-legend-icon-eye-slash', // css class for the hidden icon on opacity slider
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
}],
collapseSimple: true,
detectStretched: true,
collapsedOnInit: true,
defaultOpacity: 0.7,
visibleIcon: 'icon icon-eye',
hiddenIcon: 'icon icon-eye-slash'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leaflet-html-legend",
"version": "0.2.0",
"version": "0.2.1",
"description": "Leaflet legend plugin using html elements",
"homepage": "http://github.com/consbio/Leaflet.HtmlLegend",
"author": {
Expand Down

0 comments on commit b0fd453

Please sign in to comment.