forked from SaulBurgos/easyLocator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easyLocator.min.js
1 lines (1 loc) · 6.96 KB
/
easyLocator.min.js
1
!function(t){var o=this;this.easyLocatorMethods={locations:[],htmlPlug:'<div class="locatorMap_loader">Loading...</div><div id="mapContainer_map" class="locatorMap_map"> </div><div class="locatorMap_listContainer locatorMap_list--desktop"><div class="locatorMap_listContainer_filter"> <input class="locatorMap_listContainer_filter_input" type="text" placeholder="filter.."> </div><ul class="locatorMap_list js-locatorMap_list"></ul> </div><div class="locatorMap_listContainer locatorMap_list--mobile js-locatorMap_listContaineMobile" style="display:none"> <div class="locatorMap_list_close js-locatorMap_list_Close"> <i class="fa fa-chevron-down"></i> </div><ul class="locatorMap_list"></ul> </div>',options:{mapContainer:void 0,map:void 0,isAPIloaded:!1,myLocations:[],openInfowindowAfterClick:!1,useMarkerCluster:!1,afterCLick:void 0,markerClustererOptions:{maxZoom:12}},loadScripts:function(){this.showHideLoader("show");var t="https://maps.googleapis.com/maps/api/js?libraries=places&signed_in=true&signed_in=true&language=en&callback=window.easyLocatorMethods.loadMap",e=document.createElement("link");e.rel="stylesheet",e.href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css";var a=document.getElementsByTagName("link")[0];if(a.parentNode.insertBefore(e,a),"object"==typeof google&&"object"==typeof google.maps)o.easyLocatorMethods.options.isAPIloaded=!0,this.loadMap();else{"undefined"!=typeof this.options.apiKey&&(t="https://maps.googleapis.com/maps/api/js?libraries=places&signed_in=true&signed_in=true&language=en&key="+this.options.apiKey+"&callback=window.easyLocatorMethods.loadMap");var i=document.createElement("script");i.type="text/javascript",i.src=t,document.body.appendChild(i)}},loadMap:function(){this.options.isAPIloaded=!0;var t={zoom:8,center:new google.maps.LatLng(-34.397,150.644),mapTypeId:google.maps.MapTypeId.ROADMAP};this.options.map=new google.maps.Map(document.getElementById("mapContainer_map"),t),this.options.map.controls[google.maps.ControlPosition.TOP_CENTER].push(this.createButtonList()),this.options.infoWindow=new google.maps.InfoWindow({maxWidth:400}),this.options.markerClusterer=new MarkerClusterer(this.options.map,null,this.options.markerClustererOptions),google.maps.event.addListenerOnce(this.options.map,"idle",function(){return"undefined"!=typeof o.easyLocatorMethods.options.spreadsheetId?void o.easyLocatorMethods.getJsonData():void(o.easyLocatorMethods.options.myLocations.length>0&&o.easyLocatorMethods.loadMyLocations())})},createEvents:function(){t(".js-locatorMap_list_Close").on("click",function(){t(".js-locatorMap_listContaineMobile").slideToggle("fast")}),t(".locatorMap_listContainer_filter_input").change(function(){o.easyLocatorMethods.filterList(this)}).keyup(function(){o.easyLocatorMethods.filterList(this)})},filterList:function(o){var e=t(o).val();""!=e?(t(".js-locatorMap_list").find('.locatorMap_list_item_title:not(:contains_("'+e+'"))').parent().slideUp(),t(".js-locatorMap_list").find('.locatorMap_list_item_title:contains_("'+e+'")').parent().slideDown()):t(".js-locatorMap_list").find("li").slideDown()},createButtonList:function(){var o=t.parseHTML('<div id="locatorMap_openList"><i class="fa fa-list"></i></div>')[0];return google.maps.event.addDomListener(o,"click",function(){t(".js-locatorMap_listContaineMobile").slideToggle("fast")}),o},showHideLoader:function(o){"show"==o?t(".locatorMap_loader").show():t(".locatorMap_loader").hide()},getJsonData:function(){var t=document.createElement("script");t.type="text/javascript",t.src="https://spreadsheets.google.com/feeds/list/"+this.options.spreadsheetId+"/od6/public/values?hl=en_US&alt=json&callback=window.easyLocatorMethods.successGetJsonData",t.async=!0,document.body.appendChild(t)},getContentITemList:function(t,o){var e='<li class="locatorMap_list_item" data-indexarray="'+t+'"><i class="locatorMap_list_item_icon fa fa-map-marker"></i> <span class="locatorMap_list_item_title">'+o+"</span></li>";return e},successGetJsonData:function(o){var e=t(".locatorMap_list");e.empty();for(var a="",i=0;i<o.feed.entry.length;i++){var s=o.feed.entry[i];a+=this.getContentITemList(i,s.gsx$title.$t);var n=new google.maps.Marker({position:new google.maps.LatLng(s.gsx$lat.$t,s.gsx$lng.$t),map:this.options.map,title:s.gsx$title.$t});""!=s.gsx$iconmarker.$t&&n.setOptions({icon:{url:s.gsx$iconmarker.$t,scaledSize:new google.maps.Size(32,32)}}),this.locations.push({title:s.gsx$title.$t,description:s.gsx$description.$t,image:s.gsx$image.$t,link:s.gsx$link.$t,iconMarker:s.gsx$iconmarker.$t,marker:n}),this.options.useMarkerCluster&&this.options.markerClusterer.addMarker(n)}e.html(a),this.centerMapOnLocations(),this.attachEventLocations(),this.showHideLoader("hide")},loadMyLocations:function(){var o=t(".locatorMap_list");o.empty();for(var e="",a=0;a<this.options.myLocations.length;a++){var i=this.options.myLocations[a];e+=this.getContentITemList(a,i.title);var s=new google.maps.Marker({position:new google.maps.LatLng(i.lat,i.lng),map:this.options.map,title:i.title});"undefined"!=typeof i.iconMarker&&s.setOptions({icon:{url:i.iconMarker,scaledSize:new google.maps.Size(32,32)}}),this.locations.push({title:i.title,description:i.description,image:i.image,link:i.link,iconMarker:i.iconmarker,marker:s}),this.options.useMarkerCluster&&this.options.markerClusterer.addMarker(s)}o.html(e),this.centerMapOnLocations(),this.attachEventLocations(),this.showHideLoader("hide")},centerMapOnLocations:function(){for(var t=new google.maps.LatLngBounds,o=0;o<this.locations.length;o++)t.extend(this.locations[o].marker.getPosition());this.options.map.fitBounds(t)},attachEventLocations:function(){function e(t){google.maps.event.addListener(t.marker,"click",function(){o.easyLocatorMethods.openInfoWindow(t)})}for(var a=0;a<this.locations.length;a++)e(this.locations[a]);t(".locatorMap_list_item").on("click",function(){var e=o.easyLocatorMethods.locations[t(this).attr("data-indexarray")];o.easyLocatorMethods.options.map.setCenter(e.marker.getPosition()),o.easyLocatorMethods.options.openInfowindowAfterClick&&o.easyLocatorMethods.openInfoWindow(e),t(window).width()<=768&&t(".js-locatorMap_listContaineMobile").slideToggle("fast")})},openInfoWindow:function(t){var o="",e="";""!=t.link&&(o='<p><a href="'+t.link+'" target="_blank">Link</a></p>'),""!=t.image&&(e='<img src="'+t.image+'" class="locatorMap_responsiveImg"/>');var a='<div id="locatorMap_contentInfoWindow">'+e+'<p class="locatorMap_contentInfoWindow_title"><b>'+t.title+"</b></p><p>"+t.description+"</p>"+o+"</div>";this.options.infoWindow.setContent(a),this.options.infoWindow.open(this.options.map,t.marker),"function"==typeof this.options.afterCLick&&this.options.afterCLick(t)}},t.fn.easyLocator=function(e){return jQuery.expr[":"].contains_=function(t,o,e){return(t.textContent||t.innerText||"").toUpperCase().indexOf(e[3].toUpperCase())>=0},this.addClass("locatorMap"),this.html(o.easyLocatorMethods.htmlPlug),o.easyLocatorMethods.options=t.extend(o.easyLocatorMethods.options,e),o.easyLocatorMethods.options.mapContainer=this,o.easyLocatorMethods.loadScripts(),o.easyLocatorMethods.createEvents(),this}}(jQuery);