Sha256: 538064835683c14e44d5c70e2c48a688e27fb156a9d89d76b6c2cec8e644141b

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

class Morris.Hover
  # Displays contextual information in a floating HTML div.

  @defaults:
    class: 'morris-hover morris-default-style'

  constructor: (options = {}) ->
    @options = $.extend {}, Morris.Hover.defaults, options
    @el = $ "<div class='#{@options.class}'></div>"
    @el.hide()
    @options.parent.append(@el)

  update: (html, x, y) ->
    if not html
      @hide()
    else
      @html(html)
      @show()
      @moveTo(x, y)

  html: (content) ->
    @el.html(content)

  moveTo: (x, y) ->
    parentWidth  = @options.parent.innerWidth()
    parentHeight = @options.parent.innerHeight()
    hoverWidth   = @el.outerWidth()
    hoverHeight  = @el.outerHeight()
    left = Math.min(Math.max(0, x - hoverWidth / 2), parentWidth - hoverWidth)
    if y?
      top = y - hoverHeight - 10
      if top < 0
        top = y + 10
        if top + hoverHeight > parentHeight
          top = parentHeight / 2 - hoverHeight / 2
    else
      top = parentHeight / 2 - hoverHeight / 2
    @el.css(left: left + "px", top: parseInt(top) + "px")

  show: ->
    @el.show()

  hide: ->
    @el.hide()

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
radius-rails-3.1.4 app/assets/components/morris.js/lib/morris.hover.coffee
rails_modular_admin-1.0.0 app/assets/node_modules/morris.js/lib/morris.hover.coffee
rails_modular_admin-0.4.0 app/assets/node_modules/morris.js/lib/morris.hover.coffee
jinda_lte-0.0.1 lib/generators/jinda_lte/templates/app/assets/jinda_assets/bower_components/morris.js/lib/morris.hover.coffee
jinda_bsb-0.0.1 lib/generators/jinda_bsb/templates/app/assets/jinda_assets/plugins/morrisjs/lib/morris.hover.coffee