diff options
Diffstat (limited to 'lib/epub.js/src/displayoptions.js')
-rw-r--r-- | lib/epub.js/src/displayoptions.js | 70 |
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; |