mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Updated URL parsing to handle remote book paths
This commit is contained in:
parent
b6b48e0b08
commit
fe8edc77c1
3 changed files with 34 additions and 9 deletions
|
@ -79,7 +79,7 @@
|
||||||
var currentSection;
|
var currentSection;
|
||||||
var currentSectionIndex = 7;
|
var currentSectionIndex = 7;
|
||||||
|
|
||||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
|
||||||
book.loaded.navigation.then(function(nav){
|
book.loaded.navigation.then(function(nav){
|
||||||
var toc = nav.get();
|
var toc = nav.get();
|
||||||
var $select = document.getElementById("toc"),
|
var $select = document.getElementById("toc"),
|
||||||
|
|
|
@ -3,7 +3,7 @@ EPUBJS.Book = function(_url){
|
||||||
this.opening = new RSVP.defer();
|
this.opening = new RSVP.defer();
|
||||||
this.opened = this.opening.promise;
|
this.opened = this.opening.promise;
|
||||||
|
|
||||||
this.baseUrl = undefined;
|
this.url = undefined;
|
||||||
|
|
||||||
this.spine = undefined;
|
this.spine = undefined;
|
||||||
|
|
||||||
|
@ -59,9 +59,14 @@ EPUBJS.Book.prototype.open = function(_url){
|
||||||
// Find path to the Container
|
// Find path to the Container
|
||||||
if(uri.extension === "opf") {
|
if(uri.extension === "opf") {
|
||||||
// Direct link to package, no container
|
// Direct link to package, no container
|
||||||
this.packageUrl = uri.path;
|
this.packageUrl = uri.href;
|
||||||
this.containerUrl = '';
|
this.containerUrl = '';
|
||||||
|
|
||||||
|
if(uri.origin) {
|
||||||
|
this.url = uri.origin + "/" + uri.directory;
|
||||||
|
} else {
|
||||||
this.url = uri.directory;
|
this.url = uri.directory;
|
||||||
|
}
|
||||||
|
|
||||||
epubPackage = this.request(this.packageUrl);
|
epubPackage = this.request(this.packageUrl);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,26 @@ asyncTest("Open using ePub(/path/to/epub/package.opf)", 1, function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest("Open Remote ePub", 1, function() {
|
||||||
|
|
||||||
|
var book = ePub("https://s3.amazonaws.com/moby-dick/");
|
||||||
|
book.opened.then(function(){
|
||||||
|
equal( book.packageUrl, "https://s3.amazonaws.com/moby-dick/OPS/package.opf", "packageUrl is set" );
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
asyncTest("Open Remote ePub from Package", 1, function() {
|
||||||
|
|
||||||
|
var book = ePub("https://s3.amazonaws.com/moby-dick/OPS/package.opf");
|
||||||
|
book.opened.then(function(){
|
||||||
|
equal( book.packageUrl, "https://s3.amazonaws.com/moby-dick/OPS/package.opf", "packageUrl is set" );
|
||||||
|
start();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
asyncTest("Find Epub Package", 1, function() {
|
asyncTest("Find Epub Package", 1, function() {
|
||||||
|
|
||||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
var book = ePub("../books/moby-dick/OPS/package.opf");
|
||||||
|
@ -126,8 +146,8 @@ asyncTest("Find Item by Href", 2, function() {
|
||||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
var book = ePub("../books/moby-dick/OPS/package.opf");
|
||||||
book.opened.then(function(){
|
book.opened.then(function(){
|
||||||
var section = book.spine.get("chapter_001.xhtml");
|
var section = book.spine.get("chapter_001.xhtml");
|
||||||
equal( section.href, "epigraph_001.xhtml", "chap 1 spine item href found" );
|
equal( section.href, "chapter_001.xhtml", "chap 1 spine item href found" );
|
||||||
equal( section.cfiBase, "/6/12[xepigraph_001]", "chap 1 spine item cfi found" );
|
equal( section.cfiBase, "/6/14[xchapter_001]", "chap 1 spine item cfi found" );
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
@ -139,8 +159,8 @@ asyncTest("Find Item by ID", 2, function() {
|
||||||
var book = ePub("../books/moby-dick/OPS/package.opf");
|
var book = ePub("../books/moby-dick/OPS/package.opf");
|
||||||
book.opened.then(function(){
|
book.opened.then(function(){
|
||||||
var section = book.spine.get("#xchapter_050");
|
var section = book.spine.get("#xchapter_050");
|
||||||
equal( section.href, "chapter_049.xhtml", "chap 50 spine item href found" );
|
equal( section.href, "chapter_050.xhtml", "chap 50 spine item href found" );
|
||||||
equal( section.cfiBase, "/6/110[xchapter_049]", "chap 50 spine item cfi found" );
|
equal( section.cfiBase, "/6/112[xchapter_050]", "chap 50 spine item cfi found" );
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
@ -153,7 +173,7 @@ asyncTest("Render Spine Item", 1, function() {
|
||||||
book.opened.then(function(){
|
book.opened.then(function(){
|
||||||
var section = book.spine.get("#xchapter_050");
|
var section = book.spine.get("#xchapter_050");
|
||||||
section.render().then(function(content){
|
section.render().then(function(content){
|
||||||
equal( content.substring(303, 334), "<h1>Chapter 49. The Hyena.</h1>", "Chapter text rendered as string" );
|
equal( content.substring(303, 355), "<h1>Chapter 50. Ahab’s Boat and Crew. Fedallah.</h1>", "Chapter text rendered as string" );
|
||||||
});
|
});
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue