Sha256: b374d8091f5727501be4b23e52757892b837c4d99002e96beb07678703824111

Contents?: true

Size: 1015 Bytes

Versions: 1

Compression:

Stored size: 1015 Bytes

Contents

class SeedTray
    constructor: () ->
        if window.Turbolinks != undefined
            $(window).on "page:change", => @ready()
        else
            $(@ready)
        @root = <%= Rails.application.class.to_s.split('::').first %>

    # Dynamically delegate ready to controller#action specific ready methods
    ready: =>
        #  Run the page specific ready code
        @delegate_ready()

        # Run the code that should run on every page.
        @site_wide_ready()

    delegate_ready: =>
        controller = $("[data-controller]").data("controller")
        action = $("[data-action").data("action")

        if @root[controller] && @root[controller][action]
            @root[controller][action].ready()
            console.info "Executed #{@root.name}.#{controller}.#{action}.ready()."
        else
            console.error "Couldn't find #{@root.name}.#{controller}.#{action}.ready()."

    site_wide_ready: ->

<%= Rails.application.class.to_s.split('::').first %>.delegator = new SeedTray()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seed_tray-0.1.1 app/assets/javascripts/seed_tray.js.coffee.erb