Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21627 kshitij.so 1
class Morris.Hover
2
  # Displays contextual information in a floating HTML div.
3
 
4
  @defaults:
5
    class: 'morris-hover morris-default-style'
6
 
7
  constructor: (options = {}) ->
8
    @options = $.extend {}, Morris.Hover.defaults, options
9
    @el = $ "<div class='#{@options.class}'></div>"
10
    @el.hide()
11
    @options.parent.append(@el)
12
 
13
  update: (html, x, y) ->
14
    @html(html)
15
    @show()
16
    @moveTo(x, y)
17
 
18
  html: (content) ->
19
    @el.html(content)
20
 
21
  moveTo: (x, y) ->
22
    parentWidth  = @options.parent.innerWidth()
23
    parentHeight = @options.parent.innerHeight()
24
    hoverWidth   = @el.outerWidth()
25
    hoverHeight  = @el.outerHeight()
26
    left = Math.min(Math.max(0, x - hoverWidth / 2), parentWidth - hoverWidth)
27
    if y?
28
      top = y - hoverHeight - 10
29
      if top < 0
30
        top = y + 10
31
        if top + hoverHeight > parentHeight
32
          top = parentHeight / 2 - hoverHeight / 2
33
    else
34
      top = parentHeight / 2 - hoverHeight / 2
35
    @el.css(left: left + "px", top: parseInt(top) + "px")
36
 
37
  show: ->
38
    @el.show()
39
 
40
  hide: ->
41
    @el.hide()