Created
June 30, 2011 14:50
-
-
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
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
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