1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

updated annotator plugin

This commit is contained in:
Fred Chasen 2013-03-14 12:56:42 -07:00
parent f55fb69008
commit 2e2f801384
3 changed files with 47 additions and 22 deletions

View file

@ -17,6 +17,7 @@
<script>window.jQuery || document.write('<script src="fpjs/libs/jquery-1.9.0.min.js"><\/script>')</script>
-->
<script src="fpjs/libs/jquery-1.9.0.js"></script>
<script src="fpjs/libs/jquery-migrate-1.1.1.js"></script>
<script src="fpjs/libs/modernizr-2.6.2.min.js"></script>
<script>
@ -28,6 +29,7 @@
}
};
jQuery.migrateTrace = false;
</script>
@ -56,6 +58,8 @@
<script async src="fpjs/reader/utils.js"></script>
<script async src="fpjs/reader/app.js"></script>
<!-- Annotator -->
<script async src="fpjs/libs/annotator-full.js"></script>
</head>
<body>

View file

@ -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;

View file

@ -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 = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head);
style = $('<style id="annotator-dynamic-style"></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) {