| 1 |
/*! |
| 2 |
* Based on package 'screenfull' |
| 3 |
* v5.2.0 - 2021-11-03 |
| 4 |
* (c) Sindre Sorhus; MIT License |
| 5 |
* Added definition for using screenfull as an amd module |
| 6 |
* Must be placed before the definition of leaflet.fullscreen |
| 7 |
* as it is required by that |
| 8 |
*/ |
| 9 |
(function (root, factory) { |
| 10 |
if (typeof define === 'function' && define.amd) { |
| 11 |
define('screenfull', factory); |
| 12 |
} else if (typeof module === 'object' && module.exports) { |
| 13 |
module.exports.screenfull = factory(); |
| 14 |
} else { |
| 15 |
// Save 'screenfull' into global window variable |
| 16 |
root.screenfull = factory(); |
| 17 |
} |
| 18 |
}(typeof self !== 'undefined' ? self : this, function () { |
| 19 |
'use strict'; |
| 20 |
|
| 21 |
var document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {}; |
| 22 |
|
| 23 |
var fn = (function () { |
| 24 |
var val; |
| 25 |
|
| 26 |
var fnMap = [ |
| 27 |
[ |
| 28 |
'requestFullscreen', |
| 29 |
'exitFullscreen', |
| 30 |
'fullscreenElement', |
| 31 |
'fullscreenEnabled', |
| 32 |
'fullscreenchange', |
| 33 |
'fullscreenerror' |
| 34 |
], |
| 35 |
// New WebKit |
| 36 |
[ |
| 37 |
'webkitRequestFullscreen', |
| 38 |
'webkitExitFullscreen', |
| 39 |
'webkitFullscreenElement', |
| 40 |
'webkitFullscreenEnabled', |
| 41 |
'webkitfullscreenchange', |
| 42 |
'webkitfullscreenerror' |
| 43 |
|
| 44 |
], |
| 45 |
// Old WebKit |
| 46 |
[ |
| 47 |
'webkitRequestFullScreen', |
| 48 |
'webkitCancelFullScreen', |
| 49 |
'webkitCurrentFullScreenElement', |
| 50 |
'webkitCancelFullScreen', |
| 51 |
'webkitfullscreenchange', |
| 52 |
'webkitfullscreenerror' |
| 53 |
|
| 54 |
], |
| 55 |
[ |
| 56 |
'mozRequestFullScreen', |
| 57 |
'mozCancelFullScreen', |
| 58 |
'mozFullScreenElement', |
| 59 |
'mozFullScreenEnabled', |
| 60 |
'mozfullscreenchange', |
| 61 |
'mozfullscreenerror' |
| 62 |
], |
| 63 |
[ |
| 64 |
'msRequestFullscreen', |
| 65 |
'msExitFullscreen', |
| 66 |
'msFullscreenElement', |
| 67 |
'msFullscreenEnabled', |
| 68 |
'MSFullscreenChange', |
| 69 |
'MSFullscreenError' |
| 70 |
] |
| 71 |
]; |
| 72 |
|
| 73 |
var i = 0; |
| 74 |
var l = fnMap.length; |
| 75 |
var ret = {}; |
| 76 |
|
| 77 |
for (; i < l; i++) { |
| 78 |
val = fnMap[i]; |
| 79 |
if (val && val[1] in document) { |
| 80 |
for (i = 0; i < val.length; i++) { |
| 81 |
ret[fnMap[0][i]] = val[i]; |
| 82 |
} |
| 83 |
return ret; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return false; |
| 88 |
})(); |
| 89 |
|
| 90 |
var eventNameMap = { |
| 91 |
change: fn.fullscreenchange, |
| 92 |
error: fn.fullscreenerror |
| 93 |
}; |
| 94 |
|
| 95 |
var screenfull = { |
| 96 |
request: function (element, options) { |
| 97 |
return new Promise(function (resolve, reject) { |
| 98 |
var onFullScreenEntered = function () { |
| 99 |
this.off('change', onFullScreenEntered); |
| 100 |
resolve(); |
| 101 |
}.bind(this); |
| 102 |
|
| 103 |
this.on('change', onFullScreenEntered); |
| 104 |
|
| 105 |
element = element || document.documentElement; |
| 106 |
|
| 107 |
var returnPromise = element[fn.requestFullscreen](options); |
| 108 |
|
| 109 |
if (returnPromise instanceof Promise) { |
| 110 |
returnPromise.then(onFullScreenEntered).catch(reject); |
| 111 |
} |
| 112 |
}.bind(this)); |
| 113 |
}, |
| 114 |
exit: function () { |
| 115 |
return new Promise(function (resolve, reject) { |
| 116 |
if (!this.isFullscreen) { |
| 117 |
resolve(); |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
var onFullScreenExit = function () { |
| 122 |
this.off('change', onFullScreenExit); |
| 123 |
resolve(); |
| 124 |
}.bind(this); |
| 125 |
|
| 126 |
this.on('change', onFullScreenExit); |
| 127 |
|
| 128 |
var returnPromise = document[fn.exitFullscreen](); |
| 129 |
|
| 130 |
if (returnPromise instanceof Promise) { |
| 131 |
returnPromise.then(onFullScreenExit).catch(reject); |
| 132 |
} |
| 133 |
}.bind(this)); |
| 134 |
}, |
| 135 |
toggle: function (element, options) { |
| 136 |
return this.isFullscreen ? this.exit() : this.request(element, options); |
| 137 |
}, |
| 138 |
onchange: function (callback) { |
| 139 |
this.on('change', callback); |
| 140 |
}, |
| 141 |
onerror: function (callback) { |
| 142 |
this.on('error', callback); |
| 143 |
}, |
| 144 |
on: function (event, callback) { |
| 145 |
var eventName = eventNameMap[event]; |
| 146 |
if (eventName) { |
| 147 |
document.addEventListener(eventName, callback, false); |
| 148 |
} |
| 149 |
}, |
| 150 |
off: function (event, callback) { |
| 151 |
var eventName = eventNameMap[event]; |
| 152 |
if (eventName) { |
| 153 |
document.removeEventListener(eventName, callback, false); |
| 154 |
} |
| 155 |
}, |
| 156 |
raw: fn |
| 157 |
}; |
| 158 |
|
| 159 |
if (!fn) { |
| 160 |
return {isEnabled: false}; |
| 161 |
} else { |
| 162 |
Object.defineProperties(screenfull, { |
| 163 |
isFullscreen: { |
| 164 |
get: function () { |
| 165 |
return Boolean(document[fn.fullscreenElement]); |
| 166 |
} |
| 167 |
}, |
| 168 |
element: { |
| 169 |
enumerable: true, |
| 170 |
get: function () { |
| 171 |
return document[fn.fullscreenElement]; |
| 172 |
} |
| 173 |
}, |
| 174 |
isEnabled: { |
| 175 |
enumerable: true, |
| 176 |
get: function () { |
| 177 |
// Coerce to boolean in case of old WebKit |
| 178 |
return Boolean(document[fn.fullscreenEnabled]); |
| 179 |
} |
| 180 |
} |
| 181 |
}); |
| 182 |
return screenfull; |
| 183 |
} |
| 184 |
})); |
| 185 |
|
| 186 |
/*! |
| 187 |
* leaflet.fullscreen |
| 188 |
*/ |
| 189 |
(function (root, factory) { |
| 190 |
if (typeof define === 'function' && define.amd) { |
| 191 |
// define an AMD module that requires 'leaflet' and 'screenfull' |
| 192 |
// and resolve to an object containing leaflet and screenfull |
| 193 |
define('leafletFullScreen', ['leaflet', 'screenfull'], factory); |
| 194 |
} else if (typeof module === 'object' && module.exports) { |
| 195 |
// define a CommonJS module that requires 'leaflet' and 'screenfull' |
| 196 |
module.exports = factory(require('leaflet'), require('screenfull')); |
| 197 |
} else { |
| 198 |
// Assume 'leaflet' and 'screenfull' are loaded into global variable already |
| 199 |
factory(root.L, root.screenfull); |
| 200 |
} |
| 201 |
}(typeof self !== 'undefined' ? self : this, function (leaflet, screenfull) { |
| 202 |
'use strict'; |
| 203 |
|
| 204 |
leaflet.Control.FullScreen = leaflet.Control.extend({ |
| 205 |
options: { |
| 206 |
position: 'topleft', |
| 207 |
title: 'Full Screen', |
| 208 |
titleCancel: 'Exit Full Screen', |
| 209 |
forceSeparateButton: false, |
| 210 |
forcePseudoFullscreen: false, |
| 211 |
fullscreenElement: false |
| 212 |
}, |
| 213 |
|
| 214 |
_screenfull: screenfull, |
| 215 |
|
| 216 |
onAdd: function (map) { |
| 217 |
var className = 'leaflet-control-zoom-fullscreen', container, content = ''; |
| 218 |
|
| 219 |
if (map.zoomControl && !this.options.forceSeparateButton) { |
| 220 |
container = map.zoomControl._container; |
| 221 |
} else { |
| 222 |
container = leaflet.DomUtil.create('div', 'leaflet-bar'); |
| 223 |
} |
| 224 |
|
| 225 |
if (this.options.content) { |
| 226 |
content = this.options.content; |
| 227 |
} else { |
| 228 |
className += ' fullscreen-icon'; |
| 229 |
} |
| 230 |
|
| 231 |
this._createButton(this.options.title, className, content, container, this.toggleFullScreen, this); |
| 232 |
this._map.fullscreenControl = this; |
| 233 |
|
| 234 |
this._map.on('enterFullscreen exitFullscreen', this._toggleState, this); |
| 235 |
|
| 236 |
return container; |
| 237 |
}, |
| 238 |
|
| 239 |
onRemove: function () { |
| 240 |
leaflet.DomEvent |
| 241 |
.off(this.link, 'click', leaflet.DomEvent.stop) |
| 242 |
.off(this.link, 'click', this.toggleFullScreen, this); |
| 243 |
|
| 244 |
if (this._screenfull.isEnabled) { |
| 245 |
leaflet.DomEvent |
| 246 |
.off(this._container, this._screenfull.raw.fullscreenchange, leaflet.DomEvent.stop) |
| 247 |
.off(this._container, this._screenfull.raw.fullscreenchange, this._handleFullscreenChange, this); |
| 248 |
|
| 249 |
leaflet.DomEvent |
| 250 |
.off(document, this._screenfull.raw.fullscreenchange, leaflet.DomEvent.stop) |
| 251 |
.off(document, this._screenfull.raw.fullscreenchange, this._handleFullscreenChange, this); |
| 252 |
} |
| 253 |
}, |
| 254 |
|
| 255 |
_createButton: function (title, className, content, container, fn, context) { |
| 256 |
this.link = leaflet.DomUtil.create('a', className, container); |
| 257 |
this.link.href = '#'; |
| 258 |
this.link.title = title; |
| 259 |
this.link.innerHTML = content; |
| 260 |
|
| 261 |
this.link.setAttribute('role', 'button'); |
| 262 |
this.link.setAttribute('aria-label', title); |
| 263 |
|
| 264 |
L.DomEvent.disableClickPropagation(container); |
| 265 |
|
| 266 |
leaflet.DomEvent |
| 267 |
.on(this.link, 'click', leaflet.DomEvent.stop) |
| 268 |
.on(this.link, 'click', fn, context); |
| 269 |
|
| 270 |
if (this._screenfull.isEnabled) { |
| 271 |
leaflet.DomEvent |
| 272 |
.on(container, this._screenfull.raw.fullscreenchange, leaflet.DomEvent.stop) |
| 273 |
.on(container, this._screenfull.raw.fullscreenchange, this._handleFullscreenChange, context); |
| 274 |
|
| 275 |
leaflet.DomEvent |
| 276 |
.on(document, this._screenfull.raw.fullscreenchange, leaflet.DomEvent.stop) |
| 277 |
.on(document, this._screenfull.raw.fullscreenchange, this._handleFullscreenChange, context); |
| 278 |
} |
| 279 |
|
| 280 |
return this.link; |
| 281 |
}, |
| 282 |
|
| 283 |
toggleFullScreen: function () { |
| 284 |
var map = this._map; |
| 285 |
map._exitFired = false; |
| 286 |
if (map._isFullscreen) { |
| 287 |
if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) { |
| 288 |
this._screenfull.exit(); |
| 289 |
} else { |
| 290 |
leaflet.DomUtil.removeClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen'); |
| 291 |
map.invalidateSize(); |
| 292 |
} |
| 293 |
map.fire('exitFullscreen'); |
| 294 |
map._exitFired = true; |
| 295 |
map._isFullscreen = false; |
| 296 |
} |
| 297 |
else { |
| 298 |
if (this._screenfull.isEnabled && !this.options.forcePseudoFullscreen) { |
| 299 |
this._screenfull.request(this.options.fullscreenElement ? this.options.fullscreenElement : map._container); |
| 300 |
} else { |
| 301 |
leaflet.DomUtil.addClass(this.options.fullscreenElement ? this.options.fullscreenElement : map._container, 'leaflet-pseudo-fullscreen'); |
| 302 |
map.invalidateSize(); |
| 303 |
} |
| 304 |
map.fire('enterFullscreen'); |
| 305 |
map._isFullscreen = true; |
| 306 |
} |
| 307 |
}, |
| 308 |
|
| 309 |
_toggleState: function () { |
| 310 |
this.link.title = this._map._isFullscreen ? this.options.title : this.options.titleCancel; |
| 311 |
this._map._isFullscreen ? L.DomUtil.removeClass(this.link, 'leaflet-fullscreen-on') : L.DomUtil.addClass(this.link, 'leaflet-fullscreen-on'); |
| 312 |
}, |
| 313 |
|
| 314 |
_handleFullscreenChange: function () { |
| 315 |
var map = this._map; |
| 316 |
map.invalidateSize(); |
| 317 |
if (!this._screenfull.isFullscreen && !map._exitFired) { |
| 318 |
map.fire('exitFullscreen'); |
| 319 |
map._exitFired = true; |
| 320 |
map._isFullscreen = false; |
| 321 |
} |
| 322 |
} |
| 323 |
}); |
| 324 |
|
| 325 |
leaflet.Map.include({ |
| 326 |
toggleFullscreen: function () { |
| 327 |
this.fullscreenControl.toggleFullScreen(); |
| 328 |
} |
| 329 |
}); |
| 330 |
|
| 331 |
leaflet.Map.addInitHook(function () { |
| 332 |
if (this.options.fullscreenControl) { |
| 333 |
this.addControl(leaflet.control.fullscreen(this.options.fullscreenControlOptions)); |
| 334 |
} |
| 335 |
}); |
| 336 |
|
| 337 |
leaflet.control.fullscreen = function (options) { |
| 338 |
return new leaflet.Control.FullScreen(options); |
| 339 |
}; |
| 340 |
|
| 341 |
// must return an object containing also screenfull to make screenfull |
| 342 |
// available outside of this package, if used as an amd module, |
| 343 |
// as webpack cannot handle amd define with moduleid |
| 344 |
return {leaflet: leaflet, screenfull: screenfull}; |
| 345 |
})); |
| 346 |
|