summaryrefslogtreecommitdiffstats
path: root/public/js/vendor/leaflet.spin.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:24:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:24:14 +0000
commita58a146ad5cc0079fd68431cd679943f933e35a4 (patch)
tree91608c01e82676102457ffff2219f321ec474657 /public/js/vendor/leaflet.spin.js
parentInitial commit. (diff)
downloadicingaweb2-module-map-a58a146ad5cc0079fd68431cd679943f933e35a4.tar.xz
icingaweb2-module-map-a58a146ad5cc0079fd68431cd679943f933e35a4.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'public/js/vendor/leaflet.spin.js')
-rw-r--r--public/js/vendor/leaflet.spin.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/public/js/vendor/leaflet.spin.js b/public/js/vendor/leaflet.spin.js
new file mode 100644
index 0000000..25a3996
--- /dev/null
+++ b/public/js/vendor/leaflet.spin.js
@@ -0,0 +1,69 @@
+(function (factory, window) {
+ // define an AMD module that relies on 'leaflet'
+ if (typeof define === 'function' && define.amd) {
+ define(['leaflet'], function (L) {
+ factory(L);
+ });
+
+ // define a Common JS module that relies on 'leaflet'
+ } else if (typeof exports === 'object') {
+ module.exports = function (L) {
+ if (L === undefined) {
+ L = require('leaflet');
+ }
+ factory(L);
+ return L;
+ };
+ // attach your plugin to the global 'L' variable
+ } else if (typeof window !== 'undefined' && window.L) {
+ factory(window.L);
+ }
+}(function leafletSpinFactory(L) {
+ var SpinMapMixin = {
+ spin: function (state, options) {
+ if (!!state) {
+ // start spinning !
+ if (!this._spinner) {
+ this._spinner = new Spinner(options)
+ .spin(this._container);
+ this._spinning = 0;
+ }
+ this._spinning++;
+ }
+ else {
+ this._spinning--;
+ if (this._spinning <= 0) {
+ // end spinning !
+ if (this._spinner) {
+ this._spinner.stop();
+ this._spinner = null;
+ }
+ }
+ }
+ }
+ };
+
+ var SpinMapInitHook = function () {
+ this.on('layeradd', function (e) {
+ // If added layer is currently loading, spin !
+ if (e.layer.loading) this.spin(true);
+ if (typeof e.layer.on !== 'function') return;
+ e.layer.on('data:loading', function () {
+ this.spin(true);
+ }, this);
+ e.layer.on('data:loaded', function () {
+ this.spin(false);
+ }, this);
+ }, this);
+ this.on('layerremove', function (e) {
+ // Clean-up
+ if (e.layer.loading) this.spin(false);
+ if (typeof e.layer.on !== 'function') return;
+ e.layer.off('data:loaded');
+ e.layer.off('data:loading');
+ }, this);
+ };
+
+ L.Map.include(SpinMapMixin);
+ L.Map.addInitHook(SpinMapInitHook);
+}, window));