Skip to content

Commit

Permalink
rename contentType and assignedContentHandler to remove leading under…
Browse files Browse the repository at this point in the history
…score
  • Loading branch information
edsilv committed Jan 13, 2025
1 parent 9b3fe2a commit e41d4ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/BaseContentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export type EventListener = {
type EventListenerDictionaryItem = Pick<EventListener, "cb" | "ctx">;

export default class BaseContentHandler<IUVData>
implements IContentHandler<IUVData>
{
implements IContentHandler<IUVData> {
protected _el: HTMLElement;
private _eventListeners: {
[key: string]: EventListenerDictionaryItem[];
Expand All @@ -27,7 +26,6 @@ export default class BaseContentHandler<IUVData>
) {
// console.log("create YouTubeContentHandler");
this._el = this.options.target;
// this._assignedContentHandler.adapter = this.adapter; // set adapter

// add event listeners
if (eventListeners) {
Expand Down
33 changes: 20 additions & 13 deletions src/UniversalViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ 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>>;

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

private _externalEventListeners: EventListener[] = [];

constructor(public options: IUVOptions) {
super(options);
this._assignContentHandler(this.options.data);
// for backwards compat, remove in next major version
this._assignedContentHandler = this.assignedContentHandler;
}

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

public on(name: string, cb: Function, ctx?: any): void {
Expand All @@ -63,22 +70,22 @@ 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 = 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(
this.assignedContentHandler = new m.default(
{
target: this._el,
data: data,
Expand All @@ -100,20 +107,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 e41d4ac

Please sign in to comment.