Last active
August 29, 2015 14:20
-
-
Save jaromero/b9496a16153a4d941db6 to your computer and use it in GitHub Desktop.
DOM-based routing in CoffeeScript
This file contains hidden or 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
# 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