Skip to content

Instantly share code, notes, and snippets.

@jaromero
Last active August 29, 2015 14:20
Show Gist options
  • Save jaromero/b9496a16153a4d941db6 to your computer and use it in GitHub Desktop.
Save jaromero/b9496a16153a4d941db6 to your computer and use it in GitHub Desktop.
DOM-based routing in CoffeeScript
# DOM-based routing
# http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/
# Now ported to coffeescript by [email protected]
UTIL =
fire: (func, funcname, args) ->
namespace = SITE # indicate your obj literal namespace here
funcname = if funcname? then 'init' else funcname
namespace[func]?[funcname]? args
loadEvents: ->
bodyId = document.body.id
# hit up common first.
UTIL.fire 'common'
# do all the classes too.
for classnm in document.body.className.split(/\s+/)
UTIL.fire classnm
UTIL.fire classnm, bodyId
UTIL.fire classnm, 'finalize'
UTIL.fire 'common', 'finalize'
# kick it all off here
jQuery(document).ready UTIL.loadEvents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment