mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
Fix url to handle file links
This commit is contained in:
parent
d6eeb2a458
commit
265df07917
6 changed files with 130 additions and 37 deletions
|
@ -20,7 +20,7 @@
|
|||
<script>
|
||||
var currentSectionIndex = 8;
|
||||
// Load the opf
|
||||
var book = ePub("https://s3.amazonaws.com/epubjs/books/alice/OPS/package.opf");
|
||||
var book = ePub("http://localhost:8080/books/1456.epub");
|
||||
var rendition = book.renderTo("viewer", {
|
||||
width: "100%",
|
||||
height: 600
|
||||
|
|
|
@ -594,8 +594,9 @@
|
|||
// Gecko returns String("") for file: mailto:
|
||||
// WebKit/Blink returns String("SCHEME://") for file: mailto:
|
||||
switch (this._scheme) {
|
||||
case 'data':
|
||||
case 'file':
|
||||
return 'file://'
|
||||
case 'data':
|
||||
case 'javascript':
|
||||
case 'mailto':
|
||||
return 'null';
|
||||
|
|
68
package.json
68
package.json
|
@ -23,57 +23,57 @@
|
|||
"author": "fchasen@gmail.com",
|
||||
"license": "BSD-2-Clause",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.18.0",
|
||||
"babel-core": "^6.18.2",
|
||||
"babel-loader": "^6.2.8",
|
||||
"babel-cli": "^6.22.2",
|
||||
"babel-core": "^6.22.1",
|
||||
"babel-loader": "^6.2.10",
|
||||
"babel-plugin-add-module-exports": "^0.2.1",
|
||||
"babel-plugin-transform-runtime": "^6.15.0",
|
||||
"babel-polyfill": "^6.16.0",
|
||||
"babel-preset-env": "1.0.2",
|
||||
"babel-preset-es2015": "^6.18.0",
|
||||
"babili-webpack-plugin": "0.0.7",
|
||||
"babel-plugin-transform-runtime": "^6.22.0",
|
||||
"babel-polyfill": "^6.22.0",
|
||||
"babel-preset-env": "1.1.8",
|
||||
"babel-preset-es2015": "^6.22.0",
|
||||
"babili-webpack-plugin": "0.0.10",
|
||||
"colors": "^1.1.2",
|
||||
"connect": "^3.0.1",
|
||||
"eslint": "^3.11.1",
|
||||
"express": "^4.5.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-concat": "^2.3.4",
|
||||
"connect": "^3.5.0",
|
||||
"eslint": "^3.15.0",
|
||||
"express": "^4.14.1",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-concat": "^2.6.1",
|
||||
"gulp-connect": "~5.0.0",
|
||||
"gulp-documentation": "fchasen/gulp-documentation",
|
||||
"gulp-jshint": "^2.0.0",
|
||||
"gulp-jshint": "^2.0.4",
|
||||
"gulp-plumber": "^1.1.0",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-size": "^2.0.0",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-uglify": "^2.0.0",
|
||||
"gulp-util": "^3.0.0",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-size": "^2.1.0",
|
||||
"gulp-sourcemaps": "^2.4.1",
|
||||
"gulp-uglify": "^2.0.1",
|
||||
"gulp-util": "^3.0.8",
|
||||
"jquery": "^3.1.1",
|
||||
"jshint": "^2.9.3",
|
||||
"karma": "^1.3.0",
|
||||
"karma-mocha": "^1.2.0",
|
||||
"karma-mocha-reporter": "^2.2.0",
|
||||
"jshint": "^2.9.4",
|
||||
"karma": "^1.4.1",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-mocha-reporter": "^2.2.2",
|
||||
"karma-phantomjs-launcher": "^1.0.2",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-webpack": "^1.8.0",
|
||||
"mocha": "^3.1.2",
|
||||
"mocha-loader": "^1.0.0",
|
||||
"morgan": "^1.1.1",
|
||||
"karma-webpack": "^2.0.2",
|
||||
"mocha": "^3.2.0",
|
||||
"mocha-loader": "^1.1.0",
|
||||
"morgan": "^1.8.0",
|
||||
"optimist": "^0.6.1",
|
||||
"portfinder": "^1.0.2",
|
||||
"portfinder": "^1.0.13",
|
||||
"raw-loader": "^0.5.1",
|
||||
"serve-static": "^1.3.1",
|
||||
"serve-static": "^1.11.2",
|
||||
"uglify": "^0.1.5",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0",
|
||||
"webpack": "^v2.1.0-beta.25",
|
||||
"webpack-dev-middleware": "^1.8.4",
|
||||
"webpack-dev-server": "^v2.1.0-beta.10"
|
||||
"webpack": "^v2.2.1",
|
||||
"webpack-dev-middleware": "^1.10.0",
|
||||
"webpack-dev-server": "^v2.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"event-emitter": "^0.3.4",
|
||||
"jszip": "^3.1.1",
|
||||
"jszip": "^3.1.3",
|
||||
"path-webpack": "^0.0.2",
|
||||
"stream-browserify": "^2.0.1",
|
||||
"xmldom": "^0.1.22"
|
||||
"xmldom": "^0.1.27"
|
||||
}
|
||||
}
|
||||
|
|
61
src/book.js
61
src/book.js
|
@ -143,6 +143,28 @@ class Book {
|
|||
*/
|
||||
this.archived = false;
|
||||
|
||||
/**
|
||||
* @property {Archive} archive
|
||||
* @private
|
||||
*/
|
||||
this.archive = undefined;
|
||||
|
||||
/**
|
||||
* @property {Resources} resources
|
||||
* @private
|
||||
*/
|
||||
this.resources = undefined;
|
||||
|
||||
/**
|
||||
* @property {Rendition} rendition
|
||||
* @private
|
||||
*/
|
||||
this.rendition = undefined;
|
||||
|
||||
this.container = undefined;
|
||||
this.packaging = undefined;
|
||||
this.toc = undefined;
|
||||
|
||||
if(url) {
|
||||
this.open(url).catch((error) => {
|
||||
var err = new Error("Cannot load book at "+ url );
|
||||
|
@ -258,6 +280,9 @@ class Book {
|
|||
* @return {string} the resolved path string
|
||||
*/
|
||||
resolve(path, absolute) {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
var resolved = path;
|
||||
var isAbsolute = (path.indexOf("://") > -1);
|
||||
|
||||
|
@ -347,7 +372,7 @@ class Book {
|
|||
|
||||
this.isOpen = true;
|
||||
|
||||
if(this.archived) {
|
||||
if(this.archived || this.settings.replacements) {
|
||||
this.replacements().then(() => {
|
||||
this.opening.resolve(this);
|
||||
});
|
||||
|
@ -492,6 +517,40 @@ class Book {
|
|||
return `epubjs:${EPUBJS_VERSION}:${ident}`;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.opened = undefined;
|
||||
this.loading = undefined;
|
||||
this.loaded = undefined;
|
||||
this.ready = undefined;
|
||||
|
||||
this.isOpen = false;
|
||||
this.isRendered = false;
|
||||
|
||||
this.spine && this.spine.destroy();
|
||||
this.locations && this.locations.destroy();
|
||||
this.pageList && this.pageList.destroy();
|
||||
this.archive && this.archive.destroy();
|
||||
this.resources && this.resources.destroy();
|
||||
this.container && this.container.destroy();
|
||||
this.packaging && this.packaging.destroy();
|
||||
this.rendition && this.rendition.destroy();
|
||||
|
||||
this.spine = undefined;
|
||||
this.locations = undefined;
|
||||
this.pageList = undefined;
|
||||
this.archive = undefined;
|
||||
this.resources = undefined;
|
||||
this.container = undefined;
|
||||
this.packaging = undefined;
|
||||
this.rendition = undefined;
|
||||
|
||||
this.navigation = undefined;
|
||||
this.url = undefined;
|
||||
this.path = undefined;
|
||||
this.archived = false;
|
||||
this.toc = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-- Enable binding events to book
|
||||
|
|
|
@ -156,6 +156,10 @@ class Spine {
|
|||
each() {
|
||||
return this.spineItems.forEach.apply(this.spineItems, arguments);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default Spine;
|
||||
|
|
29
test/core.js
29
test/core.js
|
@ -56,6 +56,35 @@ describe('Core', function() {
|
|||
assert.equal( resolved, "http://example.com/derf.html" );
|
||||
});
|
||||
|
||||
// Doesn't work with path.parse
|
||||
xit("should handle directory with a dot", function() {
|
||||
var a = "http://example.com/fred/chasen/index.epub/";
|
||||
|
||||
var url = new Url(a);
|
||||
assert.equal( url.directory, "/fred/chasen/index.epub/" );
|
||||
assert.equal( url.extension, "" );
|
||||
});
|
||||
|
||||
it("should handle file urls", function() {
|
||||
var url = new Url("file:///var/mobile/Containers/Data/Application/F47E4434-9B98-4654-93F1-702336B08EE6/Documents/books/moby-dick/derf.html");
|
||||
|
||||
assert.equal( url.href, "file:///var/mobile/Containers/Data/Application/F47E4434-9B98-4654-93F1-702336B08EE6/Documents/books/moby-dick/derf.html" );
|
||||
assert.equal( url.directory, "/var/mobile/Containers/Data/Application/F47E4434-9B98-4654-93F1-702336B08EE6/Documents/books/moby-dick/" );
|
||||
assert.equal( url.extension, "html" );
|
||||
assert.equal( url.filename, "derf.html" );
|
||||
assert.equal( url.origin, "file://" ); // origin should be blank
|
||||
assert.equal( url.protocol, "file:" );
|
||||
assert.equal( url.search, "" );
|
||||
});
|
||||
|
||||
it("should resolve with file urls", function() {
|
||||
var a = "file:///var/mobile/Containers/Data/Application/books/";
|
||||
var b = "derf.html";
|
||||
|
||||
var resolved = new Url(a).resolve(b);
|
||||
assert.equal( resolved, "file:///var/mobile/Containers/Data/Application/books/derf.html" );
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue