mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
remove boomark, handle goto and gotoCfi before render
This commit is contained in:
parent
c17e707ec4
commit
4e129111b4
10 changed files with 113 additions and 36 deletions
|
@ -2196,11 +2196,11 @@ EPUBJS.Book.prototype.renderTo = function(elem){
|
|||
EPUBJS.Book.prototype.startDisplay = function(){
|
||||
var display;
|
||||
|
||||
if( this.settings.restore && this.settings.goto) {
|
||||
if(this.settings.goto) {
|
||||
|
||||
display = this.goto(this.settings.goto);
|
||||
|
||||
}else if( this.settings.restore && this.settings.previousLocationCfi) {
|
||||
}else if(this.settings.previousLocationCfi) {
|
||||
|
||||
display = this.displayChapter(this.settings.previousLocationCfi);
|
||||
|
||||
|
@ -2366,14 +2366,23 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
|
|||
};
|
||||
|
||||
EPUBJS.Book.prototype.gotoCfi = function(cfi){
|
||||
if(!this.isRendered) return this._enqueue("gotoCfi", arguments);
|
||||
//if(!this.isRendered) return this._enqueue("gotoCfi", arguments);
|
||||
if(!this.isRendered) {
|
||||
this.settings.previousLocationCfi = cfi;
|
||||
return;
|
||||
}
|
||||
|
||||
return this.displayChapter(cfi);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.goto = function(url){
|
||||
var split, chapter, section, absoluteURL, spinePos;
|
||||
var deferred = new RSVP.defer();
|
||||
if(!this.isRendered) return this._enqueue("goto", arguments);
|
||||
//if(!this.isRendered) return this._enqueue("goto", arguments);
|
||||
if(!this.isRendered) {
|
||||
this.settings.goto = url;
|
||||
return;
|
||||
}
|
||||
|
||||
split = url.split("#");
|
||||
chapter = split[0];
|
||||
|
|
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -43,10 +43,13 @@ EPUBJS.Reader = function(path, _options) {
|
|||
|
||||
this.book = book = new EPUBJS.Book({
|
||||
bookPath: path,
|
||||
restore: this.settings.restore,
|
||||
previousLocationCfi: this.settings.previousLocationCfi
|
||||
restore: this.settings.restore
|
||||
});
|
||||
|
||||
if(this.settings.previousLocationCfi) {
|
||||
book.gotoCfi(this.settings.previousLocationCfi);
|
||||
}
|
||||
|
||||
this.offline = false;
|
||||
this.sidebarOpen = false;
|
||||
if(!this.settings.bookmarks) {
|
||||
|
@ -96,9 +99,11 @@ EPUBJS.Reader.prototype.addBookmark = function(cfi) {
|
|||
|
||||
EPUBJS.Reader.prototype.removeBookmark = function(cfi) {
|
||||
var bookmark = this.isBookmarked(cfi);
|
||||
if(!bookmark === -1 ) return;
|
||||
if( bookmark === -1 ) return;
|
||||
|
||||
delete this.settings.bookmarks[bookmark];
|
||||
|
||||
this.trigger("reader:unbookmarked", bookmark);
|
||||
};
|
||||
|
||||
EPUBJS.Reader.prototype.isBookmarked = function(cfi) {
|
||||
|
@ -175,6 +180,7 @@ EPUBJS.Reader.prototype.unload = function(){
|
|||
//-- Enable binding events to reader
|
||||
RSVP.EventTarget.mixin(EPUBJS.Reader.prototype);
|
||||
EPUBJS.reader.BookmarksController = function() {
|
||||
var reader = this;
|
||||
var book = this.book;
|
||||
|
||||
var $bookmarks = $("#bookmarksView"),
|
||||
|
@ -190,10 +196,13 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
$bookmarks.hide();
|
||||
};
|
||||
|
||||
var counter = 0;
|
||||
|
||||
var createBookmarkItem = function(cfi) {
|
||||
var listitem = document.createElement("li"),
|
||||
link = document.createElement("a");
|
||||
|
||||
listitem.id = "bookmark-"+counter;
|
||||
listitem.classList.add('list_item');
|
||||
|
||||
//-- TODO: Parse Cfi
|
||||
|
@ -209,6 +218,9 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
}, false);
|
||||
|
||||
listitem.appendChild(link);
|
||||
|
||||
counter++;
|
||||
|
||||
return listitem;
|
||||
};
|
||||
|
||||
|
@ -219,13 +231,16 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
|
||||
$list.append(docfrag);
|
||||
|
||||
|
||||
|
||||
this.on("reader:bookmarked", function(cfi) {
|
||||
var item = createBookmarkItem(cfi);
|
||||
$list.append(item);
|
||||
});
|
||||
|
||||
this.on("reader:unbookmarked", function(index) {
|
||||
var $item = $("#bookmark-"+index);
|
||||
$item.remove();
|
||||
});
|
||||
|
||||
return {
|
||||
"show" : show,
|
||||
"hide" : hide
|
||||
|
@ -280,9 +295,21 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
});
|
||||
|
||||
$bookmark.on("click", function() {
|
||||
$bookmark.addClass("icon-bookmark");
|
||||
$bookmark.removeClass("icon-bookmark-empty");
|
||||
reader.addBookmark(reader.book.getCurrentLocationCfi());
|
||||
var cfi = reader.book.getCurrentLocationCfi();
|
||||
var bookmarked = reader.isBookmarked(cfi);
|
||||
|
||||
if(bookmarked === -1) { //-- Add bookmark
|
||||
reader.addBookmark(cfi);
|
||||
$bookmark
|
||||
.addClass("icon-bookmark")
|
||||
.removeClass("icon-bookmark-empty");
|
||||
} else { //-- Remove Bookmark
|
||||
reader.removeBookmark(cfi);
|
||||
$bookmark
|
||||
.removeClass("icon-bookmark")
|
||||
.addClass("icon-bookmark-empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
book.on('renderer:pageChanged', function(cfi){
|
||||
|
|
|
@ -56,12 +56,13 @@ body {
|
|||
}
|
||||
|
||||
#titlebar a {
|
||||
visibility: hidden;
|
||||
width: 18px;
|
||||
height: 20px;
|
||||
overflow: hidden;
|
||||
display: inline-block;
|
||||
opacity: .5;
|
||||
padding: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
#titlebar a::before {
|
||||
|
@ -70,11 +71,15 @@ body {
|
|||
|
||||
#titlebar a:hover {
|
||||
opacity: .8;
|
||||
border: 1px rgba(0,0,0,.2) solid;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
#titlebar a:active {
|
||||
opacity: 1;
|
||||
margin: 1px -1px -1px 1px;
|
||||
color: rgba(0,0,0,.6);
|
||||
/* margin: 1px -1px -1px 1px; */
|
||||
-webkit-box-shadow: inset 0 0 6px rgba(155,155,155,.8);
|
||||
}
|
||||
|
||||
#book-title {
|
||||
|
|
4
demo/js/epub.min.js
vendored
4
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/reader.min.js
vendored
2
demo/js/reader.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,5 @@
|
|||
EPUBJS.reader.BookmarksController = function() {
|
||||
var reader = this;
|
||||
var book = this.book;
|
||||
|
||||
var $bookmarks = $("#bookmarksView"),
|
||||
|
@ -14,10 +15,13 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
$bookmarks.hide();
|
||||
};
|
||||
|
||||
var counter = 0;
|
||||
|
||||
var createBookmarkItem = function(cfi) {
|
||||
var listitem = document.createElement("li"),
|
||||
link = document.createElement("a");
|
||||
|
||||
listitem.id = "bookmark-"+counter;
|
||||
listitem.classList.add('list_item');
|
||||
|
||||
//-- TODO: Parse Cfi
|
||||
|
@ -33,6 +37,9 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
}, false);
|
||||
|
||||
listitem.appendChild(link);
|
||||
|
||||
counter++;
|
||||
|
||||
return listitem;
|
||||
};
|
||||
|
||||
|
@ -43,13 +50,16 @@ EPUBJS.reader.BookmarksController = function() {
|
|||
|
||||
$list.append(docfrag);
|
||||
|
||||
|
||||
|
||||
this.on("reader:bookmarked", function(cfi) {
|
||||
var item = createBookmarkItem(cfi);
|
||||
$list.append(item);
|
||||
});
|
||||
|
||||
this.on("reader:unbookmarked", function(index) {
|
||||
var $item = $("#bookmark-"+index);
|
||||
$item.remove();
|
||||
});
|
||||
|
||||
return {
|
||||
"show" : show,
|
||||
"hide" : hide
|
||||
|
|
|
@ -47,9 +47,21 @@ EPUBJS.reader.ControlsController = function(book) {
|
|||
});
|
||||
|
||||
$bookmark.on("click", function() {
|
||||
$bookmark.addClass("icon-bookmark");
|
||||
$bookmark.removeClass("icon-bookmark-empty");
|
||||
reader.addBookmark(reader.book.getCurrentLocationCfi());
|
||||
var cfi = reader.book.getCurrentLocationCfi();
|
||||
var bookmarked = reader.isBookmarked(cfi);
|
||||
|
||||
if(bookmarked === -1) { //-- Add bookmark
|
||||
reader.addBookmark(cfi);
|
||||
$bookmark
|
||||
.addClass("icon-bookmark")
|
||||
.removeClass("icon-bookmark-empty");
|
||||
} else { //-- Remove Bookmark
|
||||
reader.removeBookmark(cfi);
|
||||
$bookmark
|
||||
.removeClass("icon-bookmark")
|
||||
.addClass("icon-bookmark-empty");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
book.on('renderer:pageChanged', function(cfi){
|
||||
|
|
|
@ -43,10 +43,13 @@ EPUBJS.Reader = function(path, _options) {
|
|||
|
||||
this.book = book = new EPUBJS.Book({
|
||||
bookPath: path,
|
||||
restore: this.settings.restore,
|
||||
previousLocationCfi: this.settings.previousLocationCfi
|
||||
restore: this.settings.restore
|
||||
});
|
||||
|
||||
if(this.settings.previousLocationCfi) {
|
||||
book.gotoCfi(this.settings.previousLocationCfi);
|
||||
}
|
||||
|
||||
this.offline = false;
|
||||
this.sidebarOpen = false;
|
||||
if(!this.settings.bookmarks) {
|
||||
|
@ -96,9 +99,11 @@ EPUBJS.Reader.prototype.addBookmark = function(cfi) {
|
|||
|
||||
EPUBJS.Reader.prototype.removeBookmark = function(cfi) {
|
||||
var bookmark = this.isBookmarked(cfi);
|
||||
if(!bookmark === -1 ) return;
|
||||
if( bookmark === -1 ) return;
|
||||
|
||||
delete this.settings.bookmarks[bookmark];
|
||||
|
||||
this.trigger("reader:unbookmarked", bookmark);
|
||||
};
|
||||
|
||||
EPUBJS.Reader.prototype.isBookmarked = function(cfi) {
|
||||
|
|
17
src/book.js
17
src/book.js
|
@ -423,11 +423,11 @@ EPUBJS.Book.prototype.renderTo = function(elem){
|
|||
EPUBJS.Book.prototype.startDisplay = function(){
|
||||
var display;
|
||||
|
||||
if( this.settings.restore && this.settings.goto) {
|
||||
if(this.settings.goto) {
|
||||
|
||||
display = this.goto(this.settings.goto);
|
||||
|
||||
}else if( this.settings.restore && this.settings.previousLocationCfi) {
|
||||
}else if(this.settings.previousLocationCfi) {
|
||||
|
||||
display = this.displayChapter(this.settings.previousLocationCfi);
|
||||
|
||||
|
@ -593,14 +593,23 @@ EPUBJS.Book.prototype.getCurrentLocationCfi = function() {
|
|||
};
|
||||
|
||||
EPUBJS.Book.prototype.gotoCfi = function(cfi){
|
||||
if(!this.isRendered) return this._enqueue("gotoCfi", arguments);
|
||||
//if(!this.isRendered) return this._enqueue("gotoCfi", arguments);
|
||||
if(!this.isRendered) {
|
||||
this.settings.previousLocationCfi = cfi;
|
||||
return;
|
||||
}
|
||||
|
||||
return this.displayChapter(cfi);
|
||||
};
|
||||
|
||||
EPUBJS.Book.prototype.goto = function(url){
|
||||
var split, chapter, section, absoluteURL, spinePos;
|
||||
var deferred = new RSVP.defer();
|
||||
if(!this.isRendered) return this._enqueue("goto", arguments);
|
||||
//if(!this.isRendered) return this._enqueue("goto", arguments);
|
||||
if(!this.isRendered) {
|
||||
this.settings.goto = url;
|
||||
return;
|
||||
}
|
||||
|
||||
split = url.split("#");
|
||||
chapter = split[0];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue