Commit 6d5f7d94 authored by Randall Leeds's avatar Randall Leeds

Refactor toolbar for multi-frame

parent 2227a706
...@@ -12,6 +12,10 @@ class Annotator.Guest extends Annotator ...@@ -12,6 +12,10 @@ class Annotator.Guest extends Annotator
options: options:
Document: {} Document: {}
# Internal state
tool: 'comment'
visibleHighlights: false
constructor: (element, options) -> constructor: (element, options) ->
Gettext.prototype.parse_locale_data annotator_locale_data Gettext.prototype.parse_locale_data annotator_locale_data
...@@ -80,6 +84,12 @@ class Annotator.Guest extends Annotator ...@@ -80,6 +84,12 @@ class Annotator.Guest extends Annotator
} }
) )
.bind('setTool', (ctx, name) => this.setTool name)
.bind('setVisibleHighlights', (ctx, state) =>
this.setVisibleHighlights state
)
scanDocument: (reason = "something happened") => scanDocument: (reason = "something happened") =>
try try
console.log "Analyzing host frame, because " + reason + "..." console.log "Analyzing host frame, because " + reason + "..."
...@@ -132,7 +142,7 @@ class Annotator.Guest extends Annotator ...@@ -132,7 +142,7 @@ class Annotator.Guest extends Annotator
return confirm "You have selected a very short piece of text: only " + length + " chars. Are you sure you want to highlight this?" return confirm "You have selected a very short piece of text: only " + length + " chars. Are you sure you want to highlight this?"
onSuccessfulSelection: (event) -> onSuccessfulSelection: (event) ->
if @highlightingMode if @tool is 'highlight'
# Do we really want to make this selection? # Do we really want to make this selection?
return unless this.confirmSelection() return unless this.confirmSelection()
...@@ -160,12 +170,12 @@ class Annotator.Guest extends Annotator ...@@ -160,12 +170,12 @@ class Annotator.Guest extends Annotator
# When clicking on a highlight in highlighting mode, # When clicking on a highlight in highlighting mode,
# set @noBack to true to prevent the sidebar from closing # set @noBack to true to prevent the sidebar from closing
onHighlightMousedown: (event) => onHighlightMousedown: (event) =>
if @highlightingMode or @alwaysOnMode then @noBack = true if (@tool is 'highlight') or @visibleHighlights then @noBack = true
# When clicking on a highlight in highlighting mode, # When clicking on a highlight in highlighting mode,
# tell the sidebar to bring up the viewer for the relevant annotations # tell the sidebar to bring up the viewer for the relevant annotations
onHighlightClick: (event) => onHighlightClick: (event) =>
return unless @highlightingMode or @alwaysOnMode and @noBack return unless (@tool is 'highlight') or @visibleHighlights and @noBack
# Collect relevant annotations # Collect relevant annotations
annotations = $(event.target) annotations = $(event.target)
...@@ -179,13 +189,30 @@ class Annotator.Guest extends Annotator ...@@ -179,13 +189,30 @@ class Annotator.Guest extends Annotator
# We have already prevented closing the sidebar, now reset this flag # We have already prevented closing the sidebar, now reset this flag
@noBack = false @noBack = false
setPersistentHighlights: (state) -> setTool: (name) ->
body = $('body') @tool = name
@panel?.notify
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
@panel?.notify
method: 'setVisibleHighlights'
params: state
markerClass = 'annotator-highlights-always-on' markerClass = 'annotator-highlights-always-on'
if @alwaysOnMode or @highlightingMode if state or (@tool is 'highlight')
body.addClass markerClass @element.addClass markerClass
else else
body.removeClass markerClass @element.removeClass markerClass
addComment: -> addComment: ->
sel = @selectedRanges # Save the selection sel = @selectedRanges # Save the selection
......
...@@ -48,6 +48,9 @@ class Hypothesis extends Annotator ...@@ -48,6 +48,9 @@ class Hypothesis extends Annotator
providers: null providers: null
host: null host: null
tool: 'comment'
visibleHighlights: false
# Here as a noop just to make the Permissions plugin happy # Here as a noop just to make the Permissions plugin happy
# XXX: Change me when Annotator stops assuming things about viewers # XXX: Change me when Annotator stops assuming things about viewers
viewer: viewer:
...@@ -127,6 +130,14 @@ class Hypothesis extends Annotator ...@@ -127,6 +130,14 @@ class Hypothesis extends Annotator
entities.push href entities.push href
this.plugins.Store?.loadAnnotations() this.plugins.Store?.loadAnnotations()
channel.notify
method: 'setTool'
params: this.tool
channel.notify
method: 'setVisibleHighlights'
params: this.visibleHighlights
@providers.push @providers.push
channel: channel channel: channel
entities: entities entities: entities
...@@ -216,6 +227,12 @@ class Hypothesis extends Annotator ...@@ -216,6 +227,12 @@ class Hypothesis extends Annotator
this.updateViewer ((@threading.getContainer id).message for id in ids) this.updateViewer ((@threading.getContainer id).message for id in ids)
) )
.bind('setTool', (ctx, name) => this.setTool name)
.bind('setVisibleHighlights', (ctx, state) =>
this.setVisibleHighlights state
)
_setupWrapper: -> _setupWrapper: ->
@wrapper = @element.find('#wrapper') @wrapper = @element.find('#wrapper')
.on 'mousewheel', (event, delta) -> .on 'mousewheel', (event, delta) ->
...@@ -422,6 +439,21 @@ class Hypothesis extends Annotator ...@@ -422,6 +439,21 @@ class Hypothesis extends Annotator
angular.extend @options.Store, options angular.extend @options.Store, options
this.addPlugin 'Store', @options.Store this.addPlugin 'Store', @options.Store
setTool: (name) =>
return if name is @tool
@tool = name
for p in @providers
p.channel.notify
method: 'setTool'
params: name
setVisibleHighlights: (state) =>
return if state is @visibleHighlights
@visibleHighlights = state
for p in @providers
p.channel.notify
method: 'setVisibleHighlights'
params: state
class AuthenticationProvider class AuthenticationProvider
constructor: -> constructor: ->
......
...@@ -21,9 +21,8 @@ class Annotator.Toolbar extends Annotator.Widget ...@@ -21,9 +21,8 @@ class Annotator.Toolbar extends Annotator.Widget
"click": (event) -> "click": (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
state = not window.annotator.alwaysOnMode state = not window.annotator.visibleHighlights
window.annotator.alwaysOnMode = state window.annotator.setVisibleHighlights state
window.annotator.setPersistentHighlights()
if state if state
$(event.target).addClass('pushed') $(event.target).addClass('pushed')
else else
...@@ -34,9 +33,9 @@ class Annotator.Toolbar extends Annotator.Widget ...@@ -34,9 +33,9 @@ class Annotator.Toolbar extends Annotator.Widget
"click": (event) -> "click": (event) ->
event.preventDefault() event.preventDefault()
event.stopPropagation() event.stopPropagation()
state = not window.annotator.highlightingMode state = not (window.annotator.tool is 'highlight')
window.annotator.highlightingMode = state tool = if state then 'highlight' else 'comment'
window.annotator.setPersistentHighlights() window.annotator.setTool tool
if state if state
$(event.target).addClass('pushed') $(event.target).addClass('pushed')
else else
......
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