summaryrefslogtreecommitdiff
path: root/lib/epub.js/src/displayoptions.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-09-17 21:53:37 +0300
committerAndrew Dolgov <[email protected]>2021-09-17 21:53:37 +0300
commit4fd9b8f2b5a98bfcde57970b48fed2488a80f356 (patch)
tree51e0ce9cd61c24916b7d5820ee69e74bd3e76aac /lib/epub.js/src/displayoptions.js
parentd0cd10f08286be33306336fe8c4cac26ea7ce637 (diff)
add in master snapshot of epubjs
Diffstat (limited to 'lib/epub.js/src/displayoptions.js')
-rw-r--r--lib/epub.js/src/displayoptions.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/epub.js/src/displayoptions.js b/lib/epub.js/src/displayoptions.js
new file mode 100644
index 0000000..a2793e2
--- /dev/null
+++ b/lib/epub.js/src/displayoptions.js
@@ -0,0 +1,70 @@
+import {qs, qsa } from "./utils/core";
+
+/**
+ * Open DisplayOptions Format Parser
+ * @class
+ * @param {document} displayOptionsDocument XML
+ */
+class DisplayOptions {
+ constructor(displayOptionsDocument) {
+ this.interactive = "";
+ this.fixedLayout = "";
+ this.openToSpread = "";
+ this.orientationLock = "";
+
+ if (displayOptionsDocument) {
+ this.parse(displayOptionsDocument);
+ }
+ }
+
+ /**
+ * Parse XML
+ * @param {document} displayOptionsDocument XML
+ * @return {DisplayOptions} self
+ */
+ parse(displayOptionsDocument) {
+ if(!displayOptionsDocument) {
+ return this;
+ }
+
+ const displayOptionsNode = qs(displayOptionsDocument, "display_options");
+ if(!displayOptionsNode) {
+ return this;
+ }
+
+ const options = qsa(displayOptionsNode, "option");
+ options.forEach((el) => {
+ let value = "";
+
+ if (el.childNodes.length) {
+ value = el.childNodes[0].nodeValue;
+ }
+
+ switch (el.attributes.name.value) {
+ case "interactive":
+ this.interactive = value;
+ break;
+ case "fixed-layout":
+ this.fixedLayout = value;
+ break;
+ case "open-to-spread":
+ this.openToSpread = value;
+ break;
+ case "orientation-lock":
+ this.orientationLock = value;
+ break;
+ }
+ });
+
+ return this;
+ }
+
+ destroy() {
+ this.interactive = undefined;
+ this.fixedLayout = undefined;
+ this.openToSpread = undefined;
+ this.orientationLock = undefined;
+ }
+}
+
+export default DisplayOptions;