Skip to content

Commit

Permalink
Revert "remove support for old "webkitFullscreen""
Browse files Browse the repository at this point in the history
This reverts commit a746b7f.
  • Loading branch information
mistic100 committed May 18, 2024
1 parent 8f5ce07 commit 3cf5470
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
19 changes: 19 additions & 0 deletions packages/core/src/data/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export const SYSTEM = {
*/
isTouchEnabled: null as ResolvableBoolean,

/**
* Name of the fullscreen event
*/
fullscreenEvent: null as string,

/**
* @internal
*/
Expand Down Expand Up @@ -65,6 +70,7 @@ export const SYSTEM = {
this.isWebGLSupported = ctx !== null;
this.maxTextureWidth = ctx ? ctx.getParameter(ctx.MAX_TEXTURE_SIZE) : 0;
this.isTouchEnabled = isTouchEnabled();
this.fullscreenEvent = getFullscreenEvent();
this.isIphone = /iPhone/i.test(navigator.userAgent);
this.loaded = true;
}
Expand Down Expand Up @@ -189,3 +195,16 @@ function getMaxCanvasWidth(maxWidth: number): number {
throw new PSVError('Unable to detect system capabilities');
}
}

/**
* Gets the event name for fullscreen
*/
function getFullscreenEvent(): string {
if ('exitFullscreen' in document) {
return 'fullscreenchange';
}
if ('webkitExitFullscreen' in document) {
return 'webkitfullscreenchange';
}
return null;
}
6 changes: 3 additions & 3 deletions packages/core/src/services/EventsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class EventsHandler extends AbstractService {
window.addEventListener('touchmove', this, { passive: false });
window.addEventListener('touchend', this, { passive: false });
this.viewer.container.addEventListener('wheel', this, { passive: false });
document.addEventListener('fullscreenchange', this);
document.addEventListener(SYSTEM.fullscreenEvent, this);
this.resizeObserver.observe(this.viewer.container);
}

Expand All @@ -130,7 +130,7 @@ export class EventsHandler extends AbstractService {
window.removeEventListener('touchmove', this);
window.removeEventListener('touchend', this);
this.viewer.container.removeEventListener('wheel', this);
document.removeEventListener('fullscreenchange', this);
document.removeEventListener(SYSTEM.fullscreenEvent, this);
this.resizeObserver.disconnect();

clearTimeout(this.data.dblclickTimeout);
Expand All @@ -153,7 +153,7 @@ export class EventsHandler extends AbstractService {
case 'mouseup': this.__onMouseUp(evt as MouseEvent); break;
case 'touchmove': this.__onTouchMove(evt as TouchEvent); break;
case 'touchend': this.__onTouchEnd(evt as TouchEvent); break;
case 'fullscreenchange': this.__onFullscreenChange(); break;
case SYSTEM.fullscreenEvent: this.__onFullscreenChange(); break;
}

if (!getClosest(evt.target as HTMLElement, '.' + CAPTURE_EVENTS_CLASS)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function isFullscreenEnabled(elt: HTMLElement, isIphone = false): boolean
if (isIphone) {
return elt === fullscreenElement;
} else {
return document.fullscreenElement === elt;
return (document.fullscreenElement || (document as any).webkitFullscreenElement) === elt;
}
}

Expand All @@ -145,9 +145,9 @@ export function requestFullscreen(elt: HTMLElement, isIphone = false) {
if (isIphone) {
fullscreenElement = elt;
elt.classList.add('psv-fullscreen-emulation');
document.dispatchEvent(new Event('fullscreenchange'));
document.dispatchEvent(new Event(SYSTEM.fullscreenEvent));
} else {
elt.requestFullscreen();
(elt.requestFullscreen || (elt as any).webkitRequestFullscreen).call(elt);
}
}

Expand All @@ -158,8 +158,8 @@ export function exitFullscreen(isIphone = false) {
if (isIphone) {
fullscreenElement.classList.remove('psv-fullscreen-emulation');
fullscreenElement = null;
document.dispatchEvent(new Event('fullscreenchange'));
document.dispatchEvent(new Event(SYSTEM.fullscreenEvent));
} else {
document.exitFullscreen();
(document.exitFullscreen || (document as any).webkitExitFullscreen).call(document);
}
}

0 comments on commit 3cf5470

Please sign in to comment.