1/* 2 * This file holds javascript functions needed in frontend for the functionallity of the Google Maps widgets and shortcodes 3 * Handles conditional loading of Google API script. 4 * 5 * @author Christian "Kriesi" Budschedl 6 * @copyright Copyright ( c ) Christian Budschedl 7 * @link http://kriesi.at 8 * @link http://aviathemes.com 9 * @since Version 1.0 10 * @package AviaFramework 11 * 12 */ 13 14"use strict"; 15 16/** 17 * Avia Google Maps in frontend 18 */ 19(function($) 20{ 21 var objAviaGoogleMaps = null; 22 23 var AviaGoogleMaps = function(){ 24 25 if( 'undefined' == typeof window.av_google_map || 'undefined' == typeof avia_framework_globals ) 26 { 27 return; 28 } 29 30 if( objAviaGoogleMaps != null ) 31 { 32 return; 33 } 34 35 objAviaGoogleMaps = this; 36 37 this.document = $( document ); 38 this.script_loading = false; 39 this.script_loaded = false; 40 this.script_source = avia_framework_globals.gmap_avia_api; 41 this.maps = {}; 42 this.loading_icon_html = '<div class="ajax_load"><span class="ajax_load_inner"></span></div>'; 43 44 this.LoadAviaMapsAPIScript(); 45 }; 46 47 AviaGoogleMaps.prototype = { 48 49 LoadAviaMapsAPIScript: function() 50 { 51 this.maps = $('body').find( '.avia-google-map-container' ); 52 if( this.maps.length == 0 ) 53 { 54 return; 55 } 56 57 // Check if we need to load the api or we have only links to Google Maps page 58 var needToLoad = false; 59 this.maps.each(function( index ) { 60 var container = $(this); 61 if( container.hasClass('av_gmaps_show_unconditionally') || container.hasClass('av_gmaps_show_delayed') ) 62 { 63 needToLoad = true; 64 return false; 65 } 66 }); 67 68 if( ! needToLoad ) 69 { 70 return; 71 } 72 73 //check if maps are disabled by user setting via cookie. 74 if(document.cookie.match(/aviaPrivacyGoogleMapsDisabled/)) 75 { 76 $('.av_gmaps_main_wrap').addClass('av-maps-user-disabled'); 77 return; 78 } 79 80 // Check if our API already loaded 81 if( typeof $.AviaMapsAPI != 'undefined' ) 82 { 83 this.AviaMapsScriptLoaded(); 84 return; 85 } 86 87 $('body').on( 'avia-google-maps-api-script-loaded', $.proxy( this.AviaMapsScriptLoaded, this )); 88 89 this.script_loading = true; 90 91 var script = document.createElement('script'); 92 script.id = 'avia-gmaps-api-script'; 93 script.type = 'text/javascript'; 94 script.src = this.script_source; 95 96 document.body.appendChild(script); 97 }, 98 99 AviaMapsScriptLoaded: function() 100 { 101 this.script_loading = false; 102 this.script_loaded = true; 103 104 var object = this; 105 106 // Now we bind maps with AviaMapsAPI via aviaMaps 107 this.maps.each(function( index ) { 108 var container = $(this); 109 110 if( container.hasClass('av_gmaps_show_page_only') ) 111 { 112 return; 113 } 114 115 var mapid = container.data('mapid'); 116 117 // skip container if no map info found 118 if( 'undefined' == typeof window.av_google_map[mapid] ) 119 { 120 console.log( 'Map cannot be displayed because no info: ' + mapid); 121 return; 122 } 123 124 if( container.hasClass('av_gmaps_show_unconditionally') ) 125 { 126 container.aviaMaps(); 127// container.removeClass('av_gmaps_show_unconditionally'); 128 } 129 else if( container.hasClass('av_gmaps_show_delayed') ) 130 { 131 var wrap = container.closest('.av_gmaps_main_wrap'); 132 var confirm = wrap.find('a.av_text_confirm_link'); 133 134 confirm.on('click', object.AviaMapsLoadConfirmed ); 135 } 136 else 137 { 138 console.log( 'Map cannot be displayed because missing display class: ' + mapid); 139 } 140 }); 141 }, 142 143 AviaMapsLoadConfirmed: function( event ) 144 { 145 event.preventDefault(); 146 147 var confirm = $(this); 148 var container = confirm.closest('.av_gmaps_main_wrap').find('.avia-google-map-container'); 149 container.aviaMaps(); 150 } 151 }; 152 153 $(function() 154 { 155 new AviaGoogleMaps(); 156 }); 157 158})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.