From 2e2f8013846ae05b7ae6c2fcfd1612bdb8ebd37c Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Thu, 14 Mar 2013 12:56:42 -0700 Subject: [PATCH] updated annotator plugin --- annotator.html | 4 +++ fpjs/hooks/annotate.js | 49 +++++++++++++++++++++++++------------ fpjs/libs/annotator-full.js | 16 ++++++------ 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/annotator.html b/annotator.html index d833e26..7161500 100755 --- a/annotator.html +++ b/annotator.html @@ -17,6 +17,7 @@ --> + @@ -56,6 +58,8 @@ + + diff --git a/fpjs/hooks/annotate.js b/fpjs/hooks/annotate.js index 717377f..82d1e33 100644 --- a/fpjs/hooks/annotate.js +++ b/fpjs/hooks/annotate.js @@ -10,11 +10,25 @@ FP.Hooks.register("beforeChapterDisplay").annotate = function(callback, chapter) ]; - FP.core.loadScripts(files, annotate, chapter.doc.head); - + //FP.core.loadScripts(files, annotate, chapter.doc.head); + $(chapter.doc.body).annotator().annotator('setupPlugins', {}, { + + Filter:false, + Store: { + annotationData: { + 'uri': chapter.path + }, + loadFromSearch: { + 'limit': 100, + 'uri': chapter.path + } + } + + }); + FP.core.addCss("css/annotator.css", false, chapter.doc.head); + if(callback) callback(); - - function annotate(path){ + function annotate(){ FP.core.addCss("css/annotator.css", false, chapter.doc.head); var s = document.createElement("script"); @@ -22,11 +36,15 @@ FP.Hooks.register("beforeChapterDisplay").annotate = function(callback, chapter) var a = "jQuery.migrateTrace = false;"; //a += "console.log(document.getElementById('c001p0002').getBoundingClientRect());"; - //a += "var content = $('body').annotator(),"; - a += "var content = $('body').annotator().annotator('setupPlugins', {}, {Filter:false}),"; - a += " server = '" + server + "';"; - a += " path = '" + chapter.path + "';"; - + + a += "var content = $('body').annotator().annotator('setupPlugins', {}, {Filter:false});"; + + //-- Use Local Server: + + // a += "var content = $('body').annotator(),"; + // a += " server = '" + server + "';"; + // a += " path = '" + chapter.path + "';"; + // // a += " content.annotator('addPlugin', 'Store', {"; // // The endpoint of the store on your server. // a += " prefix: server,"; @@ -34,16 +52,17 @@ FP.Hooks.register("beforeChapterDisplay").annotate = function(callback, chapter) // // Attach the uri of the current page to all annotations to allow search. // a += " annotationData: {"; // a += " 'uri': path"; - // a += " },"; - // - // // This will perform a search action rather than read when the plugin - // // loads. Will request the last 20 annotations for the current url. - // // eg. /store/endpoint/search?limit=20&uri=http://this/document/only + // a += " }"; + + // This will perform a search action rather than read when the plugin + // loads. Will request the last 20 annotations for the current url. + // eg. /store/endpoint/search?limit=20&uri=http://this/document/only + // a += "," // a += " loadFromSearch: {"; // a += " 'limit': 20,"; // a += " 'uri': path"; // a += " }"; - // a += "});"; + //a += "});"; s.innerHTML = a; diff --git a/fpjs/libs/annotator-full.js b/fpjs/libs/annotator-full.js index 046cec6..076b3f5 100644 --- a/fpjs/libs/annotator-full.js +++ b/fpjs/libs/annotator-full.js @@ -6,7 +6,7 @@ ** Dual licensed under the MIT and GPLv3 licenses. ** https://github.com/okfn/annotator/blob/master/LICENSE ** -** Built at: 2013-03-04 19:18:55Z +** Built at: 2013-03-06 19:56:56Z */ (function() { @@ -273,11 +273,12 @@ Range.nodeFromXPath = function(xpath, root) { var customResolver, evaluateXPath, namespace, node, segment; if (root == null) root = document; + this.document = root.ownerDocument || document; evaluateXPath = function(xp, nsResolver) { if (nsResolver == null) nsResolver = null; - return document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + return this.document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }; - if (!$.isXMLDoc(document.documentElement)) { + if (!$.isXMLDoc(this.document.documentElement)) { return evaluateXPath(xpath); } else { customResolver = document.createNSResolver(document.ownerDocument === null ? document.documentElement : document.ownerDocument.documentElement); @@ -653,6 +654,7 @@ this.onEditorHide = __bind(this.onEditorHide, this); this.showEditor = __bind(this.showEditor, this); Annotator.__super__.constructor.apply(this, arguments); this.plugins = {}; + this.document = element.ownerDocument; if (!Annotator.supported()) return this; if (!this.options.readOnly) this._setupDocumentEvents(); this._setupWrapper()._setupViewer()._setupEditor(); @@ -706,7 +708,7 @@ }; Annotator.prototype._setupDocumentEvents = function() { - $(document).bind({ + $(this.document).bind({ "mouseup": this.checkForEndSelection, "mousedown": this.checkForStartSelection }); @@ -717,7 +719,7 @@ var max, sel, style, x; style = $('#annotator-dynamic-style'); if (!style.length) { - style = $('').appendTo(document.head); + style = $('').appendTo(this.document.head); } sel = '*' + ((function() { var _k, _len3, _ref2, _results; @@ -729,7 +731,7 @@ } return _results; })()).join(''); - max = util.maxZIndex($(document.body).find(sel)); + max = util.maxZIndex($(this.document.body).find(sel)); max = Math.max(max, 1000); style.text([".annotator-adder, .annotator-outer, .annotator-notice {", " z-index: " + (max + 20) + ";", "}", ".annotator-filter {", " z-index: " + (max + 10) + ";", "}"].join("\n")); return this; @@ -737,7 +739,7 @@ Annotator.prototype.getSelectedRanges = function() { var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _k, _len3; - selection = util.getGlobal().getSelection(); + selection = this.document.getSelection(); ranges = []; rangesToIgnore = []; if (!selection.isCollapsed) {