Last active
August 29, 2015 14:05
-
-
Save rummelonp/9d3cda9d410a3847e634 to your computer and use it in GitHub Desktop.
雑なディスパッチャ
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<%= javascript_include_tag "application" %> | |
</head> | |
<body data-route="<%= controller_name %>#<%= action_name %>"> | |
</body> | |
</html> |
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
#= require jquery | |
#= require jquery.dispatcher | |
$.dispatcher.add 'users#index', -> | |
alert 'users#index' | |
$document.ready -> | |
$.dispatcher.fire($('[data-route]').data('route')) |
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
$.dispatcher = (-> | |
list: [] | |
add: (route, callback) -> | |
$.dispatcher.list.push([route, callback]) | |
fire: (currentRoute) -> | |
for [route, callback] in $.dispatcher.list | |
if route == currentRoute | |
callback() | |
)() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment