1(function () { 2 L.Control.EasyBar = L.Control.extend({ 3 options: { 4 position: 'topleft', 5 id: null, 6 leafletClasses: true 7 }, 8 initialize: function (buttons, options) { 9 if (options) { 10 L.Util.setOptions(this, options); 11 } 12 this._buildContainer(); 13 this._buttons = []; 14 for (var i = 0; i < buttons.length; i++) { 15 buttons[i]._bar = this; 16 buttons[i]._container = buttons[i].button; 17 this._buttons.push(buttons[i]); 18 this.container.appendChild(buttons[i].button); 19 } 20 }, 21 _buildContainer: function () { 22 this._container = this.container = L.DomUtil.create('div', ''); 23 this.options.leafletClasses && L.DomUtil.addClass(this.container, 'leaflet-bar easy-button-container leaflet-control'); 24 this.options.id && (this.container.id = this.options.id); 25 }, 26 enable: function () { 27 L.DomUtil.addClass(this.container, 'enabled'); 28 L.DomUtil.removeClass(this.container, 'disabled'); 29 this.container.setAttribute('aria-hidden', 'false'); 30 return this; 31 }, 32 disable: function () { 33 L.DomUtil.addClass(this.container, 'disabled'); 34 L.DomUtil.removeClass(this.container, 'enabled'); 35 this.container.setAttribute('aria-hidden', 'true'); 36 return this; 37 }, 38 onAdd: function () { 39 return this.container; 40 }, 41 addTo: function (map) { 42 this._map = map; 43 for (var i = 0; i < this._buttons.length; i++) { 44 this._buttons[i]._map = map; 45 } 46 var container = this._container = this.onAdd(map), 47 pos = this.getPosition(), 48 corner = map._controlCorners[pos]; 49 L.DomUtil.addClass(container, 'leaflet-control'); 50 if (pos.indexOf('bottom') !== -1) { 51 corner.insertBefore(container, corner.firstChild); 52 } else { 53 corner.appendChild(container); 54 } 55 return this; 56 } 57 }); 58 L.easyBar = function () { 59 var args = [L.Control.EasyBar]; 60 for (var i = 0; i < arguments.length; i++) { 61 args.push(arguments[i]); 62 } 63 return new (Function.prototype.bind.apply(L.Control.EasyBar, args)); 64 }; 65 L.Control.EasyButton = L.Control.extend({ 66 options: { 67 position: 'topleft', 68 id: null, 69 type: 'replace', 70 states: [], 71 leafletClasses: true, 72 tagName: 'button', 73 }, 74 initialize: function (icon, onClick, title, id) { 75 this.options.states = []; 76 if (id != null) { 77 this.options.id = id; 78 } 79 this.storage = {}; 80 if (typeof arguments[arguments.length - 1] === 'object') { 81 L.Util.setOptions(this, arguments[arguments.length - 1]); 82 } 83 if (this.options.states.length === 0 && 84 typeof icon === 'string' && 85 typeof onClick === 'function') { 86 this.options.states.push({ 87 icon: icon, 88 onClick: onClick, 89 title: typeof title === 'string' ? title : '' 90 }); 91 } 92 this._states = []; 93 for (var i = 0; i < this.options.states.length; i++) { 94 this._states.push(new State(this.options.states[i], this)); 95 } 96 this._buildButton(); 97 this._activateState(this._states[0]); 98 }, 99 _buildButton: function () { 100 this.button = L.DomUtil.create(this.options.tagName, ''); 101 if (this.options.tagName === 'button') { 102 this.button.setAttribute('type', 'button'); 103 } 104 if (this.options.id) { 105 this.button.id = this.options.id; 106 } 107 if (this.options.leafletClasses) { 108 L.DomUtil.addClass(this.button, 'easy-button-button leaflet-bar-part leaflet-interactive'); 109 } 110 L.DomEvent.addListener(this.button, 'dblclick', L.DomEvent.stop); 111 L.DomEvent.addListener(this.button, 'mousedown', L.DomEvent.stop); 112 L.DomEvent.addListener(this.button, 'mouseup', L.DomEvent.stop); 113 L.DomEvent.addListener(this.button, 'click', function (e) { 114 L.DomEvent.stop(e); 115 this._currentState.onClick(this, this._map ? this._map : null); 116 this._map && this._map.getContainer().focus(); 117 }, this); 118 if (this.options.type == 'replace') { 119 this.button.appendChild(this._currentState.icon); 120 } else { 121 for (var i = 0; i < this._states.length; i++) { 122 this.button.appendChild(this._states[i].icon); 123 } 124 } 125 }, 126 _currentState: { 127 stateName: 'unnamed', 128 icon: (function () { return document.createElement('span'); })() 129 }, 130 _states: null, 131 state: function (newState) { 132 if (typeof newState == 'string') { 133 this._activateStateNamed(newState); 134 } else if (typeof newState == 'number') { 135 this._activateState(this._states[newState]); 136 } 137 return this; 138 }, 139 _activateStateNamed: function (stateName) { 140 for (var i = 0; i < this._states.length; i++) { 141 if (this._states[i].stateName == stateName) { 142 this._activateState(this._states[i]); 143 } 144 } 145 }, 146 _activateState: function (newState) { 147 if (newState === this._currentState) { 148 return; 149 } else { 150 if (this.options.type == 'replace') { 151 this.button.appendChild(newState.icon); 152 this.button.removeChild(this._currentState.icon); 153 } 154 if (newState.title) { 155 this.button.title = newState.title; 156 } else { 157 this.button.removeAttribute('title'); 158 } 159 for (var i = 0; i < this._states.length; i++) { 160 L.DomUtil.removeClass(this._states[i].icon, this._currentState.stateName + '-active'); 161 L.DomUtil.addClass(this._states[i].icon, newState.stateName + '-active'); 162 } 163 L.DomUtil.removeClass(this.button, this._currentState.stateName + '-active'); 164 L.DomUtil.addClass(this.button, newState.stateName + '-active'); 165 this._currentState = newState; 166 } 167 }, 168 enable: function () { 169 L.DomUtil.addClass(this.button, 'enabled'); 170 L.DomUtil.removeClass(this.button, 'disabled'); 171 this.button.setAttribute('aria-hidden', 'false'); 172 return this; 173 }, 174 disable: function () { 175 L.DomUtil.addClass(this.button, 'disabled'); 176 L.DomUtil.removeClass(this.button, 'enabled'); 177 this.button.setAttribute('aria-hidden', 'true'); 178 return this; 179 }, 180 onAdd: function (map) { 181 var bar = L.easyBar([this], { 182 position: this.options.position, 183 leafletClasses: this.options.leafletClasses 184 }); 185 this._anonymousBar = bar; 186 this._container = bar.container; 187 return this._anonymousBar.container; 188 }, 189 removeFrom: function (map) { 190 if (this._map === map) 191 this.remove(); 192 return this; 193 }, 194 }); 195 L.easyButton = function () { 196 var args = Array.prototype.concat.apply([L.Control.EasyButton], arguments); 197 return new (Function.prototype.bind.apply(L.Control.EasyButton, args)); 198 }; 199 function State(template, easyButton) { 200 this.title = template.title; 201 this.stateName = template.stateName ? template.stateName : 'unnamed-state'; 202 this.icon = L.DomUtil.create('span', ''); 203 L.DomUtil.addClass(this.icon, 'button-state state-' + this.stateName.replace(/(^\s*|\s*$)/g, '')); 204 this.icon.innerHTML = buildIcon(template.icon); 205 this.onClick = L.Util.bind(template.onClick ? template.onClick : function () { }, easyButton); 206 }
207 function buildIcon(ambiguousIconString) { 208 var tmpIcon; 209 if (ambiguousIconString.match(/[&;=<>"']/)) { 210 tmpIcon = ambiguousIconString; 211 } else { 212 ambiguousIconString = ambiguousIconString.replace(/(^\s*|\s*$)/g, ''); 213 tmpIcon = L.DomUtil.create('span', ''); 214 if (ambiguousIconString.indexOf('fa-') === 0) { 215 L.DomUtil.addClass(tmpIcon, 'fa ' + ambiguousIconString) 216 } else if (ambiguousIconString.indexOf('glyphicon-') === 0) { 217 L.DomUtil.addClass(tmpIcon, 'glyphicon ' + ambiguousIconString) 218 } else { 219 L.DomUtil.addClass(tmpIcon, ambiguousIconString) 220 } 221 tmpIcon = tmpIcon.outerHTML; 222 } 223 return tmpIcon; 224 } 225})();
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.