Commit 4e1b8ce3 authored by csillag's avatar csillag

DTM changes

 * Updated dom-text-mapper to 3fb30bee (master branch)
 * Updated Annotator to 631c1345 (typed-packaging branch)

These are all internal DTM / Annotator changes.
The communcation about DOM changes has migrated from method calls
to events.

See also https://github.com/hypothesis/dom-text-mapper/issues/14
parent 3924bae4
...@@ -48,11 +48,12 @@ class window.PDFTextMapper extends window.PageTextMapperCore ...@@ -48,11 +48,12 @@ class window.PDFTextMapper extends window.PageTextMapperCore
@_unmapPage @pageInfo[index] @_unmapPage @pageInfo[index]
# Do something about cross-page selections # Do something about cross-page selections
window.DomTextMapper.instances.push viewer = document.getElementById "viewer"
id: "cross-page catcher" viewer.addEventListener "domChange", (event) =>
rootNode: document.getElementById "viewer" node = event.srcElement
performUpdateOnNode: (node, data) => data = event.data
if "viewer" is node.getAttribute? "id" if "viewer" is node.getAttribute? "id"
console.log "Detected cross-page change event."
# This event escaped the pages. # This event escaped the pages.
# Must be a cross-page selection. # Must be a cross-page selection.
if data.start? and data.end? if data.start? and data.end?
...@@ -61,8 +62,6 @@ class window.PDFTextMapper extends window.PageTextMapperCore ...@@ -61,8 +62,6 @@ class window.PDFTextMapper extends window.PageTextMapperCore
for index in [ startPage.index .. endPage.index ] for index in [ startPage.index .. endPage.index ]
#console.log "Should rescan page #" + index #console.log "Should rescan page #" + index
@_updateMap @pageInfo[index] @_updateMap @pageInfo[index]
documentChanged: ->
timestamp: ->
$(PDFView.container).on 'scroll', => @_onScroll() $(PDFView.container).on 'scroll', => @_onScroll()
......
...@@ -67,7 +67,10 @@ class TextHighlight extends Annotator.Highlight ...@@ -67,7 +67,10 @@ class TextHighlight extends Annotator.Highlight
for node in normedRange.textNodes() when not white.test node.nodeValue for node in normedRange.textNodes() when not white.test node.nodeValue
r = @$(node).wrapAll(hl).parent().show()[0] r = @$(node).wrapAll(hl).parent().show()[0]
window.DomTextMapper?.changed node, "created hilite" event = document.createEvent "UIEvents"
event.initUIEvent "domChange", true, false, window, 0
event.reason = "created hilite"
node.dispatchEvent event
r r
# Public: highlight a list of ranges # Public: highlight a list of ranges
...@@ -121,8 +124,11 @@ class TextHighlight extends Annotator.Highlight ...@@ -121,8 +124,11 @@ class TextHighlight extends Annotator.Highlight
# We should restore original state # We should restore original state
child = hl.childNodes[0] child = hl.childNodes[0]
@$(hl).replaceWith hl.childNodes @$(hl).replaceWith hl.childNodes
window.DomTextMapper?.changed child.parentNode,
"removed hilite (annotation deleted)" event = document.createEvent "UIEvents"
event.initUIEvent "domChange", true, false, window, 0
event.reason = "removed hilite (annotation deleted)"
child.parentNode.dispatchEvent event
# Get the HTML elements making up the highlight # Get the HTML elements making up the highlight
_getDOMElements: -> @_highlights _getDOMElements: -> @_highlights
......
...@@ -211,9 +211,12 @@ class Range.BrowserRange ...@@ -211,9 +211,12 @@ class Range.BrowserRange
while nr.commonAncestor.nodeType isnt Node.ELEMENT_NODE while nr.commonAncestor.nodeType isnt Node.ELEMENT_NODE
nr.commonAncestor = nr.commonAncestor.parentNode nr.commonAncestor = nr.commonAncestor.parentNode
if window.DomTextMapper? and changed if changed
# console.log "Ranged normalization changed the DOM, updating d-t-m" event = document.createEvent "UIEvents"
window.DomTextMapper.changed nr.commonAncestor, "range normalization", nr event.initUIEvent "domChange", true, false, window, 0
event.reason = "range normalization"
event.data = nr
nr.commonAncestor.dispatchEvent event
new Range.NormalizedRange(nr) new Range.NormalizedRange(nr)
......
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
** Annotator 1.2.6-dev-3d4ae84 ** Annotator 1.2.6-dev-6bedfd2
** https://github.com/okfn/annotator/ ** https://github.com/okfn/annotator/
** **
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning. ** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses. ** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE ** https://github.com/okfn/annotator/blob/master/LICENSE
** **
** Built at: 2013-11-28 15:22:14Z ** Built at: 2013-11-28 17:54:20Z
*/ */
...@@ -492,7 +492,7 @@ ...@@ -492,7 +492,7 @@
} }
BrowserRange.prototype.normalize = function(root) { BrowserRange.prototype.normalize = function(root) {
var changed, n, node, nr, r; var changed, event, n, node, nr, r;
if (this.tainted) { if (this.tainted) {
console.error(_t("You may only call normalize() once on a BrowserRange!")); console.error(_t("You may only call normalize() once on a BrowserRange!"));
return false; return false;
...@@ -557,8 +557,12 @@ ...@@ -557,8 +557,12 @@
while (nr.commonAncestor.nodeType !== Node.ELEMENT_NODE) { while (nr.commonAncestor.nodeType !== Node.ELEMENT_NODE) {
nr.commonAncestor = nr.commonAncestor.parentNode; nr.commonAncestor = nr.commonAncestor.parentNode;
} }
if ((window.DomTextMapper != null) && changed) { if (changed) {
window.DomTextMapper.changed(nr.commonAncestor, "range normalization", nr); event = document.createEvent("UIEvents");
event.initUIEvent("domChange", true, false, window, 0);
event.reason = "range normalization";
event.data = nr;
nr.commonAncestor.dispatchEvent(event);
} }
return new Range.NormalizedRange(nr); return new Range.NormalizedRange(nr);
}; };
......
This diff is collapsed.
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
** Annotator 1.2.6-dev-2000a65 ** Annotator 1.2.6-dev-6bedfd2
** https://github.com/okfn/annotator/ ** https://github.com/okfn/annotator/
** **
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning. ** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses. ** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE ** https://github.com/okfn/annotator/blob/master/LICENSE
** **
** Built at: 2013-11-26 10:43:03Z ** Built at: 2013-11-28 18:04:55Z
*/ */
...@@ -61,7 +61,8 @@ ...@@ -61,7 +61,8 @@
} }
PDFTextMapper.prototype.setEvents = function() { PDFTextMapper.prototype.setEvents = function() {
var _this = this; var viewer,
_this = this;
addEventListener("pagerender", function(evt) { addEventListener("pagerender", function(evt) {
var index; var index;
if (_this.pageInfo == null) { if (_this.pageInfo == null) {
...@@ -78,12 +79,13 @@ ...@@ -78,12 +79,13 @@
return _this._unmapPage(_this.pageInfo[index]); return _this._unmapPage(_this.pageInfo[index]);
} }
}); });
window.DomTextMapper.instances.push({ viewer = document.getElementById("viewer");
id: "cross-page catcher", viewer.addEventListener("domChange", function(event) {
rootNode: document.getElementById("viewer"), var data, endPage, index, node, startPage, _i, _ref, _ref1, _results;
performUpdateOnNode: function(node, data) { node = event.srcElement;
var endPage, index, startPage, _i, _ref, _ref1, _results; data = event.data;
if ("viewer" === (typeof node.getAttribute === "function" ? node.getAttribute("id") : void 0)) { if ("viewer" === (typeof node.getAttribute === "function" ? node.getAttribute("id") : void 0)) {
console.log("Detected cross-page change event.");
if ((data.start != null) && (data.end != null)) { if ((data.start != null) && (data.end != null)) {
startPage = _this.getPageForNode(data.start); startPage = _this.getPageForNode(data.start);
endPage = _this.getPageForNode(data.end); endPage = _this.getPageForNode(data.end);
...@@ -94,9 +96,6 @@ ...@@ -94,9 +96,6 @@
return _results; return _results;
} }
} }
},
documentChanged: function() {},
timestamp: function() {}
}); });
return $(PDFView.container).on('scroll', function() { return $(PDFView.container).on('scroll', function() {
return _this._onScroll(); return _this._onScroll();
......
{"version":3,"file":"annotator.pdf.js","sources":["_preamble.coffee","_annotator_mapsrc/src/plugin/pdf.coffee"],"names":[],"mappings":";AAAA;;;;;;;;;;CAAA;CAAA;;;;;;;ACCA;CAAA,GAAA,EAAA;KAAA;;oSAAA;;CAAA,CAAM,IAAM;CAGV;;CAAA,EAAa,CAAb,KAAa,CAAb,GAAC;CAAe,GAAA,MAAA;CAAH,EAA0B;CAAvC,IAAa;;CAAb,EAE4B,CAF5B,sBAEA;;CAFA,EAKc,MAAA,GAAd;CAAyB,IAAK,EAAN,MAAP;CALjB,IAKc;;CALd,EAQc,MAAA,GAAd;CAAyB,EAAO,CAAf,GAAO,MAAP;CARj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AAA,EAAA;CACA,EACM,CAAmB,CAAJ,EAElB,CAFA,GAED,CAFA,CAAA,sBAAA;CAIA,EAAA,KAAA,EAAA;CANF,MACA;CADA,CASkC,CAA1B,EAAR,CAAA,EAAQ,EAAuB;CAG9B,GAAA,CAAS,GAAA,KAAV;CA5IF,IA8HgB;;CA9HhB;;CAHiC,KAAM;;CAAzC,CAmJM,IAAgB,GAAP;CAEb;;;;;CAAA;;CAAA,EAAY,MAAA,CAAZ;AAES,CAAP,GAAA,EAAA,CAAyB,EAAR,IAAjB;CACE,aAAM,+CAAN;QADF;CAGC,GAAA,GAAD,EAAU,IAAV,WAAmC;CAEjC,CAAM,EAAN,IAAA;CAAA,CACQ,IAAR,EAAA,KADA;CAPQ,OAKV;CALF,IAAY;;CAAZ;;CAFiC,QAAS;CAnJ5C"}
\ No newline at end of file \ No newline at end of file
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
** Annotator 1.2.6-dev-9183f7e ** Annotator 1.2.6-dev-6bedfd2
** https://github.com/okfn/annotator/ ** https://github.com/okfn/annotator/
** **
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning. ** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses. ** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE ** https://github.com/okfn/annotator/blob/master/LICENSE
** **
** Built at: 2013-11-28 15:40:48Z ** Built at: 2013-11-28 17:56:16Z
*/ */
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
}; };
TextHighlight.prototype._highlightRange = function(normedRange, cssClass) { TextHighlight.prototype._highlightRange = function(normedRange, cssClass) {
var hl, node, r, white, _i, _len, _ref, _ref1, _results; var event, hl, node, r, white, _i, _len, _ref, _results;
if (cssClass == null) { if (cssClass == null) {
cssClass = 'annotator-hl'; cssClass = 'annotator-hl';
} }
...@@ -85,9 +85,10 @@ ...@@ -85,9 +85,10 @@
continue; continue;
} }
r = this.$(node).wrapAll(hl).parent().show()[0]; r = this.$(node).wrapAll(hl).parent().show()[0];
if ((_ref1 = window.DomTextMapper) != null) { event = document.createEvent("UIEvents");
_ref1.changed(node, "created hilite"); event.initUIEvent("domChange", true, false, window, 0);
} event.reason = "created hilite";
node.dispatchEvent(event);
_results.push(r); _results.push(r);
} }
return _results; return _results;
...@@ -137,7 +138,7 @@ ...@@ -137,7 +138,7 @@
}; };
TextHighlight.prototype.removeFromDocument = function() { TextHighlight.prototype.removeFromDocument = function() {
var child, hl, _i, _len, _ref, _ref1, _results; var child, event, hl, _i, _len, _ref, _results;
_ref = this._highlights; _ref = this._highlights;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
...@@ -145,7 +146,10 @@ ...@@ -145,7 +146,10 @@
if ((hl.parentNode != null) && this.annotator.domMapper.isPageMapped(this.pageIndex)) { if ((hl.parentNode != null) && this.annotator.domMapper.isPageMapped(this.pageIndex)) {
child = hl.childNodes[0]; child = hl.childNodes[0];
this.$(hl).replaceWith(hl.childNodes); this.$(hl).replaceWith(hl.childNodes);
_results.push((_ref1 = window.DomTextMapper) != null ? _ref1.changed(child.parentNode, "removed hilite (annotation deleted)") : void 0); event = document.createEvent("UIEvents");
event.initUIEvent("domChange", true, false, window, 0);
event.reason = "removed hilite (annotation deleted)";
_results.push(child.parentNode.dispatchEvent(event));
} else { } else {
_results.push(void 0); _results.push(void 0);
} }
......
{"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,C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jB,IAAT;CAFF,IAAY;;CAAZ;;CAH4C,QAAS;CApIvD"}
\ No newline at end of file \ No newline at end of file
...@@ -7,38 +7,41 @@ class window.DomTextMapper ...@@ -7,38 +7,41 @@ class window.DomTextMapper
SELECT_CHILDREN_INSTEAD = ["thead", "tbody", "ol", "a", "caption", "p", "span", "div", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "li", "form"] SELECT_CHILDREN_INSTEAD = ["thead", "tbody", "ol", "a", "caption", "p", "span", "div", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "li", "form"]
CONTEXT_LEN = 32 CONTEXT_LEN = 32
@instances: [] @instances: 0
@changed: (node, reason = "no reason", data = {}) ->
if @instances.length is 0 then return
# console.log "==== Node"
# console.log node
# console.log "has changed: " + reason
# console.log data
for instance in @instances when instance.rootNode.contains(node)
# console.log "Telling instance '" + instance.id + "'."
instance.documentChanged()
instance.performUpdateOnNode node, false, data
instance.lastScanned = instance.timestamp()
null
constructor: (@id)-> constructor: (@id)->
@setRealRoot() @setRealRoot()
instances = window.DomTextMapper.instances DomTextMapper.instances += 1
instances.push this @id ?= "d-t-m #" + DomTextMapper.instances
@id ?= "d-t-m #" + instances.length
log: (msg) -> log: (msg...) ->
console.log @id + ": " + msg console.log @id, ": ", msg...
# ===== Public methods ======= # ===== Public methods =======
# Change handler
_onChange: (event) =>
# @log "received change event", event
# console.log "source", event.srcElement
# console.log "reason", event.reason ? "no reason"
# console.log "data", event.data
@documentChanged()
@performUpdateOnNode event.srcElement, false, event.data
@lastScanned = @timestamp()
# Change the root node, and subscribe to the events
_changeRootNode: (node) ->
@rootNode?.removeEventListener "domChange", @_onChange
@rootNode = node
@rootNode.addEventListener "domChange", @_onChange
node
# Consider only the sub-tree beginning with the given node. # Consider only the sub-tree beginning with the given node.
# #
# This will be the root node to use for all operations. # This will be the root node to use for all operations.
setRootNode: (rootNode) -> setRootNode: (rootNode) ->
@rootWin = window @rootWin = window
@pathStartNode = @rootNode = rootNode @pathStartNode = @_changeRootNode rootNode
# Consider only the sub-tree beginning with the node whose ID was given. # Consider only the sub-tree beginning with the node whose ID was given.
# #
...@@ -55,7 +58,7 @@ class window.DomTextMapper ...@@ -55,7 +58,7 @@ class window.DomTextMapper
@rootWin = iframe.contentWindow @rootWin = iframe.contentWindow
unless @rootWin? unless @rootWin?
throw new Error "Can't access contents of the specified iframe!" throw new Error "Can't access contents of the specified iframe!"
@rootNode = @rootWin.document @_changeRootNode @rootWin.document
@pathStartNode = @getBody() @pathStartNode = @getBody()
# Return the default path # Return the default path
...@@ -67,7 +70,7 @@ class window.DomTextMapper ...@@ -67,7 +70,7 @@ class window.DomTextMapper
# a different root earlier, and now you want to restore the default setting.) # a different root earlier, and now you want to restore the default setting.)
setRealRoot: -> setRealRoot: ->
@rootWin = window @rootWin = window
@rootNode = document @_changeRootNode document
@pathStartNode = @getBody() @pathStartNode = @getBody()
# Notify the library that the document has changed. # Notify the library that the document has changed.
......
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