Skip to content

Commit

Permalink
implemented google maps asyncronous loading
Browse files Browse the repository at this point in the history
  • Loading branch information
salgua committed May 27, 2016
1 parent 15a4837 commit 35e292c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.0.2
## 27/05/2016

1. [](#improved)
* implemented Google Maps asynchronous loading

# v0.1.0
## 05/09/2016

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Google Maps
version: 1.0.0
version: 1.0.2
description: Google Maps plugin for Grav
icon: code
icon: map-marker
author:
name: Salvatore Guarino
email: [email protected]
Expand Down
8 changes: 4 additions & 4 deletions js/google-maps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
jQuery(document).ready(function () {
function initMap () {
var $mapDivs = $('.google-map');
$mapDivs.each(function(index){
var lat = $(this).data('lat');
var lng = $(this).data('lng');
var lat = parseFloat($(this).data('lat'));
var lng = parseFloat($(this).data('lng'));
var zoom = $(this).data('zoom');
var window = $(this).data('infowindow');
var map = new google.maps.Map(this, {
Expand All @@ -29,4 +29,4 @@ jQuery(document).ready(function () {
infowindow.open(map, marker);
}
});
});
}
6 changes: 3 additions & 3 deletions shortcodes/MapShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public function init()
{
$apikey = $this->grav['config']->get('plugins.google-maps.google_api_key');
$apikeystring = ($apikey) ? "?key=$apikey" : "";

$this->shortcode->getHandlers()->add('google-maps', function(ShortcodeInterface $sc) use ($apikeystring) {

//add assets
$this->shortcode->addAssets('js', 'https://maps.googleapis.com/maps/api/js'.$apikeystring);
$this->shortcode->addAssets('js', 'plugin://google-maps/js/google-maps.js');
$this->shortcode->addAssets('asyncJs', 'plugin://google-maps/js/google-maps.js');
$this->shortcode->addAssets('asyncJs', 'https://maps.googleapis.com/maps/api/js'.$apikeystring.'&callback=initMap');
$hash = $this->shortcode->getId($sc);
$infowindow = $sc->getContent();

Expand Down

0 comments on commit 35e292c

Please sign in to comment.