Skip to content

Commit

Permalink
Change scripts for Google Map to Asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
YOSHIDA Hiroki committed Jun 5, 2015
1 parent c6ed494 commit cb7b284
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
25 changes: 18 additions & 7 deletions backend/app/views/comable/admin/orders/_google_map.slim
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
javascript:
comable_google_map_element_id = "#{id}";
comable_google_map_address = "#{address.full_address}";
coffee:
window.initialize_google_map = (element_id, address) ->
google_map = new google.maps.Map(document.getElementById(element_id), { zoom: 15 })
window.initialize_google_map_api = ->
return if google?
script = document.createElement('script')
script.type = 'text/javascript'
script.src = '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initialize_google_map'
script.async = true
document.body.appendChild(script)

window.initialize_google_map = ->
google_map = new google.maps.Map(document.getElementById(comable_google_map_element_id), { zoom: 15 })
google_geo = new google.maps.Geocoder()
google_geo.geocode({ address: address }, (result, status) =>
google_geo.geocode({ address: comable_google_map_address }, (result, status) =>
return if status != google.maps.GeocoderStatus.OK
location = result[0].geometry.location
google_map.setCenter(location)
new google.maps.Marker({ map: google_map, position: location })
)

javascript:
$(document).ready(function() {
initialize_google_map('#{id}', '#{address.full_address}');
})
$(document).ready(->
initialize_google_map_api()
)

.comable-map
.comable-google-map id="#{id}"
Expand Down
3 changes: 0 additions & 3 deletions backend/app/views/layouts/comable/admin/application.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ html
= stylesheet_link_tag 'http://rawgithub.com/aehlke/tag-it/master/css/tagit.ui-zendesk.css', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'http://rawgithub.com/aehlke/tag-it/master/js/tag-it.min.js', 'data-turbolinks-track' => true

/ TODO: Refactoring
= javascript_include_tag '//maps.google.com/maps/api/js?v=3&sensor=false', 'data-turbolinks-track' => true

= csrf_meta_tags

body id="#{"comable-#{controller_name.singularize}"}"
Expand Down

0 comments on commit cb7b284

Please sign in to comment.