MCPcopy
hub / github.com/codedogQBY/ReadAny / open

Method open

packages/foliate-js/reader.js:108–191  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

106 menu.groups.layout.select("paginated");
107 }
108 async open(file) {
109 this.view = document.createElement("foliate-view");
110 document.body.append(this.view);
111 await this.view.open(file);
112 this.view.addEventListener("load", this.#onLoad.bind(this));
113 this.view.addEventListener("relocate", this.#onRelocate.bind(this));
114
115 const { book } = this.view;
116 book.transformTarget?.addEventListener("data", ({ detail }) => {
117 detail.data = Promise.resolve(detail.data).catch((e) => {
118 console.error(new Error(`Failed to load ${detail.name}`, { cause: e }));
119 return "";
120 });
121 });
122 this.view.renderer.setStyles?.(getCSS(this.style));
123 this.view.renderer.next();
124
125 $("#header-bar").style.visibility = "visible";
126 $("#nav-bar").style.visibility = "visible";
127 $("#left-button").addEventListener("click", () => this.view.goLeft());
128 $("#right-button").addEventListener("click", () => this.view.goRight());
129
130 const slider = $("#progress-slider");
131 slider.dir = book.dir;
132 slider.addEventListener("input", (e) =>
133 this.view.goToFraction(Number.parseFloat(e.target.value)),
134 );
135 for (const fraction of this.view.getSectionFractions()) {
136 const option = document.createElement("option");
137 option.value = fraction;
138 $("#tick-marks").append(option);
139 }
140
141 document.addEventListener("keydown", this.#handleKeydown.bind(this));
142
143 const title = formatLanguageMap(book.metadata?.title) || "Untitled Book";
144 document.title = title;
145 $("#side-bar-title").innerText = title;
146 $("#side-bar-author").innerText = formatContributor(book.metadata?.author);
147 Promise.resolve(book.getCover?.())?.then((blob) =>
148 blob ? ($("#side-bar-cover").src = URL.createObjectURL(blob)) : null,
149 );
150
151 const toc = book.toc;
152 if (toc) {
153 this.#tocView = createTOCView(toc, (href) => {
154 this.view.goTo(href).catch((e) => console.error(e));
155 this.closeSideBar();
156 });
157 $("#toc-view").append(this.#tocView.element);
158 }
159
160 // load and show highlights embedded in the file by Calibre
161 const bookmarks = await book.getCalibreBookmarks?.();
162 if (bookmarks) {
163 const { fromCalibreHighlight } = await import("./epubcfi.js");
164 for (const obj of bookmarks) {
165 if (obj.type === "highlight") {

Callers 1

openFunction · 0.95

Calls 15

closeSideBarMethod · 0.95
createTOCViewFunction · 0.90
getCSSFunction · 0.85
$Function · 0.85
formatLanguageMapFunction · 0.85
formatContributorFunction · 0.85
fromCalibreHighlightFunction · 0.85
setStylesMethod · 0.80
getSectionFractionsMethod · 0.80
getCalibreBookmarksMethod · 0.80
pushMethod · 0.80
appendMethod · 0.65

Tested by

no test coverage detected