Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/BookReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,24 @@ BookReader.prototype.unbind = function(name, callback) {
return this.off(name, callback);
};

/**
* Resolves `this.el` to a DOM Element, whether it was provided as an
* Element reference or a CSS selector string.
*
* This is needed because some consumers (e.g. apps using shadow DOM)
* must pass a DOM element directly — `document.querySelector` cannot
* cross shadow boundaries. jQuery's `$()` already handles both forms,
* but code that calls `document.querySelector(br.el)` will fail when
* `el` is an Element or when the target is inside a shadow root.
*
* @returns {Element|null}
*/
BookReader.prototype.resolveEl = function() {
if (this.el instanceof Element) return this.el;
if (typeof this.el === 'string') return document.querySelector(this.el);
return null;
};

/**
* Resizes based on the container width and height
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ia-bookreader/ia-bookreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class IaBookReader extends LitElement {

/** gets element that houses the bookreader in light dom */
get mainBRContainer() {
return document.querySelector(this.bookreader?.el);
return this.bookreader?.resolveEl?.() ?? document.querySelector(this.bookreader?.el);
}

get baseProviderConfig() {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/search/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ class SearchView {
const modal = document.createElement('div');
modal.classList.add('BRprogresspopup', 'search_modal');
modal.innerHTML = messageHTML;
document.querySelector(this.br.el).append(modal);
const container = this.br.resolveEl?.() ?? document.querySelector(this.br.el);
container?.append(modal);
}

/**
Expand Down
Loading