Sha256: 7cc011c9674b75ce32e02823598b1dd32cd0a247d56f4a181fa820ad46fa4b63

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

##
# Notification
# Raise notifications from anywhere in the JS code
# Pass the $(el) to place the message into
#
class outpost.Notification
    constructor: (@wrapper, @type, @message) ->
        @el = @_buildElement()

    # Alias for #append
    render: ->
        @append()

    # Replaces the element.
    # This is useful if you've changed the message or type.
    rerender: ->
        newEl = @_buildElement()
        @el.replaceWith(newEl)
        @el = newEl

    # Append the element to the wrapper.
    append: ->
        @wrapper.append @el

    # Prepend the element to the wrapper.
    prepend: ->
        @wrapper.prepend @el

    # Replaces the wrapper's content with the alert
    replace: ->
        @wrapper.html @el

    # Delegation for jQuery: @el.html("new text")
    html: (html) ->
        @el.html(html)

    # Delegation for jQuery: @el.is(":visible")
    isVisible: ->
        @el.is(":visible")

    # Delegation for jQuery: @el.show()
    show: ->
        @el.show()

    # Delegation for jQuery: @el.hide()
    hide: ->
        @el.hide()

    # Delegation for jQuery: @el.fadeIn()
    fadeIn: (speed=400, callback=null) ->
        @el.fadeIn(speed, callback?())

    # Delegation for jQuery: @el.fadeOut()
    fadeOut: (speed=400, callback=null) ->
        @el.fadeOut(speed, callback?())

    # Delegation for jQuery: @el.detach()
    detach: ->
        @el.detach()

    # Delegation for jQuery: @el.remove()
    remove: ->
        @el.remove()


    # Builds an element based on the attributes.
    _buildElement: ->
        $("<div />", class: "alert alert-#{@type}").html("#{@message}")

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
outpost-cms-0.1.4 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.1.3 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.1.2 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.1.1 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.1.0 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.0.5 app/assets/javascripts/outpost/notification.js.coffee
outpost-cms-0.0.4 app/assets/javascripts/outpost/notification.js.coffee