Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Last active April 9, 2019 19:21
Show Gist options
  • Save gosukiwi/a2d732382b124934d02be43158e3cbd5 to your computer and use it in GitHub Desktop.
Save gosukiwi/a2d732382b124934d02be43158e3cbd5 to your computer and use it in GitHub Desktop.
# 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