Sha256: 9e2fde5461d1a4e50ec27cf36b81ae8852a34287a5aff157cc6a3ff6608bc23d

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

class @Mercury.SnippetToolbar extends Mercury.Toolbar

  constructor: (@document, @options = {}) ->
    super(@options)


  build: ->
    @element = $('<div>', {class: 'mercury-toolbar mercury-snippet-toolbar', style: 'display:none'})
    @element.appendTo($(@options.appendTo).get(0) ? 'body')

    for buttonName, options of Mercury.config.toolbars.snippetable
      button = @buildButton(buttonName, options)
      button.appendTo(@element) if button


  bindEvents: ->
    Mercury.bind 'show:toolbar', (event, options) =>
      return unless options.snippet
      options.snippet.mouseout => @hide()
      @show(options.snippet)

    Mercury.bind 'hide:toolbar', (event, options) =>
      return unless options.type && options.type == 'snippet'
      @hide(options.immediately)

    $(@document).scroll => @position() if @visible

    @element.mousemove => clearTimeout(@hideTimeout)
    @element.mouseout => @hide()


  show: (@snippet) ->
    Mercury.tooltip.hide()
    @position()
    @appear()


  position: ->
    offset = @snippet.offset()

    top = offset.top + Mercury.displayRect.top - $(@document).scrollTop() - @height() + 10
    left = offset.left - $(@document).scrollLeft()

    @element.css {
      top: top,
      left: left
    }


  appear: ->
    clearTimeout(@hideTimeout)
    return if @visible
    @visible = true
    @element.css({display: 'block', opacity: 0})
    @element.stop().animate({opacity: 1}, 200, 'easeInOutSine')


  hide: (immediately = false) ->
    clearTimeout(@hideTimeout)
    if immediately
      @element.hide()
      @visible = false
    else
      @hideTimeout = setTimeout((=>
        @element.stop().animate {opacity: 0}, 300, 'easeInOutSine', =>
          @element.hide()
        @visible = false
      ), 500)

Version data entries

2 entries across 2 versions & 1 rubygems

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