]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Merge branch 't371' into 0.5
authorAnna Sobiepanek <annaopensource@gmail.com>
Mon, 28 Mar 2011 19:33:37 +0000 (15:33 -0400)
committerAnna Sobiepanek <annaopensource@gmail.com>
Mon, 28 Mar 2011 19:33:37 +0000 (15:33 -0400)
1  2 
plugins/googlemap/popcorn.googlemap.js

index 1a45eaf549a3ce33e0b32612be15dd4a150a4849,11ae0c605ec2175dcfec26dca68f95edf174603c..92dbc385e9bf457dde1c6053a5d257cb669cb395
@@@ -1,6 -1,43 +1,42 @@@
  // PLUGIN: Google Maps
  var googleCallback;
  (function (Popcorn) {
 -    if ( typeof google !== 'undefined'  && google.maps && typeof google.maps.Geocoder !== 'undefined' &&
 -         typeof google.maps.LatLng !== 'undefined' ) {
 -        geocoder = new google.maps.Geocoder();
 -        _mapLoaded = true;
+   var newdiv,
+       i = 1,
+       _mapFired = false,
+       _mapLoaded = false,
+       geocoder,
+       loadMaps;
+   //google api callback 
+   googleCallback  = function( data ) {
+     // ensure all of the maps functions needed are loaded 
+     // before setting _maploaded to true
++    if ( typeof google !== "undefined" && google.maps && google.maps.Geocoder && google.maps.LatLng ) {
++      geocoder = new google.maps.Geocoder();
++      _mapLoaded = true;
+     } else {
+       setTimeout( function() {
+         googleCallback( data );
+       }, 1);
+     }
+   };
+   // function that loads the google api
+   loadMaps = function () {
+     // for some reason the Google Map API adds content to the body
+     if ( document.body ) {
+       _mapFired = true;
+       Popcorn.getScript( "http://maps.google.com/maps/api/js?sensor=false&callback=googleCallback" );
+     } else {
+       setTimeout( function() {
+           loadMaps( );
+         }, 1);
+     }
+   };
+   // if this is the firest time running the plugins
+   // call the function that gets the sctipt
+   if ( !_mapFired ) {
+     loadMaps();
+   }
  
    /**
     * googlemap popcorn plug-in