Created
September 15, 2013 18:26
-
-
Save fiedl/6573175 to your computer and use it in GitHub Desktop.
"Hack" that dynamically loads the [gmaps4rails google api](https://github.com/apneadiving/Google-Maps-for-Rails) when using [turbolinks](https://github.com/rails/turbolinks/).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ready = -> | |
if $('.gmaps4rails_map').length > 0 | |
$.getScript("http://maps.google.com/maps/api/js?v=3.9&sensor=false&client=&key=&libraries=geometry&language=&hl=®ion=") | |
.success(-> | |
$.ajax( | |
dataType: "script", | |
cache: true, | |
url: "http://maps.gstatic.com/cat_js/intl/de_de/mapfiles/api-3/12/17/%7Bmain,geometry%7D.js" | |
) | |
.success(-> | |
Gmaps.loadMaps() | |
) | |
) | |
# | |
# This works, but fixes the google static server to de_de. | |
# Have a look at: | |
# http://stackoverflow.com/questions/18775450/jquery-cross-domain-ajax-callback-when-executed | |
# | |
$(document).ready(ready) | |
$(document).on('page:load', ready) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can write
$(document).on('ready page:load turbolinks:load')
(The last one is for turbolinks 5)