Sha256: 4b34011cc353de1c8f57918e1fb87c877a783f840f051cf5816da84a6aaa5a13

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

@Mercury.tooltip = (forElement, content, options = {}) ->
  Mercury.tooltip.show(forElement, content, options)
  return Mercury.tooltip

$.extend Mercury.tooltip, {

  show: (@forElement, @content, @options = {}) ->
    @document = $(@forElement.get(0).ownerDocument)
    @initialize()
    if @visible then @update() else @appear()


  initialize: ->
    return if @initialized
    @build()
    @bindEvents()
    @initialized = true


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


  bindEvents: ->
    Mercury.bind 'resize', => @position() if @visible
    @document.scroll => @position() if @visible
    @element.mousedown (event) ->
      event.preventDefault()
      event.stopPropagation()


  appear: ->
    @update()

    @element.show()
    @element.animate {opacity: 1}, 200, 'easeInOutSine', =>
      @visible = true


  update: ->
    @element.html(@content)
    @position()


  position: ->
    offset = @forElement.offset()
    width = @element.width()

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

    left = left - (left + width + 25) - Mercury.displayRect.width if (left + width + 25) > Mercury.displayRect.width
    left = if left <= 0 then 0 else left

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


  hide: ->
    return unless @initialized
    @element.hide()
    @visible = false

}

Version data entries

2 entries across 2 versions & 1 rubygems

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