mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
add destroy methods
This commit is contained in:
parent
265df07917
commit
db727b00a9
11 changed files with 183 additions and 4 deletions
|
@ -20,7 +20,7 @@
|
|||
<script>
|
||||
var currentSectionIndex = 8;
|
||||
// Load the opf
|
||||
var book = ePub("http://localhost:8080/books/1456.epub");
|
||||
var book = ePub("http://localhost:8080/books/moby-dick.epub");
|
||||
var rendition = book.renderTo("viewer", {
|
||||
width: "100%",
|
||||
height: 600
|
||||
|
@ -88,6 +88,11 @@
|
|||
console.log(location);
|
||||
});
|
||||
|
||||
window.addEventListener("unload", function () {
|
||||
console.log("unloading");
|
||||
this.book.destroy();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -11,8 +11,10 @@ class Archive {
|
|||
|
||||
constructor() {
|
||||
this.zip = undefined;
|
||||
this.checkRequirements();
|
||||
this.urlCache = {};
|
||||
|
||||
this.checkRequirements();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,6 +245,13 @@ class Archive {
|
|||
var fromCache = this.urlCache[url];
|
||||
if(fromCache) _URL.revokeObjectURL(fromCache);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.urlCache.forEach((fromCache) => _URL.revokeObjectURL(fromCache));
|
||||
|
||||
this.zip = undefined;
|
||||
this.urlCache = {};
|
||||
}
|
||||
}
|
||||
|
||||
export default Archive;
|
||||
|
|
|
@ -8,6 +8,10 @@ import {qs} from "./utils/core";
|
|||
*/
|
||||
class Container {
|
||||
constructor(containerDocument) {
|
||||
this.packagePath = '';
|
||||
this.directory = '';
|
||||
this.encoding = '';
|
||||
|
||||
if (containerDocument) {
|
||||
this.parse(containerDocument);
|
||||
}
|
||||
|
@ -35,6 +39,12 @@ class Container {
|
|||
this.directory = path.dirname(this.packagePath);
|
||||
this.encoding = containerDocument.xmlEncoding;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.packagePath = undefined;
|
||||
this.directory = undefined;
|
||||
this.encoding = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default Container;
|
||||
|
|
|
@ -23,6 +23,10 @@ class Locations {
|
|||
this.break = 150;
|
||||
|
||||
this._current = 0;
|
||||
|
||||
this.currentLocation = '';
|
||||
this._currentCfi ='';
|
||||
this.processingTimeout = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +80,7 @@ class Locations {
|
|||
|
||||
section.unload();
|
||||
|
||||
setTimeout(() => completed.resolve(locations), this.pause);
|
||||
this.processingTimeout = setTimeout(() => completed.resolve(locations), this.pause);
|
||||
return completed.promise;
|
||||
}.bind(this));
|
||||
|
||||
|
@ -257,6 +261,26 @@ class Locations {
|
|||
length () {
|
||||
return this._locations.length;
|
||||
}
|
||||
|
||||
destroy () {
|
||||
this.spine = undefined;
|
||||
this.request = undefined;
|
||||
this.pause = undefined;
|
||||
|
||||
this.q.clear();
|
||||
this.q = undefined;
|
||||
this.epubcfi = undefined;
|
||||
|
||||
this._locations = undefined
|
||||
this.total = undefined;
|
||||
|
||||
this.break = undefined;
|
||||
this._current = undefined;
|
||||
|
||||
this.currentLocation = undefined;
|
||||
this._currentCfi = undefined;
|
||||
clearTimeout(this.processingTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
EventEmitter(Locations.prototype);
|
||||
|
|
|
@ -7,6 +7,14 @@ import {qs, qsa, qsp} from "./utils/core";
|
|||
*/
|
||||
class Packaging {
|
||||
constructor(packageDocument) {
|
||||
this.manifest = {};
|
||||
this.navPath = '';
|
||||
this.ncxPath = '';
|
||||
this.coverPath = '';
|
||||
this.spineNodeIndex = 0;
|
||||
this.spine = [];
|
||||
this.metadata = {};
|
||||
|
||||
if (packageDocument) {
|
||||
this.parse(packageDocument);
|
||||
}
|
||||
|
@ -273,6 +281,16 @@ class Packaging {
|
|||
|
||||
return "";
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.manifest = undefined;
|
||||
this.navPath = undefined;
|
||||
this.ncxPath = undefined;
|
||||
this.coverPath = undefined;
|
||||
this.spineNodeIndex = undefined;
|
||||
this.spine = undefined;
|
||||
this.metadata = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default Packaging;
|
||||
|
|
|
@ -17,6 +17,14 @@ class PageList {
|
|||
this.locations = [];
|
||||
this.epubcfi = new EpubCFI();
|
||||
|
||||
this.firstPage = 0;
|
||||
this.lastPage = 0;
|
||||
this.totalPages = 0;
|
||||
|
||||
this.toc = undefined;
|
||||
this.ncx = undefined;
|
||||
|
||||
this.lastPage
|
||||
if (xml) {
|
||||
this.pageList = this.parse(xml);
|
||||
}
|
||||
|
@ -250,6 +258,17 @@ class PageList {
|
|||
var percentage = this.percentageFromPage(pg);
|
||||
return percentage;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.pages = undefined;
|
||||
this.locations = undefined;
|
||||
this.epubcfi = undefined;
|
||||
|
||||
this.pageList = undefined;
|
||||
|
||||
this.toc = undefined;
|
||||
this.ncx = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default PageList;
|
||||
|
|
|
@ -514,8 +514,29 @@ class Rendition {
|
|||
destroy(){
|
||||
// Clear the queue
|
||||
this.q.clear();
|
||||
this.q = undefined;
|
||||
|
||||
this.manager.destroy();
|
||||
this.book = book;
|
||||
|
||||
this.views = null;
|
||||
|
||||
this.hooks.display.clear();
|
||||
this.hooks.serialize.clear();
|
||||
this.hooks.content.clear();
|
||||
this.hooks.layout.clear();
|
||||
this.hooks.render.clear();
|
||||
this.hooks.show.clear();
|
||||
this.hooks = {};
|
||||
|
||||
this.themes.destroy();
|
||||
this.themes = undefined;
|
||||
|
||||
this.epubcfi = undefined;
|
||||
|
||||
this.starting = undefined;
|
||||
this.started = undefined;
|
||||
|
||||
this.manager && this.manager.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,6 +27,13 @@ class Resources {
|
|||
|
||||
this.replacementUrls = [];
|
||||
|
||||
this.html = [];
|
||||
this.assets = [];
|
||||
this.css = [];
|
||||
|
||||
this.urls = [];
|
||||
this.cssUrls = [];
|
||||
|
||||
this.split();
|
||||
this.splitUrls();
|
||||
}
|
||||
|
@ -259,6 +266,19 @@ class Resources {
|
|||
}
|
||||
return substitute(content, relUrls, this.replacementUrls);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.settings = undefined;
|
||||
this.manifest = undefined;
|
||||
this.resources = undefined;
|
||||
this.replacementUrls = undefined;
|
||||
this.html = undefined;
|
||||
this.assets = undefined;
|
||||
this.css = undefined;
|
||||
|
||||
this.urls = undefined;
|
||||
this.cssUrls = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default Resources;
|
||||
|
|
|
@ -171,11 +171,32 @@ class Section {
|
|||
return new EpubCFI(el, this.cfiBase).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload the section document
|
||||
*/
|
||||
unload() {
|
||||
this.document = undefined;
|
||||
this.contents = undefined;
|
||||
this.output = undefined;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.unload();
|
||||
this.hooks.serialize.clear();
|
||||
this.hooks.content.clear();
|
||||
|
||||
this.hooks = undefined;
|
||||
this.idref = undefined;
|
||||
this.linear = undefined;
|
||||
this.properties = undefined;
|
||||
this.index = undefined;
|
||||
this.href = undefined;
|
||||
this.url = undefined;
|
||||
this.next = undefined;
|
||||
this.prev = undefined;
|
||||
|
||||
this.cfiBase = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default Section;
|
||||
|
|
24
src/spine.js
24
src/spine.js
|
@ -23,6 +23,12 @@ class Spine {
|
|||
this.epubcfi = new EpubCFI();
|
||||
|
||||
this.loaded = false;
|
||||
|
||||
this.items = undefined;
|
||||
this.manifest = undefined;
|
||||
this.spineNodeIndex = undefined;
|
||||
this.baseUrl = undefined;
|
||||
this.length = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +164,25 @@ class Spine {
|
|||
}
|
||||
|
||||
destroy() {
|
||||
this.each((section) => section.destroy());
|
||||
|
||||
this.spineItems = undefined
|
||||
this.spineByHref = undefined
|
||||
this.spineById = undefined
|
||||
|
||||
this.hooks.serialize.clear();
|
||||
this.hooks.content.clear();
|
||||
this.hooks = undefined;
|
||||
|
||||
this.epubcfi = undefined;
|
||||
|
||||
this.loaded = false;
|
||||
|
||||
this.items = undefined;
|
||||
this.manifest = undefined;
|
||||
this.spineNodeIndex = undefined;
|
||||
this.baseUrl = undefined;
|
||||
this.length = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,14 @@ class Themes {
|
|||
this.override("font-size", size);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.rendition = undefined;
|
||||
this._themes = undefined;
|
||||
this._overrides = undefined;
|
||||
this._current = undefined;
|
||||
this._injected = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Themes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue