Skip to content

Commit

Permalink
Clean up pageList
Browse files Browse the repository at this point in the history
  • Loading branch information
fchasen committed Nov 6, 2017
1 parent 68956ab commit c977fc1
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 82 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ node_js:
- "node"
notifications:
email: false
sudo: false
addons:
chrome: stable
cache:
directories:
- node_modules
script:
- npm test
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module.exports = function(config) {

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
browsers: ['ChromeHeadless'],


// Continuous Integration mode
Expand Down
96 changes: 64 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "test"
},
"scripts": {
"test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS",
"test": "./node_modules/.bin/karma start --single-run --browsers ChromeHeadless",
"documentation": "./node_modules/.bin/gulp docs",
"lint": "./node_modules/.bin/eslint -c .eslintrc.js src; exit 0",
"start": "./node_modules/.bin/webpack-dev-server --inline --d",
Expand Down Expand Up @@ -51,12 +51,13 @@
"jquery": "^3.2.1",
"jshint": "^2.9.5",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.4",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"mocha": "^3.5.0",
"mocha": "^3.5.3",
"mocha-loader": "^1.1.1",
"morgan": "^1.8.2",
"optimist": "^0.6.1",
Expand Down
7 changes: 5 additions & 2 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class Book {
/**
* @property {PageList} pagelist
*/
this.pageList = new PageList();
this.pageList = undefined;

/**
* @property {Url} url
Expand Down Expand Up @@ -441,11 +441,14 @@ class Book {
let navPath = opf.navPath || opf.ncxPath;
let toc = opf.toc;

// From json manifest
if (toc) {
return new Promise((resolve, reject) => {
this.navigation = new Navigation(toc);

this.pageList = new PageList(); // TODO: handle page lists
if (opf.pageList) {
this.pageList = new PageList(opf.pageList); // TODO: handle page lists from Manifest
}

resolve(this.navigation);
});
Expand Down
47 changes: 2 additions & 45 deletions src/pagelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class PageList {
this.toc = undefined;
this.ncx = undefined;

this.lastPage
if (xml) {
this.pageList = this.parse(xml);
}
Expand All @@ -43,9 +42,9 @@ class PageList {
var ncx = qs(xml, "ncx");

if(html) {
this.toc = this.parseNav(xml);
return this.parseNav(xml);
} else if(ncx){ // Not supported
// this.toc = this.parseNcx(xml);
// return this.parseNcx(xml);
return;
}

Expand Down Expand Up @@ -126,48 +125,6 @@ class PageList {
this.totalPages = this.lastPage - this.firstPage;
}


/**
* Replace HREFs with CFI
* TODO: implement getting CFI from Href
*/
addCFIs() {
this.pageList.forEach(function(pg){
if(!pg.cfi) {
// epubcfi.generateCfiFromHref(pg.href, book).then(function(cfi){
// pg.cfi = cfi;
// pg.packageUrl = book.settings.packageUrl;
// });
}
});
}

/*
EPUBJS.generateCfiFromHref(href, book) {
var uri = EPUBJS.core.uri(href);
var path = uri.path;
var fragment = uri.fragment;
var spinePos = book.spineIndexByURL[path];
var loaded;
var deferred = new RSVP.defer();
var epubcfi = new EPUBJS.EpubCFI();
var spineItem;
if(typeof spinePos !== "undefined"){
spineItem = book.spine[spinePos];
loaded = book.loadXml(spineItem.url);
loaded.then(function(doc){
var element = doc.getElementById(fragment);
var cfi;
cfi = epubcfi.generateCfiFromElement(element, spineItem.cfiBase);
deferred.resolve(cfi);
});
}
return deferred.promise;
}
*/

/**
* Get a PageList result from a EpubCFI
* @param {string} cfi EpubCFI String
Expand Down

0 comments on commit c977fc1

Please sign in to comment.