Commit 5fc45562 authored by csillag's avatar csillag

Implement location sort.

The only way to get information about the location of the annotations
in the document is to request this information from the highlights.

This information can't be read out from the selectors, because anchoring
can place them *anywhere* in the document.

They also can't be read from the anchors, because anchors can contain
any kind of description; there is no mapping to any uniform coordinate
system.

The only way to get this information is to ask the hights for
the coordinates, after they have been rendered.

So this must be done after the second-phase of anchoring; after the
rendering of the highlights in the DOM.

So now we query this info from the highlights (upon rendering
in the host fram), and then store it back into the targets,
which are then sent back to the sidebar, so that this information
is available for sorting.

Fixes #1217.
parent eb42da74
......@@ -213,8 +213,8 @@ class App
$rootScope.searchPredicate = 'message.updated'
$rootScope.reverse = false
when 'Location'
$rootScope.predicate = 'target[0].selector[2].start'
$rootScope.searchPredicate = 'message.target[0].selector[2].start'
$rootScope.predicate = 'target[0].pos.top'
$rootScope.searchPredicate = 'message.target[0].pos.top'
$rootScope.reverse = false
$rootScope.applySort "Newest"
......
......@@ -90,6 +90,47 @@ class Annotator.Guest extends Annotator
@comments[i..i] = []
@plugins.Heatmap._update()
# Watch for newly rendered highlights, and update positions in sidebar
this.subscribe "highlightsCreated", (highlights) =>
unless Array.isArray highlights
highlights = [highlights]
highlights.forEach (hl) ->
hls = hl.anchor.highlight # Fetch all the highlights
# Get the pages we have highlights on (for the given anchor)
pages = Object.keys(hls).map (s) -> parseInt s
firstPage = pages.sort()[0] # Determine the first page
firstHl = hls[firstPage] # Determine the first (topmost) hl
# Store the position of this anchor inside target
hl.anchor.target.pos =
top: hl.getTop()
heigth: hl.getHeight()
# Collect all impacted annotations
annotations = (hl.annotation for hl in highlights)
# Announce the new positions, so that the sidebar knows
this.publish "annotationsLoaded", [annotations]
# Watch for removed highlights, and update positions in sidebar
this.subscribe "highlightRemoved", (highlight) =>
hls = highlight.anchor.highlight # Fetch all the highlights
# Get the pages we have highlights on (for the given anchor)
pages = Object.keys(hls).map (s) -> parseInt s
# Do we have any highlights left?
if pages.length
console.log "We still have something left"
firstPage = pages.sort()[0] # Determine the first page
firstHl = hls[firstPage] # Determine the first (topmost) hl
# Store the position of this anchor inside target
highlight.anchor.target.pos =
top: highlight.getTop()
heigth: highlight.getHeight()
else
console.log "No pos left"
delete highlight.anchor.target.pos
# Announce the new positions, so that the sidebar knows
this.publish "annotationsLoaded", [[highlight.annotation]]
_setupXDM: (options) ->
# jschannel chokes FF and Chrome extension origins.
if (options.origin.match /^chrome-extension:\/\//) or
......
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