Commit 5deb4440 authored by Randall Leeds's avatar Randall Leeds

Merge pull request #1121 from hypothesis/1118-multiple-selections-3

Multiple selections
parents eb29bd93 0e83ed3a
......@@ -196,6 +196,11 @@ class Annotator.Guest extends Annotator
(a.id for a in annotations)
]
toggleViewerSelection: (annotations) =>
@panel?.notify
method: "toggleViewerSelection"
params: (a.id for a in annotations)
updateViewer: (viewName, annotations) =>
@panel?.notify
method: "updateViewer"
......@@ -268,30 +273,36 @@ class Annotator.Guest extends Annotator
else
super
onAnchorMouseover: (annotations) ->
onAnchorMouseover: (event) ->
if (@tool is 'highlight') or @visibleHighlights
this.addEmphasis annotations
this.addEmphasis event.data.getAnnotations event
onAnchorMouseout: (annotations) ->
onAnchorMouseout: (event) ->
if (@tool is 'highlight') or @visibleHighlights
this.removeEmphasis annotations
this.removeEmphasis event.data.getAnnotations event
# When clicking on a highlight in highlighting mode,
# set @noBack to true to prevent the sidebar from closing
onAnchorMousedown: (annotations) =>
onAnchorMousedown: (event) =>
if (@tool is 'highlight') or @visibleHighlights
@noBack = true
# When clicking on a highlight in highlighting mode,
# tell the sidebar to bring up the viewer for the relevant annotations
onAnchorClick: (annotations) =>
onAnchorClick: (event) =>
return unless (@tool is 'highlight') or @visibleHighlights and @noBack
# Switch off dynamic mode; we are going to "Selection" scope
@plugins.Heatmap.dynamicBucket = false
# Tell sidebar to show the viewer for these annotations
this.showViewer "Selection", annotations
annotations = event.data.getAnnotations event
if event.metaKey or event.ctrlKey
# Tell sidebar to add these annotations to the sidebar
this.toggleViewerSelection annotations
else
# Tell sidebar to show the viewer for these annotations
this.showViewer "Selection", annotations
# We have already prevented closing the sidebar, now reset this flag
@noBack = false
......
......@@ -468,7 +468,10 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
else
d3.event.stopPropagation()
@dynamicBucket = false
annotator.showViewer "Selection", @buckets[bucket]
if d3.event.ctrlKey or d3.event.metaKey
annotator.toggleViewerSelection @buckets[bucket]
else
annotator.showViewer "Selection", @buckets[bucket]
tabs.exit().remove()
......
......@@ -227,6 +227,10 @@ class Hypothesis extends Annotator
$rootScope.$apply => this.updateViewer viewName, this._getAnnotationsFromIDs ids
)
.bind('toggleViewerSelection', (ctx, ids = []) =>
$rootScope.$apply => this.toggleViewerSelection this._getAnnotationsFromIDs ids
)
.bind('setTool', (ctx, name) =>
$rootScope.$apply => this.setTool name
)
......@@ -315,6 +319,31 @@ class Hypothesis extends Annotator
annotation.reply_list = children.sort(@sortAnnotations).reverse()
@buildReplyList children
toggleViewerSelection: (annotations=[]) =>
annotations = annotations.filter (a) -> a?
@element.injector().invoke [
'$rootScope',
($rootScope) =>
if $rootScope.view is "Selection"
# We are already in selection mode; just XOR this list
# to the current selection
@buildReplyList annotations
list = $rootScope.annotations
for a in annotations
index = list.indexOf a
if index isnt -1
list.splice index, 1
else
list.push a
else
# We are not in selection mode,
# so we switch to it, and make this list
# the new selection
$rootScope.view = "Selection"
$rootScope.annotations = annotations
]
this
updateViewer: (viewName, annotations=[]) =>
annotations = annotations.filter (a) -> a?
@element.injector().invoke [
......
......@@ -825,8 +825,8 @@ class Annotator extends Delegator
for anchor in @anchors[index] ? []
anchor.virtualize index
onAnchorMouseover: (annotations, highlightType) ->
#console.log "Mouse over annotations:", annotations
onAnchorMouseover: (event) ->
#console.log "Mouse over annotations:", event.data.getAnnotations event
# Cancel any pending hiding of the viewer.
this.clearViewerHideTimer()
......@@ -835,17 +835,18 @@ class Annotator extends Delegator
# already displaying the viewer
return false if @mouseIsDown or @viewer.isShown()
this.showViewer(annotations, util.mousePosition(event, @wrapper[0]))
this.showViewer event.data.getAnnotations(event),
util.mousePosition(event, @wrapper[0])
onAnchorMouseout: (annotations, highlightType) ->
#console.log "Mouse out on annotations:", annotations
onAnchorMouseout: (event) ->
#console.log "Mouse out on annotations:", event.data.getAnnotations event
this.startViewerHideTimer()
onAnchorMousedown: (annotations, highlightType) ->
#console.log "Mouse down on annotations:", annotations
onAnchorMousedown: (event) ->
#console.log "Mouse down on annotations:", event.data.getAnnotations event
onAnchorClick: (annotations, highlightType) ->
#console.log "Click on annotations:", annotations
onAnchorClick: (event) ->
#console.log "Click on annotations:", event.data.getAnnotations event
# Create namespace for Annotator plugins
class Annotator.Plugin extends Delegator
......
......@@ -19,31 +19,29 @@ class TextHighlight extends Annotator.Highlight
# List of annotators we have already set up events for
@_inited: []
# Collect the annotations impacted by an event
@getAnnotations: (event) ->
TextHighlight.$(event.target)
.parents('.annotator-hl')
.andSelf()
.map( -> TextHighlight.$(this).data("annotation"))
.toArray()
# Set up events for this annotator
@_init: (annotator) ->
return if annotator in @_inited
getAnnotations = (event) ->
# Collect the involved annotations
annotations = TextHighlight.$(event.target)
.parents('.annotator-hl')
.andSelf()
.map -> return TextHighlight.$(this).data("annotation")
# Make a proper array out of the list
TextHighlight.$.makeArray annotations
annotator.addEvent ".annotator-hl", "mouseover", (event) =>
annotator.onAnchorMouseover getAnnotations event, @highlightType
annotator.element.delegate ".annotator-hl", "mouseover", this,
(event) => annotator.onAnchorMouseover event
annotator.addEvent ".annotator-hl", "mouseout", (event) =>
annotator.onAnchorMouseout getAnnotations event, @highlightType
annotator.element.delegate ".annotator-hl", "mouseout", this,
(event) => annotator.onAnchorMouseout event
annotator.addEvent ".annotator-hl", "mousedown", (event) =>
annotator.onAnchorMousedown getAnnotations event, @highlightType
annotator.element.delegate ".annotator-hl", "mousedown", this,
(event) => annotator.onAnchorMousedown event
annotator.addEvent ".annotator-hl", "click", (event) =>
annotator.onAnchorClick getAnnotations event, @highlightType
annotator.element.delegate ".annotator-hl", "click", this,
(event) => annotator.onAnchorClick event
@_inited.push annotator
......
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-3cbddbb
** Annotator 1.2.6-dev-04d1465
** https://github.com/okfn/annotator/
**
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE
**
** Built at: 2014-02-17 13:39:47Z
** Built at: 2014-03-31 18:03:10Z
*/
......@@ -1694,21 +1694,21 @@
return _results;
};
Annotator.prototype.onAnchorMouseover = function(annotations, highlightType) {
Annotator.prototype.onAnchorMouseover = function(event) {
this.clearViewerHideTimer();
if (this.mouseIsDown || this.viewer.isShown()) {
return false;
}
return this.showViewer(annotations, util.mousePosition(event, this.wrapper[0]));
return this.showViewer(event.data.getAnnotations(event), util.mousePosition(event, this.wrapper[0]));
};
Annotator.prototype.onAnchorMouseout = function(annotations, highlightType) {
Annotator.prototype.onAnchorMouseout = function(event) {
return this.startViewerHideTimer();
};
Annotator.prototype.onAnchorMousedown = function(annotations, highlightType) {};
Annotator.prototype.onAnchorMousedown = function(event) {};
Annotator.prototype.onAnchorClick = function(annotations, highlightType) {};
Annotator.prototype.onAnchorClick = function(event) {};
return Annotator;
......
This diff is collapsed.
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-3cbddbb
** Annotator 1.2.6-dev-8b9bc0e
** https://github.com/okfn/annotator/
**
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE
**
** Built at: 2014-02-17 13:39:50Z
** Built at: 2014-03-31 22:37:06Z
*/
......@@ -42,30 +42,28 @@
TextHighlight._inited = [];
TextHighlight.getAnnotations = function(event) {
return TextHighlight.$(event.target).parents('.annotator-hl').andSelf().map(function() {
return TextHighlight.$(this).data("annotation");
}).toArray();
};
TextHighlight._init = function(annotator) {
var getAnnotations,
_this = this;
var _this = this;
if (__indexOf.call(this._inited, annotator) >= 0) {
return;
}
getAnnotations = function(event) {
var annotations;
annotations = TextHighlight.$(event.target).parents('.annotator-hl').andSelf().map(function() {
return TextHighlight.$(this).data("annotation");
});
return TextHighlight.$.makeArray(annotations);
};
annotator.addEvent(".annotator-hl", "mouseover", function(event) {
return annotator.onAnchorMouseover(getAnnotations(event, _this.highlightType));
annotator.element.delegate(".annotator-hl", "mouseover", this, function(event) {
return annotator.onAnchorMouseover(event);
});
annotator.addEvent(".annotator-hl", "mouseout", function(event) {
return annotator.onAnchorMouseout(getAnnotations(event, _this.highlightType));
annotator.element.delegate(".annotator-hl", "mouseout", this, function(event) {
return annotator.onAnchorMouseout(event);
});
annotator.addEvent(".annotator-hl", "mousedown", function(event) {
return annotator.onAnchorMousedown(getAnnotations(event, _this.highlightType));
annotator.element.delegate(".annotator-hl", "mousedown", this, function(event) {
return annotator.onAnchorMousedown(event);
});
annotator.addEvent(".annotator-hl", "click", function(event) {
return annotator.onAnchorClick(getAnnotations(event, _this.highlightType));
annotator.element.delegate(".annotator-hl", "click", this, function(event) {
return annotator.onAnchorClick(event);
});
return this._inited.push(annotator);
};
......
{"version":3,"file":"annotator.texthighlights.js","sources":["_preamble.coffee","_annotator_mapsrc/src/plugin/texthighlights.coffee"],"names":[],"mappings":";AAAA;;;;;;;;;;CAAA;CAAA;;;;;;;ACGA;CAAA,KAAA,aAAA;KAAA;;0JAAA;;CAAA,CAAM;CAIJ;;CAAA,EAAa,CAAb,KAAA,IAAC;;CAAD,EACK,CAAL,KAAc,IAAb;;CADD,EAEiB,CAAjB,SAAC,EAFD;;CAAA,EAKa,CAAb,GAAa,EAAC,CAAd,GAAC;CAA0B,GAAA,GAAD,CAAA,KAAA,CAAA;CAL1B,IAKa;;CALb,EAQuB,CAAvB,GAAuB,EAAC,IAAvB,OAAD;CACG,GAAA,GAAD,MAAA,gBAAA;CATF,IAQuB;;CARvB,CAAA,CAYU,CAAV,GAAA,MAAC;;CAZD,EAeQ,CAAR,CAAA,IAAS,IAAR;CACC,SAAA,IAAA;SAAA,GAAA;CAAA,CAAU,EAAA,EAAV,CAAU,EAAA,MAAa;CAAvB,aAAA;QAAA;CAAA,EAEiB,EAAA,CAAjB,GAAkB,KAAlB;CAEE,UAAA,CAAA;CAAA,EAAc,EAAqB,CAArB,CAAA,CAAd,CAGO,EAHP,EAA2B,EAAb;CAGJ,GAAO,QAAA,CAAa,IAAb;CAHH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B;;CA/HjB;;CAJ0B,QAAS;;CAArC,CAqIM,IAAgB,GAAP;CAGb;;;;;CAAA;;CAAA,EAAY,MAAA,CAAZ;CAEY,EAAgB,MAAjB,IAAT;CAFF,IAAY;;CAAZ;;CAH4C,QAAS;CArIvD"}
\ No newline at end of file
{"version":3,"file":"annotator.texthighlights.js","sources":["_preamble.coffee","_annotator_mapsrc/src/plugin/texthighlights.coffee"],"names":[],"mappings":";AAAA;;;;;;;;;;CAAA;CAAA;;;;;;;ACGA;CAAA,KAAA,aAAA;KAAA;;0JAAA;;CAAA,CAAM;CAIJ;;CAAA,EAAa,CAAb,KAAA,IAAC;;CAAD,EACK,CAAL,KAAc,IAAb;;CADD,EAEiB,CAAjB,SAAC,EAFD;;CAAA,EAKa,CAAb,GAAa,EAAC,CAAd,GAAC;CAA0B,GAAA,GAAD,CAAA,KAAA,CAAA;CAL1B,IAKa;;CALb,EAQuB,CAAvB,GAAuB,EAAC,IAAvB,OAAD;CACG,GAAA,GAAD,MAAA,gBAAA;CATF,IAQuB;;CARvB,CAAA,CAYU,CAAV,GAAA,MAAC;;CAZD,EAeiB,CAAjB,CAAiB,IAAC,IAAjB,CAAD;CACgB,EAAd,EAAqB,CAArB,CAAA,EAGQ,IAHR,EAAA;CAGyB,GAAd,QAAA,CAAa,EAAb;CAHX,MAGQ;CAnBV,IAeiB;;CAfjB,EAuBQ,CAAR,CAAA,IAAS,IAAR;CACC,SAAA,EAAA;CAAA,CAAU,EAAA,EAAV,CAAU,EAAA,MAAa;CAAvB,aAAA;QAAA;CAAA,CAE4C,CACzC,CADH,CACG,CADH,CAAiB,CAAjB,CAAS,EAAT,IAAA;CACwB,IAAV,IAAS,MAAT,EAAA;CADd,MACG;CAHH,CAK4C,CACzC,CADH,CACG,CADH,CAAiB,CAAjB,CAAS,CAAT,KAAA;CACwB,IAAV,IAAS,MAAT,CAAA;CADd,MACG;CANH,CAQ4C,CACzC,CADH,CACG,CADH,CAAiB,CAAjB,CAAS,EAAT,IAA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CA/Eb,EA6Fa,MAAA,EAAb;CAAiB,GAAA,SAAD;CA7FhB,IA6Fa;;CA7Fb,EAgGc,EAAA,IAAC,GAAf;CACE,EAAc,CAAb,CAAD,CAAA,IAAA;CACA,GAAG,CAAH,CAAA;CACG,GAAA,IAAD,GAAA,IAAA,SAAA;MADF,EAAA;CAGG,GAAA,OAAD,IAAA,SAAA;QALU;CAhGd,IAgGc;;CAhGd,EAwGW,EAAA,IAAX;CACE,GAAG,CAAH,CAAA;CACG,GAAA,IAAD,GAAA,IAAA,MAAA;MADF,EAAA;CAGG,GAAA,OAAD,IAAA,MAAA;QAJO;CAxGX,IAwGW;;CAxGX,EA+GoB,MAAA,SAApB;CACE,SAAA,gCAAA;CAAA;CAAA;YAAA,+BAAA;uBAAA;CAEE,GAAG,IAAH,CAAgC,GAAV,WAAnB;CAED,CAAU,CAAF,EAAR,KAAA;CAAA,CACA,EAAC,MAAD,CAAA;CADA,EAGQ,EAAR,GAAgB,EAAhB,CAAQ;CAHR,CAI+B,EAA/B,CAAK,CAAL,IAAA,CAAA;CAJA,EAKe,EAAV,CAAL,IAAA,2BALA;CAAA,IAMK,KAAW,GAAhB;MARF,IAAA;CAAA;UAFF;CAAA;uBADkB;CA/GpB,IA+GoB;;CA/GpB,EA6HiB,MAAA,MAAjB;CAAqB,GAAA,SAAD;CA7HpB,IA6HiB;;CA7HjB;;CAJ0B,QAAS;;CAArC,CAmIM,IAAgB,GAAP;CAGb;;;;;CAAA;;CAAA,EAAY,MAAA,CAAZ;CAEY,EAAgB,MAAjB,IAAT;CAFF,IAAY;;CAAZ;;CAH4C,QAAS;CAnIvD"}
\ 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