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 ...@@ -7,6 +7,8 @@ class Annotator.Guest extends Annotator
".annotator-adder button mousedown": "onAdderMousedown" ".annotator-adder button mousedown": "onAdderMousedown"
".annotator-hl mousedown": "onHighlightMousedown" ".annotator-hl mousedown": "onHighlightMousedown"
".annotator-hl click": "onHighlightClick" ".annotator-hl click": "onHighlightClick"
"setTool": "onSetTool"
"setVisibleHighlights": "onSetVisibleHighlights"
# Plugin configuration # Plugin configuration
options: options:
...@@ -115,7 +117,7 @@ class Annotator.Guest extends Annotator ...@@ -115,7 +117,7 @@ class Annotator.Guest extends Annotator
) )
.bind('setVisibleHighlights', (ctx, state) => .bind('setVisibleHighlights', (ctx, state) =>
this.setVisibleHighlights state this.setVisibleHighlights state, false
this.publish 'setVisibleHighlights', state this.publish 'setVisibleHighlights', state
) )
...@@ -224,24 +226,17 @@ class Annotator.Guest extends Annotator ...@@ -224,24 +226,17 @@ class Annotator.Guest extends Annotator
method: 'setTool' method: 'setTool'
params: name params: name
switch name setVisibleHighlights: (state=true, notify=true) ->
when 'comment' if notify
this.setVisibleHighlights this.visibleHighlights, true
when 'highlight'
this.setVisibleHighlights true, true
setVisibleHighlights: (state=true, temporary=false) ->
unless temporary
@visibleHighlights = state
@panel?.notify @panel?.notify
method: 'setVisibleHighlights' method: 'setVisibleHighlights'
params: state params: state
markerClass = 'annotator-highlights-always-on'
if state or (@tool is 'highlight')
@element.addClass markerClass
else else
@element.removeClass markerClass markerClass = 'annotator-highlights-always-on'
if state or this.tool is 'highlight'
@element.addClass markerClass
else
@element.removeClass markerClass
addComment: -> addComment: ->
sel = @selectedRanges # Save the selection sel = @selectedRanges # Save the selection
...@@ -318,3 +313,14 @@ class Annotator.Guest extends Annotator ...@@ -318,3 +313,14 @@ class Annotator.Guest extends Annotator
# Display the editor. # Display the editor.
this.showEditor(annotation, position) 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