2012-12-04 20:12:34 +01:00
|
|
|
class Morris.Hover
|
|
|
|
# Displays contextual information in a floating HTML div.
|
2012-12-07 20:04:21 +01:00
|
|
|
|
|
|
|
@defaults:
|
|
|
|
class: 'morris-popup'
|
|
|
|
|
2012-12-04 20:12:34 +01:00
|
|
|
constructor: (options = {}) ->
|
|
|
|
@options = $.extend {}, Morris.Hover.defaults, options
|
|
|
|
@el = $ "<div class='#{@options.class}'></div>"
|
|
|
|
@el.hide()
|
2012-12-07 20:04:21 +01:00
|
|
|
@options.parent.append(@el)
|
2012-12-04 20:12:34 +01:00
|
|
|
|
2012-12-07 20:04:21 +01:00
|
|
|
update: (x, y, data) ->
|
|
|
|
@render(data)
|
|
|
|
@show()
|
|
|
|
@moveTo(x, y)
|
2012-12-02 23:23:59 +01:00
|
|
|
|
2012-12-07 20:04:21 +01:00
|
|
|
render: (data) ->
|
2012-12-04 20:12:34 +01:00
|
|
|
if typeof @options.content is 'function'
|
|
|
|
@el.html @options.content(data)
|
|
|
|
else
|
|
|
|
@el.html @options.content
|
2012-12-07 20:04:21 +01:00
|
|
|
|
|
|
|
moveTo: (x, y) ->
|
|
|
|
@el.css(
|
|
|
|
left: (x - @el.outerWidth() / 2) + "px"
|
|
|
|
top: (y - @el.outerHeight() - 10) + "px")
|
|
|
|
|
|
|
|
show: ->
|
2012-12-04 20:12:34 +01:00
|
|
|
@el.show()
|
2012-12-02 23:23:59 +01:00
|
|
|
|
2012-12-04 20:12:34 +01:00
|
|
|
hide: ->
|
|
|
|
@el.hide()
|