1/*!_map 2* leaflet.fullscreen 3* (c) Bruno B.; MIT License 4* Uses fragments from the package 'screenfull' 5*/ 6(function (root, factory) { 7 if (typeof define === 'function' && define.amd) { 8 // define an AMD module that requires 'leaflet' 9 // and resolve to an object containing leaflet 10 define('leafletFullScreen', ['leaflet'], factory); 11 } else if (typeof module === 'object' && module.exports) { 12 // define a CommonJS module that requires 'leaflet' 13 module.exports = factory(require('leaflet')); 14 } else { 15 // Assume 'leaflet' are loaded into global variable already 16 factory(root.L); 17 } 18}(typeof self !== 'undefined' ? self : this, function (leaflet) { 19 'use strict'; 20 21 if (typeof document === 'undefined') { 22 console.warn('"window.document" is undefined; leaflet.fullscreen requires this object to access the DOM'); 23 return false; 24 } 25 26 const nativeAPI = (() => { 27 const methodMap = [ 28 // Standard 29 [ 30 'requestFullscreen', 31 'exitFullscreen', 32 'fullscreenElement', 33 'fullscreenEnabled', 34 'fullscreenchange', 35 'fullscreenerror' 36 ], 37 // New WebKit 38 [ 39 'webkitRequestFullscreen', 40 'webkitExitFullscreen', 41 'webkitFullscreenElement', 42 'webkitFullscreenEnabled', 43 'webkitfullscreenchange', 44 'webkitfullscreenerror' 45 ] 46 ]; 47 48 const baseList = methodMap[0]; 49 const ret = {}; 50 51 for (const methodList of methodMap) { 52 if (methodList[1] in document) { 53 for (let i = 0; i < methodList.length; i++) { 54 ret[baseList[i]] = methodList[i]; 55 } 56 return ret; 57 } 58 } 59 60 return false; 61 })(); 62 63 const eventNameMap = { 64 change: nativeAPI.fullscreenchange, 65 error: nativeAPI.fullscreenerror, 66 }; 67 68 const fullscreenAPI = { 69 request: function (element, options) { 70 return new Promise(function (resolve, reject) { 71 const onFullScreenEntered = function () { 72 this.off('change', onFullScreenEntered); 73 resolve(); 74 }.bind(this); 75 76 this.on('change', onFullScreenEntered); 77 element = element || document.documentElement; 78 const returnPromise = element[nativeAPI.requestFullscreen](options); 79 if (returnPromise instanceof Promise) { 80 returnPromise.then(onFullScreenEntered).catch(reject); 81 } 82 }.bind(this)); 83 }, 84 exit: function () { 85 return new Promise(function (resolve, reject) { 86 if (!this.isFullscreen) { 87 resolve(); 88 return; 89 } 90 91 const onFullScreenExit = function () { 92 this.off('change', onFullScreenExit); 93 resolve(); 94 }.bind(this); 95 96 this.on('change', onFullScreenExit); 97 const returnPromise = document[nativeAPI.exitFullscreen](); 98 if (returnPromise instanceof Promise) { 99 returnPromise.then(onFullScreenExit).catch(reject); 100 } 101 }.bind(this)); 102 }, 103 on: function (event, callback) { 104 var eventName = eventNameMap[event]; 105 if (eventName) { 106 document.addEventListener(eventName, callback, false); 107 } 108 }, 109 off: function (event, callback) { 110 var eventName = eventNameMap[event]; 111 if (eventName) { 112 document.removeEventListener(eventName, callback, false); 113 } 114 }, 115 nativeAPI: nativeAPI 116}; 117 118 Object.defineProperties(fullscreenAPI, { 119 isFullscreen: { 120 get: function () { 121 return Boolean(document[nativeAPI.fullscreenElement]); 122 } 123 }, 124 isEnabled: { 125 enumerable: true, 126 get: function () { 127 // Coerce to boolean in case of old WebKit 128 return Boolean(document[nativeAPI.fullscreenEnabled]); 129 } 130 } 131 }); 132 133 leaflet.Control.FullScreen = leaflet.Control.extend({ 134 options: { 135 position: 'topleft', 136 title: 'Full Screen', 137 titleCancel: 'Exit Full Screen',
138 forceSeparateButton: false, 139 forcePseudoFullscreen: false, 140 fullscreenElement: false 141 }, 142 143 _screenfull: fullscreenAPI, 144 145 onAdd: function (map) { 146 var className = 'leaflet-control-zoom-fullscreen', container, content = ''; 147 148 if (map.zoomControl && !this.options.forceSeparateButton) { 149 container = map.zoomControl._container; 150 } else { 151 container = leaflet.DomUtil.create('div', 'leaflet-bar'); 152 } 153 154 if (this.options.content) { 155 content = this.options.content; 156 } else { 157 className += ' fullscreen-icon'; 158 } 159 160 this._createButton(this.options.title, className, content, container, this.toggleFullScreen, this); 161 this._map.fullscreenControl = this; 162 163 this._map.on('enterFullscreen exitFullscreen', this._toggleState, this); 164 165 return container; 166 }, 167 168 onRemove: function () { 169 leaflet.DomEvent 170 .off(this.link, 'click', leaflet.DomEvent.stop) 171 .off(this.link, 'click', this.toggleFullScreen, this); 172 173 if (this._screenfull.isEnabled) { 174 leaflet.DomEvent 175 .off(this._container, this._screenfull.nativeAPI.fullscreenchange, leaflet.DomEvent.stop) 176 .off(this._container, this._screenfull.nativeAPI.fullscreenchange, this._handleFullscreenChange, this); 177 178 leaflet.DomEvent 179 .off(document, this._screenfull.nativeAPI.fullscreenchange, leaflet.DomEvent.stop) 180 .off(document, this._screenfull.nativeAPI.fullscreenchange, this._handleFullscreenChange, this); 181 } 182 }, 183 184 _createButton: function (title, className, content, container, fn, context) { 185 this.link = leaflet.DomUtil.create('a', className, container); 186 this.link.href = '#'; 187 this.link.title = title; 188 this.link.innerHTML = content; 189 190 this.link.setAttribute('role', 'button'); 191 this.link.setAttribute('aria-label', title); 192 193 L.DomEvent.disableClickPropagation(container); 194 195 leaflet.DomEvent 196 .on(this.link, 'click', leaflet.DomEvent.stop) 197 .on(this.link, 'click', fn, context); 198 199 if (this._screenfull.isEnabled) { 200 leaflet.DomEvent 201 .on(container, this._screenfull.nativeAPI.fullscreenchange, leaflet.DomEvent.stop) 202 .on(container, this._screenfull.nativeAPI.fullscreenchange, this._handleFullscreenChange, context); 203 204 leaflet.DomEvent 205 .on(document, this._screenfull.nativeAPI.fullscreenchange, leaflet.DomEvent.stop) 206 .on(document, this._screenfull.nativeAPI.fullscreenchange, this._handleFullscreenChange, context); 207 } 208 209 return this.link; 210 }, 211 212 toggleFullScreen: function () { 213 var map = this._map; 214 map._exitFired = false; 215 if (map._isFullscreen) { 216 if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) { 217 this._screenfull.exit(); 218 } else { 219 leaflet.DomUtil.removeClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen'); 220 map.invalidateSize(); 221 } 222 map.fire('exitFullscreen'); 223 map._exitFired = true; 224 map._isFullscreen = false; 225 } 226 else { 227 if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) { 228 this._screenfull.request(this.options.fullscreenElement ? this.options.fullscreenElement : map._container); 229 } else { 230 leaflet.DomUtil.addClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen'); 231 map.invalidateSize(); 232 } 233 map.fire('enterFullscreen'); 234 map._isFullscreen = true; 235 } 236 }, 237 238 _toggleState: function () { 239 this.link.title = this._map._isFullscreen ? this.options.title : this.options.titleCancel; 240 this._map._isFullscreen ? L.DomUtil.removeClass(this.link, 'leaflet-fullscreen-on') : L.DomUtil.addClass(this.link, 'leaflet-fullscreen-on'); 241 }, 242 243 _handleFullscreenChange: function (ev) { 244 var map = this._map; 245 if (ev.target === map.getContainer() && !this._screenfull.isFullscreen && !map._exitFired) { 246 map.invalidateSize(); 247 map.fire('exitFullscreen'); 248 map._exitFired = true; 249 map._isFullscreen = false; 250 } 251 } 252 }); 253 254 leaflet.Map.include({ 255 toggleFullscreen: function () { 256 this.fullscreenControl.toggleFullScreen(); 257 } 258 }); 259 260 leaflet.Map.addInitHook(function () { 261 if (this.options.fullscreenControl) { 262 this.addControl(leaflet.control.fullscreen(this.options.fullscreenControlOptions)); 263 } 264 }); 265 266 leaflet.control.fullscreen = function (options) { 267 return new leaflet.Control.FullScreen(options); 268 }; 269 270 return {leaflet: leaflet}; 271}));
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.