L.Control.Base64Legend.js
function () {
        L.DomUtil.empty(this._container);
        var legends = this.options.legends;

        if (!legends) return;

        legends.forEach(function(legend) {
            if (!legend.elements) return;
            var elements = legend.elements;

            var className = 'legend-block';

            if (this.options.detectStretched) {
                if (elements.length === 3  && elements[0].label !== '' && elements[1].label === '' && elements[2].label !== ''){
                    legend.type = 'stretched';
                }
            }

            if (legend.type === 'stretched') {
                className += ' legend-stretched';
            }

            var block = L.DomUtil.create('div', className, this._container);

            if (this.options.collapseSimple && elements.length == 1 && !elements[0].label){
                this._addElement(elements[0].imageData, legend.name, block);
                return;
            }

            if (legend.name) {
                var header = L.DomUtil.create('h4', null, block);
                L.DomUtil.create('div', 'caret', header);
                L.DomUtil.create('span', null, header).innerHTML = legend.name;

                L.DomEvent.on(header, 'click', function() {
                    if (L.DomUtil.hasClass(header, 'closed')) {
                        L.DomUtil.removeClass(header, 'closed');
                    }
                    else {
                        L.DomUtil.addClass(header, 'closed');
                    }
                }, this);
            }
            var elementContainer = L.DomUtil.create('div', 'legend-elements', block);

            elements.forEach(function (element) {
                this._addElement(element.imageData, element.label, elementContainer);
            }, this);
        }, this);
    }
function () {
        L.DomUtil.empty(this._container);
        var legends = this.options.legends;

        if (!legends) return;

        legends.forEach(function(legend) {
            if (!legend.elements) return;
            var elements = legend.elements;

            var className = 'legend-block';

            if (this.options.detectStretched) {
                if (elements.length === 3  && elements[0].label !== '' && elements[1].label === '' && elements[2].label !== ''){
                    legend.type = 'stretched';
                }
            }

            if (legend.type === 'stretched') {
                className += ' legend-stretched';
            }

            var block = L.DomUtil.create('div', className, this._container);

            if (this.options.collapseSimple && elements.length == 1 && !elements[0].label){
                this._addElement(elements[0].imageData, legend.name, block);
                return;
            }

            if (legend.name) {
                var header = L.DomUtil.create('h4', null, block);
                L.DomUtil.create('div', 'caret', header);
                L.DomUtil.create('span', null, header).innerHTML = legend.name;

                L.DomEvent.on(header, 'click', function() {
                    if (L.DomUtil.hasClass(header, 'closed')) {
                        L.DomUtil.removeClass(header, 'closed');
                    }
                    else {
                        L.DomUtil.addClass(header, 'closed');
                    }
                }, this);
            }
            var elementContainer = L.DomUtil.create('div', 'legend-elements', block);

            elements.forEach(function (element) {
                this._addElement(element.imageData, element.label, elementContainer);
            }, this);
        }, this);
    }
render this.options.entries