Skip to content

Commit

Permalink
Better overlapping highlight allowance
Browse files Browse the repository at this point in the history
The `isAnnotator` method can ignore the highlight spans, making it a
simple call to `isAnnotator` when ignoring selections, rather than a
loop that tries to escape the highlights.

Close #466
  • Loading branch information
tilgovi committed Jan 17, 2015
1 parent b091a74 commit b66d3fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/annotator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,6 @@ class Annotator extends Delegator

for range in @selectedRanges
container = range.commonAncestor
if $(container).hasClass('annotator-hl')
container = $(container).parents('[class!=annotator-hl]')[0]
return if this.isAnnotator(container)

if event and @selectedRanges.length
Expand All @@ -599,7 +597,13 @@ class Annotator extends Delegator
#
# Returns true if the element is a child of an annotator element.
isAnnotator: (element) ->
!!$(element).parents().addBack().filter('[class^=annotator-]').not(@wrapper).length
!!$(element)
.parents()
.addBack()
.filter('[class^=annotator-]')
.not('[class=annotator-hl]')
.not(@wrapper)
.length

# Annotator#element callback. Displays viewer with all annotations
# associated with highlight Elements under the cursor.
Expand Down
4 changes: 4 additions & 0 deletions test/spec/annotator_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ describe 'Annotator', ->
for element in elements
assert.isFalse(annotator.isAnnotator(element))

it "should ignore the annotator highlight elements", ->
element = $('<span class="annotator-hl"></span>')[0]
assert.isFalse(annotator.isAnnotator(element))

describe "onHighlightMouseover", ->
element = null
mockEvent = null
Expand Down

0 comments on commit b66d3fb

Please sign in to comment.