backend/app/views/comable/admin/orders/_google_map.slim
javascript:
comable_google_map_element_id = "#{id}";
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 = ->
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) =>
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 })
)
$(document).ready(->
if google?
initialize_google_map()
else
initialize_google_map_api()
)
.comable-map
.comable-google-map id="#{id}"
| Loading map...