1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Update annotation remove and always add default theme

This commit is contained in:
Fred Chasen 2017-08-02 16:31:57 -04:00
parent 837775b2cf
commit 6401485f48
6 changed files with 41 additions and 8 deletions

View file

@ -131,6 +131,7 @@
var text; var text;
var li = document.createElement('li'); var li = document.createElement('li');
var a = document.createElement('a'); var a = document.createElement('a');
var remove = document.createElement('a');
var textNode; var textNode;
if (range) { if (range) {
@ -143,8 +144,16 @@
rendition.display(cfiRange); rendition.display(cfiRange);
}; };
remove.textContent = "remove";
remove.href = "#" + cfiRange;
remove.onclick = function () {
rendition.annotations.remove(cfiRange);
return false;
};
li.appendChild(a); li.appendChild(a);
li.appendChild(textNode); li.appendChild(textNode);
li.appendChild(remove);
highlights.appendChild(li); highlights.appendChild(li);
} }

View file

@ -218,8 +218,11 @@
</div> </div>
<script> <script>
var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
var url = params && params.get("url") && decodeURIComponent(params.get("url"));
// Load the opf // Load the opf
var book = ePub(window.location.protocol + "//s3.amazonaws.com/epubjs/books/alice/OPS/package.opf"); var book = ePub(url || window.location.protocol + "//s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", { var rendition = book.renderTo("viewer", {
ignoreClass: "annotator-hl", ignoreClass: "annotator-hl",
width: "100%", width: "100%",
@ -274,6 +277,23 @@
// window.location.hash = "#/"+section.href // window.location.hash = "#/"+section.href
}); });
var keyListener = function(e){
// Left Key
if ((e.keyCode || e.which) == 37) {
rendition.prev();
}
// Right Key
if ((e.keyCode || e.which) == 39) {
rendition.next();
}
};
rendition.on("keyup", keyListener);
document.addEventListener("keyup", keyListener, false);
book.loaded.navigation.then(function(toc){ book.loaded.navigation.then(function(toc){
var $nav = document.getElementById("toc"), var $nav = document.getElementById("toc"),
docfrag = document.createDocumentFragment(); docfrag = document.createDocumentFragment();

View file

@ -188,7 +188,11 @@
<script> <script>
// Load the opf // Load the opf
var book = ePub(window.location.protocol + "//s3.amazonaws.com/epubjs/books/alice/OPS/package.opf"); var params = URLSearchParams && new URLSearchParams(document.location.search.substring(1));
var url = params && params.get("url") && decodeURIComponent(params.get("url"));
// Load the opf
var book = ePub(url || window.location.protocol + "//s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
var rendition = book.renderTo("viewer", { var rendition = book.renderTo("viewer", {
flow: "scrolled-doc", flow: "scrolled-doc",
ignoreClass: "annotator-hl" ignoreClass: "annotator-hl"

View file

@ -1,6 +1,6 @@
{ {
"name": "epubjs", "name": "epubjs",
"version": "0.3.42", "version": "0.3.43",
"description": "Parse and Render Epubs", "description": "Parse and Render Epubs",
"main": "lib/index.js", "main": "lib/index.js",
"module": "src/index.js", "module": "src/index.js",

View file

@ -69,9 +69,9 @@ class Annotations {
return annotation; return annotation;
} }
remove (cfiRange) { remove (cfiRange, type) {
let hash = decodeURI(cfiRange); let hash = encodeURI(cfiRange);
let result;
if (hash in this._annotations) { if (hash in this._annotations) {
let annotation = this._annotations[hash]; let annotation = this._annotations[hash];
@ -84,7 +84,6 @@ class Annotations {
delete this._annotations[hash]; delete this._annotations[hash];
} }
return result;
} }
highlight (cfiRange, data, cb) { highlight (cfiRange, data, cb) {
@ -177,6 +176,7 @@ class Annotation {
detach (contents) { detach (contents) {
let {cfiRange, type} = this; let {cfiRange, type} = this;
let result;
if (contents) { if (contents) {
if (type === "highlight") { if (type === "highlight") {

View file

@ -103,7 +103,7 @@ class Themes {
var theme; var theme;
for (var name in themes) { for (var name in themes) {
if (themes.hasOwnProperty(name) && name === this._current) { if (themes.hasOwnProperty(name) && (name === this._current || name === "default")) {
theme = themes[name]; theme = themes[name];
if(theme.rules || (theme.url && links.indexOf(theme.url) === -1)) { if(theme.rules || (theme.url && links.indexOf(theme.url) === -1)) {
this.add(name, contents); this.add(name, contents);