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