mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
basic scrolling renderer
This commit is contained in:
parent
849625fc83
commit
b1b98f9d57
15 changed files with 1020 additions and 22 deletions
|
@ -37,13 +37,13 @@ EPUBJS.Spine = function(_package, _request){
|
|||
// book.spine.get("chap1.html");
|
||||
// book.spine.get("#id1234");
|
||||
EPUBJS.Spine.prototype.get = function(target) {
|
||||
var index = 1;
|
||||
var index = 0;
|
||||
|
||||
if(typeof target === "number" || isNaN(target) === false){
|
||||
index = target-1;
|
||||
} else if(target.indexOf("#") === 0) {
|
||||
if(target && (typeof target === "number" || isNaN(target) === false)){
|
||||
index = target;
|
||||
} else if(target && target.indexOf("#") === 0) {
|
||||
index = this.spineById[target.substring(1)];
|
||||
} else {
|
||||
} else if(target) {
|
||||
index = this.spineByHref[target];
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,13 @@ EPUBJS.SpineItem.prototype.load = function(_request){
|
|||
loading.resolve(this.contents);
|
||||
} else {
|
||||
request(this.url, 'xml').then(function(xml){
|
||||
var base;
|
||||
var directory = EPUBJS.core.folder(this.url);
|
||||
this.document = xml;
|
||||
this.contents = xml.documentElement;
|
||||
|
||||
this.replacements(this.document);
|
||||
|
||||
loading.resolve(this.contents);
|
||||
}.bind(this));
|
||||
}
|
||||
|
@ -79,11 +85,23 @@ EPUBJS.SpineItem.prototype.load = function(_request){
|
|||
return loaded;
|
||||
};
|
||||
|
||||
EPUBJS.SpineItem.prototype.replacements = function(_document){
|
||||
var base = _document.createElement("base");
|
||||
base.setAttribute("href", this.url);
|
||||
_document.head.insertBefore(base, _document.head.firstChild);
|
||||
};
|
||||
|
||||
EPUBJS.SpineItem.prototype.render = function(){
|
||||
return this.load().then(function(contents){
|
||||
var rendering = new RSVP.defer();
|
||||
var rendered = rendering.promise;
|
||||
|
||||
this.load().then(function(contents){
|
||||
var serializer = new XMLSerializer();
|
||||
return serializer.serializeToString(contents);
|
||||
var output = serializer.serializeToString(contents);
|
||||
rendering.resolve(output);
|
||||
});
|
||||
|
||||
return rendered;
|
||||
};
|
||||
|
||||
EPUBJS.SpineItem.prototype.find = function(_query){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue