From 7c8c1adac93370e0e3c5eb605158d7a76e16f62c Mon Sep 17 00:00:00 2001 From: Aferdita Muriqi Date: Thu, 2 Apr 2020 18:28:06 -0400 Subject: [PATCH] updated last navigated url to relative url --- package-lock.json | 2 +- package.json | 2 +- src/index.ts | 10 +++++----- src/model/Publication.ts | 5 +++++ src/navigator/IFrameNavigator.ts | 4 ++-- viewer/index_api.html | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 69fe3621..e5c9d91c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@d-i-t-a/reader", - "version": "1.0.8", + "version": "1.0.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f88b49f1..1b194ae7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@d-i-t-a/reader", - "version": "1.0.8", + "version": "1.0.9", "description": "A viewer application for EPUB files.", "repository": "https://github.com/d-i-t-a/R2D2BC", "main": "src/index.js", diff --git a/src/index.ts b/src/index.ts index 8eecc5ee..37b8535c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,9 +59,9 @@ export function currentResource() { if (IS_DEV) { console.log("currentResource") } return R2Navigator.currentResource() } -export function currentTocHref() { - if (IS_DEV) { console.log("currentTocHref") } - return R2Navigator.currentTocHref() +export function mostRecentNavigatedTocItem() { + if (IS_DEV) { console.log("mostRecentNavigatedTocItem") } + return R2Navigator.mostRecentNavigatedTocItem() } export function totalResources() { if (IS_DEV) { console.log("totalResources") } @@ -266,8 +266,8 @@ exports.annotations = function () { exports.currentResource = function() { return currentResource() } -exports.currentTocHref = function() { - return currentTocHref() +exports.mostRecentNavigatedTocItem = function() { + return mostRecentNavigatedTocItem() } exports.totalResources = function() { return totalResources() diff --git a/src/model/Publication.ts b/src/model/Publication.ts index 74354a24..7ec03ea1 100644 --- a/src/model/Publication.ts +++ b/src/model/Publication.ts @@ -152,6 +152,11 @@ export default class Publication { public getAbsoluteHref(href: string): string | null { return new URL(href, this.manifestUrl.href).href; } + public getRelativeHref(href: string): string | null { + const manifest = this.manifestUrl.href.replace("/manifest.json", ""); //new URL(this.manifestUrl.href, this.manifestUrl.href).href; + return href.replace(manifest, ""); + } + public getTOCItemAbsolute(href: string): Link | null { const absolute = this.getAbsoluteHref(href) diff --git a/src/navigator/IFrameNavigator.ts b/src/navigator/IFrameNavigator.ts index c58e86e9..e90d30f9 100644 --- a/src/navigator/IFrameNavigator.ts +++ b/src/navigator/IFrameNavigator.ts @@ -1000,8 +1000,8 @@ export default class IFrameNavigator implements Navigator { totalResources(): number { return this.publication.readingOrder.length } - currentTocHref(): string { - return this.currentTOCRawLink + mostRecentNavigatedTocItem(): string { + return this.publication.getRelativeHref(this.currentTOCRawLink) } currentResource(): number { let currentLocation = this.currentChapterLink.href diff --git a/viewer/index_api.html b/viewer/index_api.html index 759472a3..3bf2294f 100644 --- a/viewer/index_api.html +++ b/viewer/index_api.html @@ -36,7 +36,7 @@

-
+