Sha256: 018f6d08cb2fa4881690a473439e50b95772b2b0b0ad7f4ce4260b0fc1e4e675

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

class OverlayMe.MenuItem extends Backbone.View

  tagName: 'li'
  className: 'menu-item'

  initialize: (attributes, options) ->
    @id = attributes.id
    @el.appendChild @collapseButton()
    @title = this.make 'label', { class: 'title' }, attributes.title
    $(@title).bind 'click', =>
      @toggleCollapse()
    @el.appendChild @title
    @content = this.make 'div', { class: 'item-content' }
    @el.appendChild @content
    @collapsed = (if localStorage.getItem("#{@id}-collapsed") == '' then false else true)
    @setCollapse @collapsed

  collapseButton: () ->
    @collapseButton = this.make 'a', { class: 'collaps-button' }, '<span>o</span>'
    $(@collapseButton).bind 'click', =>
      @toggleCollapse()
    @collapseButton

  toggleCollapse: ->
    @collapsed = !@collapsed
    @setCollapse @collapsed
    @saveState()

  setCollapse: (toCollapse) ->
    if toCollapse
      $(@el).addClass 'collapsed'
    else
      $(@el).removeClass 'collapsed'

  append: (childElemt) ->
    @content.appendChild childElemt

  render: ->
    @el

  saveState: ->
    localStorage.setItem "#{@id}-collapsed", (if @collapsed then 1 else '')

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
overlay_me-0.12.0 javascripts/menu_item.js.coffee