Skip to content

Instantly share code, notes, and snippets.

@somethvictory
Created February 2, 2017 07:34
Show Gist options
  • Save somethvictory/ebd83264a85dd9730efd0919e0eede1c to your computer and use it in GitHub Desktop.
Save somethvictory/ebd83264a85dd9730efd0919e0eede1c to your computer and use it in GitHub Desktop.
Load all common js related code then load js page by page
IDByMe.Initializer =
exec: (pageName) ->
if pageName && IDByMe[pageName]
IDByMe[pageName]['init']()
currentPage: ->
return '' unless $('body').attr('id')
bodyId = $('body').attr('id').split('-')
action = IDByMe.Util.capitalize(bodyId[1])
controller = IDByMe.Util.capitalize(bodyId[0])
controller + action
init: ->
IDByMe.Initializer.exec('Common')
if @currentPage()
IDByMe.Initializer.exec(@currentPage())
$(document).on 'ready page:load', ->
IDByMe.Initializer.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment