-
-
Save gosukiwi/a2d732382b124934d02be43158e3cbd5 to your computer and use it in GitHub Desktop.
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
# Garber-Irish DOM-ready Execution | |
# http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution | |
# | |
# Implementation using jQuery. | |
# | |
GarberIrish = | |
initialize: -> | |
controller = $('body').data('controller') | |
action = $('body').data('action') | |
return unless controller? and action? | |
parts = controller.split('/') | |
parts.push(action) | |
parts = (@camelCase(part) for part in parts) | |
try | |
klassName = "App.Controllers.#{parts.join('.')}" | |
klass = eval(klassName) | |
klass?.initialize() | |
# private | |
# transforms `foo_bar` into `FooBar` | |
camelCase: (name) -> | |
newName = $.camelCase(name.replace(/_/g, '-')) | |
"#{newName[0].toUpperCase()}#{newName.substr(1)}" | |
$(document).on 'turbolinks:load', -> GarberIrish.initialize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment