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.4.3 app/assets/javascripts/manage/handlers.js.coffee
manage-1.4.2 app/assets/javascripts/manage/handlers.js.coffee
manage-1.4.1 app/assets/javascripts/manage/handlers.js.coffee
manage-1.4 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.52 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.51 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.50 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.49 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.48 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.47 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.46 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.45 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.44 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.43 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.42 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.40 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.39 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.38 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.37 app/assets/javascripts/manage/handlers.js.coffee
manage-1.3.36 app/assets/javascripts/manage/handlers.js.coffee