mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Tabify src
This commit is contained in:
parent
f6247e5612
commit
32993dc58c
31 changed files with 7759 additions and 7758 deletions
|
@ -4,99 +4,99 @@ var RSVP = require('rsvp');
|
|||
var URI = require('urijs');
|
||||
|
||||
function Navigation(_package, _request){
|
||||
var navigation = this;
|
||||
var parse = new Parser();
|
||||
var request = _request || require('./request');
|
||||
var navigation = this;
|
||||
var parse = new Parser();
|
||||
var request = _request || require('./request');
|
||||
|
||||
this.package = _package;
|
||||
this.toc = [];
|
||||
this.tocByHref = {};
|
||||
this.tocById = {};
|
||||
this.package = _package;
|
||||
this.toc = [];
|
||||
this.tocByHref = {};
|
||||
this.tocById = {};
|
||||
|
||||
if(_package.navPath) {
|
||||
this.navUrl = URI(_package.navPath).absoluteTo(_package.baseUrl).toString();
|
||||
this.nav = {};
|
||||
if(_package.navPath) {
|
||||
this.navUrl = URI(_package.navPath).absoluteTo(_package.baseUrl).toString();
|
||||
this.nav = {};
|
||||
|
||||
this.nav.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
this.nav.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
|
||||
request(navigation.navUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.nav(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
request(navigation.navUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.nav(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
|
||||
return loaded;
|
||||
};
|
||||
return loaded;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(_package.ncxPath) {
|
||||
this.ncxUrl = URI(_package.ncxPath).absoluteTo(_package.baseUrl).toString();
|
||||
this.ncx = {};
|
||||
if(_package.ncxPath) {
|
||||
this.ncxUrl = URI(_package.ncxPath).absoluteTo(_package.baseUrl).toString();
|
||||
this.ncx = {};
|
||||
|
||||
this.ncx.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
this.ncx.load = function(_request){
|
||||
var loading = new RSVP.defer();
|
||||
var loaded = loading.promise;
|
||||
|
||||
request(navigation.ncxUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.toc(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
request(navigation.ncxUrl, 'xml').then(function(xml){
|
||||
navigation.toc = parse.toc(xml);
|
||||
navigation.loaded(navigation.toc);
|
||||
loading.resolve(navigation.toc);
|
||||
});
|
||||
|
||||
return loaded;
|
||||
};
|
||||
return loaded;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Load the navigation
|
||||
Navigation.prototype.load = function(_request) {
|
||||
var request = _request || require('./request');
|
||||
var loading, loaded;
|
||||
var request = _request || require('./request');
|
||||
var loading, loaded;
|
||||
|
||||
if(this.nav) {
|
||||
loading = this.nav.load();
|
||||
} else if(this.ncx) {
|
||||
loading = this.ncx.load();
|
||||
} else {
|
||||
loaded = new RSVP.defer();
|
||||
loaded.resolve([]);
|
||||
loading = loaded.promise;
|
||||
}
|
||||
if(this.nav) {
|
||||
loading = this.nav.load();
|
||||
} else if(this.ncx) {
|
||||
loading = this.ncx.load();
|
||||
} else {
|
||||
loaded = new RSVP.defer();
|
||||
loaded.resolve([]);
|
||||
loading = loaded.promise;
|
||||
}
|
||||
|
||||
return loading;
|
||||
return loading;
|
||||
|
||||
};
|
||||
|
||||
Navigation.prototype.loaded = function(toc) {
|
||||
var item;
|
||||
var item;
|
||||
|
||||
for (var i = 0; i < toc.length; i++) {
|
||||
item = toc[i];
|
||||
this.tocByHref[item.href] = i;
|
||||
this.tocById[item.id] = i;
|
||||
}
|
||||
for (var i = 0; i < toc.length; i++) {
|
||||
item = toc[i];
|
||||
this.tocByHref[item.href] = i;
|
||||
this.tocById[item.id] = i;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Get an item from the navigation
|
||||
Navigation.prototype.get = function(target) {
|
||||
var index;
|
||||
var index;
|
||||
|
||||
if(!target) {
|
||||
return this.toc;
|
||||
}
|
||||
if(!target) {
|
||||
return this.toc;
|
||||
}
|
||||
|
||||
if(target.indexOf("#") === 0) {
|
||||
index = this.tocById[target.substring(1)];
|
||||
} else if(target in this.tocByHref){
|
||||
index = this.tocByHref[target];
|
||||
}
|
||||
if(target.indexOf("#") === 0) {
|
||||
index = this.tocById[target.substring(1)];
|
||||
} else if(target in this.tocByHref){
|
||||
index = this.tocByHref[target];
|
||||
}
|
||||
|
||||
return this.toc[index];
|
||||
return this.toc[index];
|
||||
};
|
||||
|
||||
module.exports = Navigation;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue