Files
inwestprofil.pl/plugins/async-google-maps.min.js
2025-06-26 22:58:38 +02:00

17 lines
2.4 KiB
JavaScript

/******************************************************
* *
* Async Google Maps - jQuery Plugin *
* *
* Purpose: This project contains a simple and *
* full configurable jQuery plugin which *
* asynchronously loads one or multiple *
* Google Maps instances located on a *
* page. The load is triggered when the *
* map is scrolled into viewport. *
* *
* Author: Andreas Kar (thex) <andreas.kar@gmx.at> *
* Repository: https://git.io/JvD8G *
* *
******************************************************/
!function(a){var i;a.fn.asyncGoogleMaps=function(n){(i=a.extend(!0,{},a.fn.asyncGoogleMaps.defaults,n)).containers=this,i.setHeight(),i.attachSpinner(),i.triggerAsyncLoad(),i.checkAndLoad()},a.fn.asyncGoogleMaps.defaults={offset:0,fixHeight:!1,spinner:{attach:!1,remove:!1,type:"included",spinnerClass:"async-gmaps-spinner",bsSpinnerClass:"spinner-border",customSpinner:"",delay:1e4},isInViewport:function(){var n=a(this).offset().top,e=n+a(this).outerHeight(),t=a(window).scrollTop(),s=t+a(window).height();return t<e&&n+i.offset<s},setHeight:function(){i.fixHeight&&a(i.containers).each(function(){var n=a(this).attr("height");void 0!==n&&a(this).attr("style","min-height:"+n+"px;")})},removeSpinner:function(){setTimeout(function(){a(this).parent().find("."+i.spinner.spinnerClass).remove()}.bind(this),i.spinner.delay)},attachSpinner:function(){var n,e=i.spinner;e.attach&&a(i.containers).each(function(){"bootstrap"==e.type?(n=a("<div>").addClass(e.bsSpinnerClass+" "+e.spinnerClass).attr("role","status")).prepend(a("<span>").addClass("sr-only").html("Loading...")):"included"==e.type?n=a("<div>").addClass("simple-spinner "+e.spinnerClass).attr("role","status"):"custom"==e.type&&(n=a(e.customSpinner).addClass(e.spinnerClass)),a(this).parent().prepend(n)})},triggerAsyncLoad:function(){a(window).on("resize scroll",function(){i.checkAndLoad()})},checkAndLoad:function(){a(i.containers).each(function(){var n=a(this);!n.attr("src")&&n.attr("data-src")&&i.isInViewport.call(n)&&(i.beforeLoad.call(n),n.attr("src",n.attr("data-src")),i.spinner.remove&&i.removeSpinner.call(n),i.afterLoad.call(n))})},beforeLoad:function(){},afterLoad:function(){}}}(jQuery);