Commit 271df572 authored by Randall Leeds's avatar Randall Leeds

Ensure always on set by sidebar state

Refactored the way changing the tool triggers setting visible highlights.
The change should always ensure better interaction if other components
change the tool or highlight state in the future and trigger events.
parent 04de6f74
......@@ -7,6 +7,8 @@ class Annotator.Guest extends Annotator
".annotator-adder button mousedown": "onAdderMousedown"
".annotator-hl mousedown": "onHighlightMousedown"
".annotator-hl click": "onHighlightClick"
"setTool": "onSetTool"
"setVisibleHighlights": "onSetVisibleHighlights"
# Plugin configuration
options:
......@@ -115,7 +117,7 @@ class Annotator.Guest extends Annotator
)
.bind('setVisibleHighlights', (ctx, state) =>
this.setVisibleHighlights state
this.setVisibleHighlights state, false
this.publish 'setVisibleHighlights', state
)
......@@ -224,24 +226,17 @@ class Annotator.Guest extends Annotator
method: 'setTool'
params: name
switch name
when 'comment'
this.setVisibleHighlights this.visibleHighlights, true
when 'highlight'
this.setVisibleHighlights true, true
setVisibleHighlights: (state=true, temporary=false) ->
unless temporary
@visibleHighlights = state
setVisibleHighlights: (state=true, notify=true) ->
if notify
@panel?.notify
method: 'setVisibleHighlights'
params: state
markerClass = 'annotator-highlights-always-on'
if state or (@tool is 'highlight')
@element.addClass markerClass
else
@element.removeClass markerClass
markerClass = 'annotator-highlights-always-on'
if state or this.tool is 'highlight'
@element.addClass markerClass
else
@element.removeClass markerClass
addComment: ->
sel = @selectedRanges # Save the selection
......@@ -318,3 +313,14 @@ class Annotator.Guest extends Annotator
# Display the editor.
this.showEditor(annotation, position)
onSetTool: (name) ->
switch name
when 'comment'
this.setVisibleHighlights this.visibleHighlights, false
when 'highlight'
this.setVisibleHighlights true, false
onSetVisibleHighlights: (state) =>
this.visibleHighlights = state
this.setVisibleHighlights state, false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment