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