Commit 6ebf0412 authored by Sean Hammond's avatar Sean Hammond

Change $anchored -> $orphan

Instead of setting $anchored=true on anchored annotations, set
$orphan=true on orphaned (i.e. unanchored) ones as we used to do.

Orphaned annotations are the exception: we don't show them, or if
show_unanchored_annotations is one then we show them with a warning.
It's simpler and less buggy to add $orphan=true onto the exceptional
annotations than to try to add $anchored=true onto all of the
unexceptional ones.

Fixes #2525.
Fixes #2541.
parent 530466ae
...@@ -197,10 +197,10 @@ module.exports = class Guest extends Annotator ...@@ -197,10 +197,10 @@ module.exports = class Guest extends Annotator
sync = (anchors) -> sync = (anchors) ->
# Store the results of anchoring. # Store the results of anchoring.
annotation.$anchored = anchors.length is 0 annotation.$orphan = anchors.length > 0
for anchor in anchors for anchor in anchors
if anchor.range? if anchor.range?
annotation.$anchored = true annotation.$orphan = false
break break
# Add the anchors for this annotation to instance storage. # Add the anchors for this annotation to instance storage.
......
...@@ -249,27 +249,27 @@ describe 'Guest', -> ...@@ -249,27 +249,27 @@ describe 'Guest', ->
afterEach -> afterEach ->
document.body.removeChild(el) document.body.removeChild(el)
it "declares annotations without targets as anchored", (done) -> it "doesn't declare annotations without targets as orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [] annotation = target: []
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isTrue(annotation.$anchored) assert.isFalse(annotation.$orphan)
.then(done, done) .then(done, done)
it "declares annotations with a working target anchored", (done) -> it "doesn't declare annotations with a working target orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: "test"}] annotation = target: [{selector: "test"}]
sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range)) sandbox.stub(anchoring, 'anchor').returns(Promise.resolve(range))
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isTrue(annotation.$anchored) assert.isFalse(annotation.$orphan)
.then(done, done) .then(done, done)
it "declares annotations with broken targets not anchored", (done) -> it "declares annotations with broken targets as orphans", (done) ->
guest = createGuest() guest = createGuest()
annotation = target: [{selector: 'broken selector'}] annotation = target: [{selector: 'broken selector'}]
sandbox.stub(anchoring, 'anchor').returns(Promise.reject()) sandbox.stub(anchoring, 'anchor').returns(Promise.reject())
guest.anchor(annotation).then -> guest.anchor(annotation).then ->
assert.isFalse(annotation.$anchored) assert.isTrue(annotation.$orphan)
.then(done, done) .then(done, done)
it 'updates the cross frame and bucket bar plugins', (done) -> it 'updates the cross frame and bucket bar plugins', (done) ->
......
...@@ -18,7 +18,7 @@ module.exports = class CrossFrame ...@@ -18,7 +18,7 @@ module.exports = class CrossFrame
new Discovery($window, options) new Discovery($window, options)
createAnnotationSync = -> createAnnotationSync = ->
whitelist = ['$anchored', '$highlight', 'target', 'document', 'uri'] whitelist = ['$orphan', '$highlight', 'target', 'document', 'uri']
options = options =
formatter: (annotation) -> formatter: (annotation) ->
formatted = {} formatted = {}
......
...@@ -58,27 +58,14 @@ module.exports = class WidgetController ...@@ -58,27 +58,14 @@ module.exports = class WidgetController
crossframe.call('scrollToAnnotation', annotation.$$tag) crossframe.call('scrollToAnnotation', annotation.$$tag)
$scope.shouldShowThread = (container) -> $scope.shouldShowThread = (container) ->
# Show stubs # Show regardless of $orphan if that feature is turned on
if not container?.message?
return true
# Show replies
if container.message.references?.length
return true
# Show selected threads
if annotationUI.hasSelectedAnnotations()
return annotationUI.isAnnotationSelected(container.message.id)
# Show regardless of $anchored if that feature is turned on
if $scope.feature('show_unanchored_annotations') if $scope.feature('show_unanchored_annotations')
return true return true
# Show anchored threads if container?.message?.$orphan == true
if container.message.$anchored
return true
return false return false
return true
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag] !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
...@@ -47,6 +47,6 @@ ...@@ -47,6 +47,6 @@
</ul> </ul>
<footer class="thread-anchor-notice" <footer class="thread-anchor-notice"
ng-if="feature('show_unanchored_annotations') && isSidebar && !vm.container.message.$anchored"> ng-if="feature('show_unanchored_annotations') && isSidebar && vm.container.message.$orphan">
<em>We can't find the exact position of this annotation.</em> <em>We can't find the exact position of this annotation.</em>
</footer> </footer>
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