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:
|
2012-12-13 20:09:50 +01:00
|
|
|
class: 'morris-hover morris-default-style'
|
2012-12-07 20:04:21 +01:00
|
|
|
|
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
|
|
|
|
2014-07-14 00:15:21 +02:00
|
|
|
update: (html, x, y, centre_y) ->
|
2014-04-01 13:10:54 +02:00
|
|
|
if not html
|
|
|
|
@hide()
|
|
|
|
else
|
|
|
|
@html(html)
|
|
|
|
@show()
|
2014-07-14 00:15:21 +02:00
|
|
|
@moveTo(x, y, centre_y)
|
2012-12-02 23:23:59 +01:00
|
|
|
|
2012-12-11 23:00:22 +01:00
|
|
|
html: (content) ->
|
|
|
|
@el.html(content)
|
2012-12-07 20:04:21 +01:00
|
|
|
|
2014-07-14 00:15:21 +02:00
|
|
|
moveTo: (x, y, centre_y) ->
|
2012-12-11 19:25:18 +01:00
|
|
|
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?
|
2014-07-14 00:15:21 +02:00
|
|
|
if centre_y is true
|
|
|
|
top = y - hoverHeight / 2
|
|
|
|
if top < 0
|
|
|
|
top = 0
|
|
|
|
else
|
|
|
|
top = y - hoverHeight - 10
|
|
|
|
if top < 0
|
|
|
|
top = y + 10
|
|
|
|
if top + hoverHeight > parentHeight
|
|
|
|
top = parentHeight / 2 - hoverHeight / 2
|
2012-12-11 19:25:18 +01:00
|
|
|
else
|
|
|
|
top = parentHeight / 2 - hoverHeight / 2
|
2013-04-25 05:22:29 +02:00
|
|
|
@el.css(left: left + "px", top: parseInt(top) + "px")
|
2012-12-07 20:04:21 +01:00
|
|
|
|
|
|
|
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()
|