Skip to content

Commit

Permalink
Change function and variable names, "EPUB" to "Publication"
Browse files Browse the repository at this point in the history
loadEPUB -> loadPublication
loadDocumentOrEPUB -> loadDocumentOrPublication
loadEPUBDoc -> loadPUBDoc
epubURL -> pubURL
epubUrl -> pubURL
  • Loading branch information
MurakamiShinyu committed Feb 24, 2019
1 parent c2df75f commit 7e909f9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
56 changes: 28 additions & 28 deletions src/adapt/epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,30 @@ adapt.epub.EPUBDocStore.prototype.startLoadingAsJSON = function(url) {
* @param {boolean} haveZipMetadata
* @return {!adapt.task.Result.<adapt.epub.OPFDoc>}
*/
adapt.epub.EPUBDocStore.prototype.loadEPUBDoc = function(url, haveZipMetadata) {
adapt.epub.EPUBDocStore.prototype.loadPUBDoc = function(url, haveZipMetadata) {
/** @type {!adapt.task.Frame.<adapt.epub.OPFDoc>} */ const frame
= adapt.task.newFrame("loadEPUBDoc");
= adapt.task.newFrame("loadPUBDoc");

adapt.net.ajax(url, null, "HEAD").then(response => {
if (response.status >= 400) {
// This url can be the root of an unzipped EPUB.
let epubUrl = url;
if (epubUrl.substring(epubUrl.length - 1) !== "/") {
epubUrl = `${epubUrl}/`;
let pubURL = url;
if (pubURL.substring(pubURL.length - 1) !== "/") {
pubURL = `${pubURL}/`;
}
if (haveZipMetadata) {
this.startLoadingAsJSON(`${epubUrl}?r=list`);
this.startLoadingAsJSON(`${pubURL}?r=list`);
}
this.startLoadingAsPlainXML(`${epubUrl}META-INF/encryption.xml`);
const containerURL = `${epubUrl}META-INF/container.xml`;
this.startLoadingAsPlainXML(`${pubURL}META-INF/encryption.xml`);
const containerURL = `${pubURL}META-INF/container.xml`;
this.loadAsPlainXML(containerURL).then(containerXML => {
if (containerXML) {
const roots = containerXML.doc().child("container").child("rootfiles")
.child("rootfile").attribute("full-path");

for (const root of roots) {
if (root) {
this.loadOPF(epubUrl, root, haveZipMetadata).thenFinish(frame);
this.loadOPF(pubURL, root, haveZipMetadata).thenFinish(frame);
return;
}
}
Expand All @@ -153,8 +153,8 @@ adapt.epub.EPUBDocStore.prototype.loadEPUBDoc = function(url, haveZipMetadata) {
}
if (response.contentType == "application/oebps-package+xml" || (/\.opf(?:[#?]|$)/).test(url)) {
// EPUB OPF
const [, epubUrl, root] = url.match(/^((?:.*\/)?)([^/]*)$/);
this.loadOPF(epubUrl, root, haveZipMetadata).thenFinish(frame);
const [, pubURL, root] = url.match(/^((?:.*\/)?)([^/]*)$/);
this.loadOPF(pubURL, root, haveZipMetadata).thenFinish(frame);
} else if (response.contentType == "application/ld+json" ||
response.contentType == "application/webpub+json" ||
response.contentType == "application/audiobook+json" ||
Expand Down Expand Up @@ -182,14 +182,14 @@ adapt.epub.EPUBDocStore.prototype.loadEPUBDoc = function(url, haveZipMetadata) {
};

/**
* @param {string} epubURL
* @param {string} pubURL
* @param {string} root
* @param {boolean} haveZipMetadata
* @return {!adapt.task.Result.<adapt.epub.OPFDoc>}
*/
adapt.epub.EPUBDocStore.prototype.loadOPF = function(epubURL, root, haveZipMetadata) {
adapt.epub.EPUBDocStore.prototype.loadOPF = function(pubURL, root, haveZipMetadata) {
const self = this;
const url = epubURL + root;
const url = pubURL + root;
let opf = self.opfByURL[url];
if (opf) {
return adapt.task.newResult(opf);
Expand All @@ -200,14 +200,14 @@ adapt.epub.EPUBDocStore.prototype.loadOPF = function(epubURL, root, haveZipMetad
if (!opfXML) {
vivliostyle.logging.logger.error(`Received an empty response for EPUB OPF ${url}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`);
} else {
self.loadAsPlainXML(`${epubURL}META-INF/encryption.xml`).then(encXML => {
self.loadAsPlainXML(`${pubURL}META-INF/encryption.xml`).then(encXML => {
const zipMetadataResult = haveZipMetadata ?
self.loadAsJSON(`${epubURL}?r=list`) : adapt.task.newResult(null);
self.loadAsJSON(`${pubURL}?r=list`) : adapt.task.newResult(null);
zipMetadataResult.then(zipMetadata => {
opf = new adapt.epub.OPFDoc(self, epubURL);
opf.initWithXMLDoc(opfXML, encXML, zipMetadata, `${epubURL}?r=manifest`).then(() => {
opf = new adapt.epub.OPFDoc(self, pubURL);
opf.initWithXMLDoc(opfXML, encXML, zipMetadata, `${pubURL}?r=manifest`).then(() => {
self.opfByURL[url] = opf;
self.primaryOPFByEPubURL[epubURL] = opf;
self.primaryOPFByEPubURL[pubURL] = opf;
frame.finish(opf);
});
});
Expand Down Expand Up @@ -642,17 +642,17 @@ adapt.epub.transformedIdPrefix = "viv-id-";
/**
* @constructor
* @param {adapt.epub.EPUBDocStore} store
* @param {string} epubURL
* @param {string} pubURL
*/
adapt.epub.OPFDoc = function(store, epubURL) {
adapt.epub.OPFDoc = function(store, pubURL) {
/** @const */ this.store = store;
/** @type {adapt.xmldoc.XMLDocHolder} */ this.opfXML = null;
/** @type {adapt.xmldoc.XMLDocHolder} */ this.encXML = null;
/** @type {Array.<adapt.epub.OPFItem>} */ this.items = null;
/** @type {Array.<adapt.epub.OPFItem>} */ this.spine = null;
/** @type {Object.<string,adapt.epub.OPFItem>} */ this.itemMap = null;
/** @type {Object.<string,adapt.epub.OPFItem>} */ this.itemMapByPath = null;
/** @const */ this.epubURL = epubURL;
/** @const */ this.pubURL = pubURL;
/** @type {?string} */ this.uid = null;
/** @type {Object.<string,string>} */ this.bindings = {};
/** @type {?string} */ this.lang = null;
Expand Down Expand Up @@ -742,10 +742,10 @@ adapt.epub.OPFDoc.prototype.getMetadata = function() {
*/
adapt.epub.OPFDoc.prototype.getPathFromURL = function(url) {
if (url.startsWith("data:")) {
return (url === this.epubURL) ? "" : url;
return (url === this.pubURL) ? "" : url;
}
if (this.epubURL) {
let epubBaseURL = adapt.base.resolveURL("", this.epubURL);
if (this.pubURL) {
let epubBaseURL = adapt.base.resolveURL("", this.pubURL);
if (url === epubBaseURL || url + "/" === epubBaseURL) {
return "";
}
Expand Down Expand Up @@ -858,7 +858,7 @@ adapt.epub.OPFDoc.prototype.initWithXMLDoc = function(opfXML, encXML, zipMetadat
// Have to deobfuscate in JavaScript
const deobfuscator = adapt.epub.makeDeobfuscator(this.uid);
for (var i = 0; i < idpfObfURLs.length; i++) {
this.store.deobfuscators[this.epubURL + idpfObfURLs[i]] = deobfuscator;
this.store.deobfuscators[this.pubURL + idpfObfURLs[i]] = deobfuscator;
}
}
if (this.prePaginated) {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ adapt.epub.OPFDoc.prototype.initWithWebPubManifest = function(manifestObj, doc)
}
// TODO: other metadata...

const primaryEntryPath = this.getPathFromURL(this.epubURL);
const primaryEntryPath = this.getPathFromURL(this.pubURL);
if (!manifestObj["readingOrder"] && doc && primaryEntryPath !== null) {
manifestObj["readingOrder"] = [encodeURI(primaryEntryPath)];

Expand Down Expand Up @@ -1070,7 +1070,7 @@ adapt.epub.OPFDoc.prototype.initWithWebPubManifest = function(manifestObj, doc)
if (encodingFormat === "text/html" || encodingFormat === "application/xhtml+xml" ||
(/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/).test(url)) {
const param = {
url: adapt.base.resolveURL(adapt.base.convertSpecialURL(url), this.epubURL),
url: adapt.base.resolveURL(adapt.base.convertSpecialURL(url), this.pubURL),
index: itemCount++,
startPage: null,
skipPagesBefore: null
Expand Down
12 changes: 6 additions & 6 deletions src/adapt/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ adapt.viewer.Viewer = function(window, viewportElement, instanceId, callbackFn)
* @type {Object.<string, adapt.viewer.Action>}
*/
this.actions = {
"loadEPUB": this.loadEPUB,
"loadPublication": this.loadPublication,
"loadXML": this.loadXML,
"configure": this.configure,
"moveTo": this.moveTo,
Expand Down Expand Up @@ -184,7 +184,7 @@ adapt.viewer.Viewer.prototype.setReadyState = function(readyState) {
* @param {adapt.base.JSON} command
* @return {!adapt.task.Result.<boolean>}
*/
adapt.viewer.Viewer.prototype.loadEPUB = function(command) {
adapt.viewer.Viewer.prototype.loadPublication = function(command) {
vivliostyle.profile.profiler.registerStartTiming("beforeRender");
this.setReadyState(vivliostyle.constants.ReadyState.LOADING);
const url = /** @type {string} */ (command["url"]);
Expand All @@ -194,14 +194,14 @@ adapt.viewer.Viewer.prototype.loadEPUB = function(command) {
const userStyleSheet = /** @type {Array.<{url: ?string, text: ?string}>} */ (command["userStyleSheet"]);
// force relayout
this.viewport = null;
/** @type {!adapt.task.Frame.<boolean>} */ const frame = adapt.task.newFrame("loadEPUB");
/** @type {!adapt.task.Frame.<boolean>} */ const frame = adapt.task.newFrame("loadPublication");
const self = this;
self.configure(command).then(() => {
const store = new adapt.epub.EPUBDocStore();
store.init(authorStyleSheet, userStyleSheet).then(() => {
const epubURL = adapt.base.resolveURL(adapt.base.convertSpecialURL(url), self.window.location.href);
self.packageURL = [epubURL];
store.loadEPUBDoc(epubURL, haveZipMetadata).then(opf => {
const pubURL = adapt.base.resolveURL(adapt.base.convertSpecialURL(url), self.window.location.href);
self.packageURL = [pubURL];
store.loadPUBDoc(pubURL, haveZipMetadata).then(opf => {
if (opf) {
self.opf = opf;
self.render(fragment).then(() => {
Expand Down
24 changes: 12 additions & 12 deletions src/vivliostyle/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,20 @@ goog.scope(() => {
if (!singleDocumentOptions) {
this.eventTarget.dispatchEvent({"type": "error", "content": "No URL specified"});
}
this.loadDocumentOrEPUB(singleDocumentOptions, null, opt_documentOptions, opt_viewerOptions);
this.loadDocumentOrPublication(singleDocumentOptions, null, opt_documentOptions, opt_viewerOptions);
};

/**
* Load an EPUB document.
* @param {string} epubUrl
* Load a EPUB/WebPub publication.
* @param {string} pubURL
* @param {!vivliostyle.viewer.DocumentOptions=} opt_documentOptions
* @param {!vivliostyle.viewer.ViewerOptions=} opt_viewerOptions
*/
Viewer.prototype.loadEPUB = function(epubUrl, opt_documentOptions, opt_viewerOptions) {
if (!epubUrl) {
Viewer.prototype.loadPublication = function(pubURL, opt_documentOptions, opt_viewerOptions) {
if (!pubURL) {
this.eventTarget.dispatchEvent({"type": "error", "content": "No URL specified"});
}
this.loadDocumentOrEPUB(null, epubUrl, opt_documentOptions, opt_viewerOptions);
this.loadDocumentOrPublication(null, pubURL, opt_documentOptions, opt_viewerOptions);
};

/**
Expand Down Expand Up @@ -272,14 +272,14 @@ goog.scope(() => {
}

/**
* Load an HTML or XML document, or an EPUB document.
* Load an HTML or XML document, or an EPUB/WebPub publication.
* @private
* @param {?(!vivliostyle.viewer.SingleDocumentOptions|!Array<!vivliostyle.viewer.SingleDocumentOptions>)} singleDocumentOptions
* @param {?string} epubUrl
* @param {?string} pubURL
* @param {!vivliostyle.viewer.DocumentOptions=} opt_documentOptions
* @param {!vivliostyle.viewer.ViewerOptions=} opt_viewerOptions
*/
Viewer.prototype.loadDocumentOrEPUB = function(singleDocumentOptions, epubUrl, opt_documentOptions, opt_viewerOptions) {
Viewer.prototype.loadDocumentOrPublication = function(singleDocumentOptions, pubURL, opt_documentOptions, opt_viewerOptions) {
const documentOptions = opt_documentOptions || {};

function convertStyleSheetArray(arr) {
Expand All @@ -301,11 +301,11 @@ goog.scope(() => {
}

const command = Object.assign({
"a": singleDocumentOptions ? "loadXML" : "loadEPUB",
"a": singleDocumentOptions ? "loadXML" : "loadPublication",

"userAgentRootURL": this.settings["userAgentRootURL"],

"url": convertSingleDocumentOptions(singleDocumentOptions) || epubUrl,
"url": convertSingleDocumentOptions(singleDocumentOptions) || pubURL,
"document": documentOptions["documentObject"],
"fragment": documentOptions["fragment"],
"authorStyleSheet": authorStyleSheet,
Expand Down Expand Up @@ -432,7 +432,7 @@ goog.scope(() => {
goog.exportProperty(Viewer.prototype, "addListener", Viewer.prototype.addListener);
goog.exportProperty(Viewer.prototype, "removeListener", Viewer.prototype.removeListener);
goog.exportProperty(Viewer.prototype, "loadDocument", Viewer.prototype.loadDocument);
goog.exportProperty(Viewer.prototype, "loadEPUB", Viewer.prototype.loadEPUB);
goog.exportProperty(Viewer.prototype, "loadPublication", Viewer.prototype.loadPublication);
goog.exportProperty(Viewer.prototype, "getCurrentPageProgression", Viewer.prototype.getCurrentPageProgression);
goog.exportProperty(Viewer.prototype, "navigateToPage", Viewer.prototype.navigateToPage);
goog.exportProperty(Viewer.prototype, "navigateToInternalUrl", Viewer.prototype.navigateToInternalUrl);
Expand Down
6 changes: 3 additions & 3 deletions src/vivliostyle/viewerapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function setViewportSize(width, height, size, orientation, config) {
*/
vivliostyle.viewerapp.main = arg => {
const fragment = (arg && arg["fragment"]) || adapt.base.getURLParam("f");
const epubURL = (arg && arg["epubURL"]) || adapt.base.getURLParam("b");
const pubURL = (arg && arg["pubURL"]) || adapt.base.getURLParam("b");
const xmlURL = (arg && arg["xmlURL"]) || adapt.base.getURLParam("x");
const width = (arg && arg["defaultPageWidth"]) || adapt.base.getURLParam("w");
const height = (arg && arg["defaultPageHeight"]) || adapt.base.getURLParam("h");
Expand All @@ -305,8 +305,8 @@ vivliostyle.viewerapp.main = arg => {
const viewportElement = (arg && arg["viewportElement"]) || document.body;

const config = {
"a": epubURL ? "loadEPUB" : "loadXML",
"url": epubURL || xmlURL,
"a": pubURL ? "loadPublication" : "loadXML",
"url": pubURL || xmlURL,
"autoresize": true,
"fragment": fragment,
// render all pages on load and resize
Expand Down

0 comments on commit 7e909f9

Please sign in to comment.