PageSourceSearch

https://visorcampoolosvalles.es/plugins/sidebarv2/js/leaflet-sidebar.js

js visorcampoolosvalles.es collected 2026-10-02 13:33:05 UTC 6,172 bytes, 199 lines download raw bytes

1L.Control.Sidebar = L.Control.extend({
2    includes: L.Mixin.Events,
3
4    options: {
5        position: 'left'
6    },
7
8    /**
9     * Create a new sidebar on this jQuery object.
10     *
11     * @constructor
12     * @param {string} id - The id of the sidebar element (without the # character)
13     * @param {Object} [options] - Optional options object
14     * @param {string} [options.position=left] - Position of the sidebar: 'left' or 'right'
15     */
16    initialize: function (id, options) {
17        var i, child;
18
19        L.setOptions(this, options);
20
21        // Find sidebar HTMLElement
22        this._sidebar = L.DomUtil.get(id);
23
24        // Attach .sidebar-left/right class
25        L.DomUtil.addClass(this._sidebar, 'sidebar-' + this.options.position);
26
27        // Attach touch styling if necessary
28        if (L.Browser.touch)
29            L.DomUtil.addClass(this._sidebar, 'leaflet-touch');
30
31        // Find sidebar > div.sidebar-content
32        for (i = this._sidebar.children.length - 1; i >= 0; i--) {
33            child = this._sidebar.children[i];
34            if (child.tagName == 'DIV' &&
35                    L.DomUtil.hasClass(child, 'sidebar-content'))
36                this._container = child;
37        }
38
39        // Find sidebar ul.sidebar-tabs > li, sidebar .sidebar-tabs > ul > li
40        this._tabitems = this._sidebar.querySelectorAll('ul.sidebar-tabs > li, .sidebar-tabs > ul > li');
41        for (i = this._tabitems.length - 1; i >= 0; i--) {
42            this._tabitems[i]._sidebar = this;
43        }
44
45        // Find sidebar > div.sidebar-content > div.sidebar-pane
46        this._panes = [];
47        this._closeButtons = [];
48        for (i = this._container.children.length - 1; i >= 0; i--) {
49            child = this._container.children[i];
50            if (child.tagName == 'DIV'  &&
51                L.DomUtil.hasClass(child, 'sidebar-pane')) {
52                this._panes.push(child);
53
54                var closeButtons = child.querySelectorAll('.sidebar-close');
55                for (var j = 0, len = closeButtons.length; j < len; j++)
56                    this._closeButtons.push(closeButtons[j]);
57            }
58        }
59    },
60
61    /**
62     * Add this sidebar to the specified map.
63     *
64     * @param {L.Map} map
65     * @returns {L.Control.Sidebar}
66     */
67    addTo: function (map) {
68        var i, child;
69
70        this._map = map;
71
72        for (i = this._tabitems.length - 1; i >= 0; i--) {
73            child = this._tabitems[i];
74            L.DomEvent
75                .on(child.querySelector('a'), 'click', L.DomEvent.preventDefault )
76                .on(child.querySelector('a'), 'click', this._onClick, child);
77        }
78
79        for (i = this._closeButtons.length - 1; i >= 0; i--) {
80            child = this._closeButtons[i];
81            L.DomEvent.on(child, 'click', this._onCloseClick, this);
82        }
83
84        return this;
85    },
86
87    /**
88     * Remove this sidebar from the map.
89     *
90     * @param {L.Map} map
91     * @returns {L.Control.Sidebar}
92     */
93    removeFrom: function (map) {
94        var i, child;
95
96        this._map = null;
97
98        for (i = this._tabitems.length - 1; i >= 0; i--) {
99            child = this._tabitems[i];
100            L.DomEvent.off(child.querySelector('a'), 'click', this._onClick);
101        }
102
103        for (i = this._closeButtons.length - 1; i >= 0; i--) {
104            child = this._closeButtons[i];
105            L.DomEvent.off(child, 'click', this._onCloseClick, this);
106        }
107
108        return this;
109    },
110
111    /**
112     * Open sidebar (if necessary) and show the specified tab.
113     *
114     * @param {string} id - The id of the tab to show (without the # character)
115     */
116    open: function(id) {
117        var i, child;
118
119        // hide old active contents and show new content
120        for (i = this._panes.length - 1; i >= 0; i--) {
121            child = this._panes[i];
122            if (child.id == id)
123                L.DomUtil.addClass(child, 'active');
124            else if (L.DomUtil.hasClass(child, 'active'))
125                L.DomUtil.removeClass(child, 'active');
126        }
127
128        // remove old active highlights and set new highlight
129        for (i = this._tabitems.length - 1; i >= 0; i--) {
130            child = this._tabitems[i];
131            if (child.querySelector('a').hash == '#' + id)
132                L.DomUtil.addClass(child, 'active');
133            else if (L.DomUtil.hasClass(child, 'active'))
134                L.DomUtil.removeClass(child, 'active');
135        }
136
137        this.fire('content', { id: id });
138
139        // open sidebar (if necessary)
140        if (L.DomUtil.hasClass(this._sidebar, 'collapsed')) {
141            this.fire('opening');
142            L.DomUtil.removeClass(this._sidebar, 'collapsed');
143        }
144
145        return this;
146    },
147
148    /**
149     * Close the sidebar (if necessary).
150     */
151    close: function() {
152        // remove old active highlights
153        for (var i = this._tabitems.length - 1; i >= 0; i--) {
154            var child = this._tabitems[i];
155            if (L.DomUtil.hasClass(child, 'active'))
156                L.DomUtil.removeClass(child, 'active');
157        }
158
159        // close sidebar
160        if (!L.DomUtil.hasClass(this._sidebar, 'collapsed')) {
161            this.fire('closing');
162            L.DomUtil.addClass(this._sidebar, 'collapsed');
163        }
164
165        return this;
166    },
167
168    /**
169     * @private
170     */
171    _onClick: function() {
172        if (L.DomUtil.hasClass(this, 'active'))
173            this._sidebar.close();
174        else if (!L.DomUtil.hasClass(this, 'disabled'))
175            this._sidebar.open(this.querySelector('a').hash.slice(1));
176    },
177
178    /**
179     * @private
180     */
181    _onCloseClick: function () {
182        this.close();
183    }
184});
185
186/**
187 * Create a new sidebar on this jQuery object.
188 *
189 * @example
190 * var sidebar = L.control.sidebar('sidebar').addTo(map);
191 *
192 * @param {string} id - The id of the sidebar element (without the # character)
193 * @param {Object} [options] - Optional options object
194 * @param {string} [options.position=left] - Position of the sidebar: 'left' or 'right'
195 * @returns {L.Control.Sidebar} A new sidebar instance
196 */
197L.control.sidebar = function (id, options) {
198    return new L.Control.Sidebar(id, options);
199};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.