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

inital setup/cleaning for v3

This commit is contained in:
Fred Chasen 2014-07-23 13:31:34 -04:00
parent 1af6322367
commit b6b48e0b08
430 changed files with 2018 additions and 95437 deletions

91
lib/epubjs/spine.js Normal file
View file

@ -0,0 +1,91 @@
EPUBJS.Spine = function(_package, _request){
this.items = _package.spine;
this.manifest = _package.manifest;
this.spineNodeIndex = _package.spineNodeIndex;
this.baseUrl = _package.baseUrl || '';
this.request = _request;
this.length = this.items.length;
this.epubcfi = new EPUBJS.EpubCFI();
this.spineItems = [];
this.spineByHref = {};
this.spineById = {};
this.items.forEach(function(item, index){
var cfiBase = this.epubcfi.generateChapterComponent(this.spineNodeIndex, item.index, item.idref);
var href, url;
var manifestItem = this.manifest[item.idref];
var spineItem;
if(manifestItem) {
href = manifestItem.href;
url = this.baseUrl + href;
}
spineItem = new EPUBJS.SpineItem(item, href, url, cfiBase);
this.spineItems.push(spineItem);
this.spineByHref[spineItem.href] = index;
this.spineById[spineItem.idref] = index;
}.bind(this));
};
// book.spine.get();
// book.spine.get(1);
// book.spine.get("chap1.html");
// book.spine.get("#id1234");
EPUBJS.Spine.prototype.get = function(target) {
var index = 1;
if(typeof target === "number" || isNaN(target) === false){
index = target-1;
} else if(target.indexOf("#") === 0) {
index = this.spineById[target.substring(1)];
} else {
index = this.spineByHref[target];
}
return this.spineItems[index];
};
EPUBJS.SpineItem = function(item, href, url, cfiBase){
this.idref = item.idref;
this.linear = item.linear;
this.properties = item.properties;
this.index = item.index;
this.href = href;
this.url = url;
this.cfiBase = cfiBase;
};
EPUBJS.SpineItem.prototype.load = function(_request){
var request = _request || this.request || EPUBJS.core.request;
var loading = new RSVP.defer();
var loaded = loading.promise;
if(this.contents) {
loading.resolve(this.contents);
} else {
request(this.url, 'xml').then(function(xml){
this.contents = xml.documentElement;
loading.resolve(this.contents);
}.bind(this));
}
return loaded;
};
EPUBJS.SpineItem.prototype.render = function(){
return this.load().then(function(contents){
var serializer = new XMLSerializer();
return serializer.serializeToString(contents);
});
};
EPUBJS.SpineItem.prototype.find = function(_query){
};