Skip to content

Commit

Permalink
Util.mousePosition - use a proper positioning root
Browse files Browse the repository at this point in the history
This partially reverts d45a366 by
restoring the use of the jQuery `.offset()` method instead of
`.position()` but fixes the function for the case where the passed
in element (usually the .annotator-wrapper div) is not a positioning
root. In this case, its offset parent is taken as the offset element.

Fix #243
Fix #244
  • Loading branch information
tilgovi committed Jul 22, 2013
1 parent 330c673 commit 3cea566
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/util.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ Util.maxZIndex = ($elements) ->
Math.max.apply(Math, all)

Util.mousePosition = (e, offsetEl) ->
offset = $(offsetEl).position()
# If the offset element is not a positioning root use its offset parent
unless $(offsetEl).css('position') in ['absolute', 'fixed', 'relative']
offsetEl = $(offsetEl).offsetParent()[0]
offset = $(offsetEl).offset()
{
top: e.pageY - offset.top,
left: e.pageX - offset.left
Expand Down

0 comments on commit 3cea566

Please sign in to comment.