Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created June 30, 2011 14:50
Show Gist options
  • Save DylanFM/1056381 to your computer and use it in GitHub Desktop.
Save DylanFM/1056381 to your computer and use it in GitHub Desktop.
First foray into asynch JS loading, this is a little snippet of the Surftourist maps code
class ST.maps.Map
constructor: (el, title, opts) ->
@el = $(el)
@opts = $.extend true, {}, @defaults, opts
if @el.length
@title = title
@markers = []
# Load Google maps if it's not present
if not google?.maps?
# Dynamically create a callback method to continue this map's setup routine
callback = "initMap#{@el.attr('id')}"
window[callback] = (=>
=> @init()
)()
$('body').append """
<script src="http://maps.google.com/maps/api/js?sensor=false&callback=#{callback}"></script>
"""
else
@init()
# These functions set it up
init: ->
# But we're going to need some more stuff now, so load that up
Modernizr.load
test: InfoBox? and RickMarker?
nope: '/assets/mapsExtra.js'
complete: =>
@setCenter()
@makeMap()
@processPoints()
@addPoints()
@infoWindows()
@drawLine()
@markCenter()
@setBounds()
# There may be external setup shiz that's listening
$(document).trigger 'mapsLoaded.ST'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment