Skip to content

Commit

Permalink
public internals (#1282)
Browse files Browse the repository at this point in the history
renamed `_contentType` and `_assignedContentHandler` to remove leading underscore. set them to public.
this is because I use them in Exhibit (they're useful), and have noticed them used elsewhere.
  • Loading branch information
edsilv authored Jan 17, 2025
1 parent b31aa64 commit 2187f78
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/UniversalViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ const ContentHandler: IContentHandlerRegistry = {
};

export class UniversalViewer extends BaseContentHandler<IUVData<any>> {
private _contentType: ContentType = ContentType.UNKNOWN;
private _assignedContentHandler: IContentHandler<IUVData<any>>;
public contentType: ContentType = ContentType.UNKNOWN;
public assignedContentHandler: IContentHandler<IUVData<any>>;

// include _contentType for backwards compat, remove in next major version (UV5)
public _contentType = this.contentType;
public _assignedContentHandler;

private _externalEventListeners: EventListener[] = [];

constructor(public options: IUVOptions) {
Expand All @@ -40,7 +45,7 @@ export class UniversalViewer extends BaseContentHandler<IUVData<any>> {
}

public get() {
return this._assignedContentHandler;
return this.assignedContentHandler;
}

public on(name: string, cb: Function, ctx?: any): void {
Expand All @@ -63,22 +68,23 @@ export class UniversalViewer extends BaseContentHandler<IUVData<any>> {
contentType = ContentType.IIIF;
} else if (data[ContentType.YOUTUBE]) {
contentType = ContentType.YOUTUBE;
} else if (this._contentType) {
contentType = this._contentType;
} else if (this.contentType) {
contentType = this.contentType;
} else {
contentType = ContentType.UNKNOWN;
}

const handlerChanged: boolean = this._contentType !== contentType;
const handlerChanged: boolean = this.contentType !== contentType;

if (contentType === ContentType.UNKNOWN) {
console.error("Unknown content type");
} else if (handlerChanged) {
this._contentType = contentType; // set content type
this._assignedContentHandler?.dispose(); // dispose previous content handler
this.contentType = this._contentType = contentType; // set content type
this.assignedContentHandler?.dispose(); // dispose previous content handler
const m = await ContentHandler[contentType](); // import content handler
this.showSpinner(); // show spinner
this._assignedContentHandler = new m.default(
// include _assignedContentHandler for backwards compat, remove in next major version (UV5)
this.assignedContentHandler = this._assignedContentHandler = new m.default(
{
target: this._el,
data: data,
Expand All @@ -100,20 +106,20 @@ export class UniversalViewer extends BaseContentHandler<IUVData<any>> {
} else {
// the handler didn't change, therefore handler's initial set didn't run
// so we need to call set
this._assignedContentHandler.set(data, initial);
this.assignedContentHandler.set(data, initial);
}
});
}

public exitFullScreen(): void {
this._assignedContentHandler?.exitFullScreen();
this.assignedContentHandler?.exitFullScreen();
}

public resize(): void {
this._assignedContentHandler?.resize();
this.assignedContentHandler?.resize();
}

public dispose(): void {
this._assignedContentHandler?.dispose();
this.assignedContentHandler?.dispose();
}
}

0 comments on commit 2187f78

Please sign in to comment.