Sha256: 159ea18c5b5b72c179d80b488b8dcc99e2ba9900d2b51c5fe241a22216049efb

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

class @Mercury.Toolbar.Expander extends Mercury.Palette

  constructor: (@name, @options) ->
    @container = @options.for
    @containerWidth = @container.outerWidth()
    super(null, @name, @options)
    return @element


  build: ->
    @container.css({whiteSpace: 'normal'})
    @trigger = $('<div>', {class: 'mercury-toolbar-expander'}).appendTo($(@options.appendTo).get(0) ? 'body')
    @element = $('<div>', {class: "mercury-palette mercury-expander mercury-#{@name}-expander", style: 'display:none'})
    @windowResize()


  bindEvents: ->
    Mercury.bind 'hide:dialogs', (event, dialog) => @hide() unless dialog == @
    Mercury.bind 'resize', => @windowResize()

    super

    @trigger.click (event) =>
      event.stopPropagation()
      hiddenButtons = []
      for button in @container.find('.mercury-button')
        button = $(button)
        hiddenButtons.push(button.data('expander')) if button.position().top > 5

      @loadContent(hiddenButtons.join(''))
      @toggle()

    @element.click (event) =>
      buttonName = $(event.target).closest('[data-button]').data('button')
      button = @container.find(".mercury-#{buttonName}-button")
      button.click()


  windowResize: ->
    if @containerWidth > $(window).width() then @trigger.show() else @trigger.hide()
    @hide()


  position: (keepVisible) ->
    @element.css({top: 0, left: 0, display: 'block', visibility: 'hidden'})
    position = @trigger.offset()
    width = @element.width()

    position.left = position.left - width + @trigger.width() if position.left + width > $(window).width()

    @element.css {
      top: position.top + @trigger.height(),
      left: position.left,
      display: if keepVisible then 'block' else 'none',
      visibility: 'visible'
    }

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercury-rails-0.1.1 app/assets/javascripts/mercury/toolbar.expander.js.coffee
mercury-rails-0.1.0 app/assets/javascripts/mercury/toolbar.expander.js.coffee