Sha256: 429a69d800d6150246d6b8a159c162b29169616d67ef0785680d8b0189c0ba88

Contents?: true

Size: 1.76 KB

Versions: 25

Compression:

Stored size: 1.76 KB

Contents

class @Mercury.SnippetToolbar extends Mercury.Toolbar

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


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

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


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

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

    @element.mousemove =>
      clearTimeout(@hideTimeout)

    @element.mouseout =>
      @hide()

    jQuery(@document).on 'scroll', =>
      @position() if @visible


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


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

    top = offset.top + Mercury.displayRect.top - jQuery(@document).scrollTop() - @height() + 10
    left = offset.left - jQuery(@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 500, =>
        @element.stop().animate {opacity: 0}, 300, 'easeInOutSine', =>
          @element.hide()
        @visible = false

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
kiteditor-1.0.25 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.24 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.23 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.22 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.21 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.20 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.19 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.18 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.17 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.16 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.14 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.13 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.11 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.10 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.9 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.8 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.7 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.6 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.5 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee
kiteditor-1.0.4 vendor/assets/javascripts/mercury/snippet_toolbar.js.coffee