Skip to content

Commit

Permalink
Fix a problem for Google Map
Browse files Browse the repository at this point in the history
The problem is that do not work in the second access.
  • Loading branch information
YOSHIDA Hiroki committed Jun 5, 2015
1 parent cb7b284 commit 41e4166
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/app/views/comable/admin/orders/_google_map.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ javascript:
comable_google_map_address = "#{address.full_address}";
coffee:
window.can_google_map = ->
return false unless comable_google_map_element_id?
return false unless comable_google_map_address?
return false unless $('#' + comable_google_map_element_id).length
true

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 = ->
return unless can_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: comable_google_map_address }, (result, status) =>
Expand All @@ -22,7 +28,10 @@ coffee:
)

$(document).ready(->
initialize_google_map_api()
if google?
initialize_google_map()
else
initialize_google_map_api()
)

.comable-map
Expand Down

0 comments on commit 41e4166

Please sign in to comment.