Sha256: 9228a3bde677fdbbf27980f6ef9035eabe185a935e3ea91400d1d97870f33909

Contents?: true

Size: 1.39 KB

Versions: 34

Compression:

Stored size: 1.39 KB

Contents

class @Handlers
  @handlers = {}

  @register: (handler, registeredClass) ->
    throw "No constructor on " + handler unless registeredClass.constructor
    @handlers[handler] = registeredClass

  @instantiate: (handlers, element) ->
    handlers = handlers.replace(/\s/g, '').split(',')
    element.handlers = []
    $.each handlers, (index, handler) =>
      if @handlers[handler]
        instance = new @handlers[handler](element)
        element.handlers.push instance
      else
        throw "Unknown handler " + handler

  @destroy: (instances) ->
    $.each instances, (index, instance) ->
      instance.destroy() if instance.destroy

  @unregisterAll: ->
    @handlers = {}

$(document).on 'handlers:pageChanged', ->
  $('[data-handler]').each ->
    Handlers.instantiate $(this).attr('data-handler'), this

$(document).on 'handlers:pageUpdated', (event, scope) ->
  $(scope).find('[data-handler]').each ->
    Handlers.instantiate $(this).attr('data-handler'), this

$(document).on 'handlers:pageUpdating', (event, scope) ->
  $(scope).find('[data-handler]').each ->
    Handlers.destroy @handlers if @handlers
    delete @handlers if @handlers

if typeof(Turbolinks) != undefined
  $(document).on 'page:fetch', ->
    $(document).trigger 'handlers:pageUpdating', 'body'

  $(document).on 'page:change', ->
    $(document).trigger 'handlers:pageUpdated', 'body'

  $ ->
    $(document).trigger 'handlers:pageChanged'

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
manage-1.3.34 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.33 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.32 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.31 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.29 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.28 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.27 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.26 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.25 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.24 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.20 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.19 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.18 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.17 app/assets/javascripts/manage/handlers.js.coffee