Sha256: 91997ce3fe76c668b8b0377d25f3f43e32907b2ef150beb113c282d48d2ce22a

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

<% app_name = Rails.application.class.to_s.split('::').first %>

class SeedTray
    constructor: () ->
        if window.Turbolinks != undefined
            if Turbolinks.EVENTS != undefined
                $(window).on "page:change", => @render()
            else
                $(window).on "turbolinks:load", => @render()
        else
            $(@render)
        @root = <%= app_name %>

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

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

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

        if @root[controller] && @render_defined(@root[controller])
            @root[controller].render()
        else
            console.info "Skipped #{@root.name}.#{controller}.render()."

        if @root[controller] && @root[controller][action] && @render_defined(@root[controller][action])
            @root[controller][action].render()
            console.info "Executed #{@root.name}.#{controller}.#{action}.render()."
        else
            console.info "Skipped #{@root.name}.#{controller}.#{action}.render()."

    render_defined: (object) ->
        object.render != undefined

    site_wide_render: ->

<%= app_name %>.delegator = new SeedTray()

Version data entries

1 entries across 1 versions & 1 rubygems

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