Files
contao-leaflet-libraries/assets/leaflet-loading/Control.Loading.min.js
2018-08-23 16:02:27 +02:00

1 line
5.5 KiB
JavaScript

!function(){var a=window.console||{error:function(){},warn:function(){}};function t(i){i.Control.Loading=i.Control.extend({options:{delayIndicator:null,position:"topleft",separate:!1,zoomControl:null,spinjs:!1,spin:{lines:7,length:3,width:3,radius:5,rotate:13,top:"83%"}},initialize:function(o){i.setOptions(this,o),this._dataLoaders={},null!==this.options.zoomControl&&(this.zoomControl=this.options.zoomControl)},onAdd:function(o){if(this.options.spinjs&&"function"!=typeof Spinner)return a.error("Leaflet.loading cannot load because you didn't load spin.js (http://fgnass.github.io/spin.js/), even though you set it in options.");this._addLayerListeners(o),this._addMapListeners(o),this.options.separate||this.zoomControl||(o.zoomControl?this.zoomControl=o.zoomControl:o.zoomsliderControl&&(this.zoomControl=o.zoomsliderControl));var t,n="leaflet-control-loading";return this.zoomControl&&!this.options.separate?(t=this.zoomControl._container,n+=" leaflet-bar-part-bottom leaflet-bar-part last",i.DomUtil.addClass(this._getLastControlButton(),"leaflet-bar-part-bottom")):t=i.DomUtil.create("div","leaflet-control-zoom leaflet-control-layer-container leaflet-bar"),this._indicatorContainer=t,this._indicator=i.DomUtil.create("a",n,t),this.options.spinjs&&(this._spinner=new Spinner(this.options.spin).spin(),this._indicator.appendChild(this._spinner.el)),t},onRemove:function(o){this._removeLayerListeners(o),this._removeMapListeners(o)},removeFrom:function(o){return this.zoomControl&&!this.options.separate?(this._container.removeChild(this._indicator),this._map=null,this.onRemove(o),this):i.Control.prototype.removeFrom.call(this,o)},addLoader:function(o){if(this._dataLoaders[o]=!0,this.options.delayIndicator&&!this.delayIndicatorTimeout){var t=this;this.delayIndicatorTimeout=setTimeout(function(){t.updateIndicator(),t.delayIndicatorTimeout=null},this.options.delayIndicator)}else this.updateIndicator()},removeLoader:function(o){delete this._dataLoaders[o],this.updateIndicator(),this.options.delayIndicator&&this.delayIndicatorTimeout&&!this.isLoading()&&(clearTimeout(this.delayIndicatorTimeout),this.delayIndicatorTimeout=null)},updateIndicator:function(){this.isLoading()?this._showIndicator():this._hideIndicator()},isLoading:function(){return 0<this._countLoaders()},_countLoaders:function(){var o,t=0;for(o in this._dataLoaders)this._dataLoaders.hasOwnProperty(o)&&t++;return t},_showIndicator:function(){i.DomUtil.addClass(this._indicator,"is-loading"),i.DomUtil.addClass(this._indicatorContainer,"is-loading"),this.options.separate||(this.zoomControl instanceof i.Control.Zoom?i.DomUtil.removeClass(this._getLastControlButton(),"leaflet-bar-part-bottom"):"function"==typeof i.Control.Zoomslider&&this.zoomControl instanceof i.Control.Zoomslider&&i.DomUtil.removeClass(this.zoomControl._ui.zoomOut,"leaflet-bar-part-bottom"))},_hideIndicator:function(){i.DomUtil.removeClass(this._indicator,"is-loading"),i.DomUtil.removeClass(this._indicatorContainer,"is-loading"),this.options.separate||(this.zoomControl instanceof i.Control.Zoom?i.DomUtil.addClass(this._getLastControlButton(),"leaflet-bar-part-bottom"):"function"==typeof i.Control.Zoomslider&&this.zoomControl instanceof i.Control.Zoomslider&&i.DomUtil.addClass(this.zoomControl._ui.zoomOut,"leaflet-bar-part-bottom"))},_getLastControlButton:function(){for(var o=this.zoomControl._container,t=o.children.length-1;0<t;){var n=o.children[t];if(this._indicator!==n&&0!==n.offsetWidth&&0!==n.offsetHeight)break;t--}return o.children[t]},_handleLoading:function(o){this.addLoader(this.getEventId(o))},_handleBaseLayerChange:function(o){var t=this;o.layer&&o.layer.eachLayer&&"function"==typeof o.layer.eachLayer?o.layer.eachLayer(function(o){t._handleBaseLayerChange({layer:o})}):i.TileLayer.Canvas&&o.layer instanceof i.TileLayer.Canvas||t._handleLoading(o)},_handleLoad:function(o){this.removeLoader(this.getEventId(o))},getEventId:function(o){return o.id?o.id:o.layer?o.layer._leaflet_id:o.target._leaflet_id},_layerAdd:function(t){if(t.layer&&t.layer.on)try{t.layer.on({loading:this._handleLoading,load:this._handleLoad},this)}catch(o){a.warn("L.Control.Loading: Tried and failed to add event handlers to layer",t.layer),a.warn("L.Control.Loading: Full details",o)}},_layerRemove:function(t){if(t.layer&&t.layer.off)try{t.layer.off({loading:this._handleLoading,load:this._handleLoad},this)}catch(o){a.warn("L.Control.Loading: Tried and failed to remove event handlers from layer",t.layer),a.warn("L.Control.Loading: Full details",o)}},_addLayerListeners:function(o){o.eachLayer(function(o){o.on&&o.on({loading:this._handleLoading,load:this._handleLoad},this)},this),o.on("layeradd",this._layerAdd,this),o.on("layerremove",this._layerRemove,this)},_removeLayerListeners:function(o){o.eachLayer(function(o){o.off&&o.off({loading:this._handleLoading,load:this._handleLoad},this)},this),o.off("layeradd",this._layerAdd,this),o.off("layerremove",this._layerRemove,this)},_addMapListeners:function(o){o.on({baselayerchange:this._handleBaseLayerChange,dataloading:this._handleLoading,dataload:this._handleLoad,layerremove:this._handleLoad},this)},_removeMapListeners:function(o){o.off({baselayerchange:this._handleBaseLayerChange,dataloading:this._handleLoading,dataload:this._handleLoad,layerremove:this._handleLoad},this)}}),i.Map.addInitHook(function(){this.options.loadingControl&&(this.loadingControl=new i.Control.Loading,this.addControl(this.loadingControl))}),i.Control.loading=function(o){return new i.Control.Loading(o)}}"function"==typeof define&&define.amd?define(["leaflet"],function(o){t(o)}):t(L)}();