1
+ import { RotataToFullscreen } from './rotate-to-fullscreen.js' ;
2
+
1
3
const NON_VISIBLE_WIDTH = window . innerWidth < 720 ? 320 : 640 ;
2
4
const DEFAULT_DOCK_TARGET_INSET = '0px 10px auto auto' ;
3
5
const DEFAULT_TRANSITION_DURATION = 300 ;
4
6
const DOCK_Z_INDEX = 9999999 ;
5
7
const LIGHTBOX_Z_INDEX = 10000000 ;
6
8
const MIN_DOCK_WIDTH = 192 ;
7
9
const MAX_DOCK_WIDTH = 400 ;
10
+ const PHONE_MAX_WIDTH = 480 ;
11
+
12
+ const allowRotateToFullscreen = Math . min ( window . innerWidth , window . innerHeight ) <= PHONE_MAX_WIDTH ;
8
13
9
14
const updateViewPortWidth = ( element ) => {
10
15
let viewPortWidth = window . innerWidth * 0.3 ;
@@ -200,7 +205,7 @@ function isInDocument(element, document) {
200
205
201
206
function adjustLightboxModeForLandscapeOnMobile ( element ) {
202
207
if ( element . getAttribute ( 'mode' ) !== 'lightbox' ) return ;
203
- const mobileLandscapeSelector = ' (max-device-width: 450px ) and (hover: none) and (pointer: coarse) and (orientation: landscape)' ;
208
+ const mobileLandscapeSelector = ` (max-device-width: ${ PHONE_MAX_WIDTH } px ) and (hover: none) and (pointer: coarse) and (orientation: landscape)` ;
204
209
if ( window . matchMedia ( mobileLandscapeSelector ) . matches ) {
205
210
// allow scrolling in mobile landscape
206
211
// so that the user can scroll down to remove the browser bar
@@ -406,7 +411,7 @@ class GlomexDialogElement extends window.HTMLElement {
406
411
z-index: ${ LIGHTBOX_Z_INDEX } ;
407
412
}
408
413
409
- @media (hover: none) and (max-device-width: 450px ) and (pointer: coarse) and (orientation: landscape) {
414
+ @media (hover: none) and (max-device-width: ${ PHONE_MAX_WIDTH } px ) and (pointer: coarse) and (orientation: landscape) {
410
415
:host([mode=lightbox]) .dialog-content {
411
416
animation-name: none;
412
417
height: 100%;
@@ -540,6 +545,12 @@ class GlomexDialogElement extends window.HTMLElement {
540
545
if ( this . _disconnectDragAndDrop ) this . _disconnectDragAndDrop ( ) ;
541
546
this . _disconnectResize ( ) ;
542
547
this . _disconnectKeyup ( ) ;
548
+ if ( this . _rotateToFullscreen ) {
549
+ this . _rotateToFullscreen . disable ( ) ;
550
+ this . _rotateToFullscreen . removeEventListener ( 'exit' , this . _onRotateToFullscreenExit ) ;
551
+ this . _rotateToFullscreen . removeEventListener ( 'enter' , this . _onRotateToFullscreenEnter ) ;
552
+ this . _rotateToFullscreen = undefined ;
553
+ }
543
554
}
544
555
545
556
static get observedAttributes ( ) {
@@ -553,6 +564,7 @@ class GlomexDialogElement extends window.HTMLElement {
553
564
'dock-sticky-target-top' ,
554
565
'dock-sticky-aspect-ratio' ,
555
566
'dock-downscale' ,
567
+ 'rotate-to-fullscreen' ,
556
568
] ;
557
569
}
558
570
@@ -669,6 +681,9 @@ class GlomexDialogElement extends window.HTMLElement {
669
681
passive : false ,
670
682
} ) ;
671
683
adjustLightboxModeForLandscapeOnMobile ( this ) ;
684
+ if ( this . _rotateToFullscreen ) {
685
+ this . _rotateToFullscreen . enable ( ) ;
686
+ }
672
687
} else if ( newValue === 'hidden' ) {
673
688
this . _wasInHiddenMode = true ;
674
689
}
@@ -680,6 +695,10 @@ class GlomexDialogElement extends window.HTMLElement {
680
695
dialogInnerWrapper . removeAttribute ( 'tabindex' ) ;
681
696
}
682
697
698
+ if ( oldValue === 'lightbox' && this . _rotateToFullscreen ) {
699
+ this . _rotateToFullscreen . disable ( ) ;
700
+ }
701
+
683
702
this . dispatchEvent (
684
703
new CustomEvent ( 'modechange' , {
685
704
detail : {
@@ -745,6 +764,32 @@ class GlomexDialogElement extends window.HTMLElement {
745
764
// No implementation when dock-downscale gets reset
746
765
}
747
766
}
767
+
768
+ if ( name === 'rotate-to-fullscreen' ) {
769
+ if ( newValue == null && this . _rotateToFullscreen ) {
770
+ this . _rotateToFullscreen . disable ( ) ;
771
+ this . _rotateToFullscreen . removeEventListener ( 'exit' , this . _onRotateToFullscreenExit ) ;
772
+ this . _rotateToFullscreen . removeEventListener ( 'enter' , this . _onRotateToFullscreenEnter ) ;
773
+ this . _rotateToFullscreen = undefined ;
774
+ } else if ( allowRotateToFullscreen ) {
775
+ this . _onRotateToFullscreenExit = ( event ) => {
776
+ if ( event . detail . orientation . indexOf ( 'landscape' ) === 0 ) {
777
+ this . _internalModeChange = true ;
778
+ this . setAttribute ( 'mode' , this . _wasInHiddenMode ? 'hidden' : 'inline' ) ;
779
+ }
780
+ this . removeAttribute ( 'fullscreen' ) ;
781
+ } ;
782
+ this . _onRotateToFullscreenEnter = ( ) => {
783
+ // expose fullscreen to the light-dom so we can apply fullscreen styles there
784
+ // (device-mode: fullscreen) media queries somehow don't work in combination
785
+ // with shadow dom
786
+ this . setAttribute ( 'fullscreen' , '' ) ;
787
+ } ;
788
+ this . _rotateToFullscreen = new RotataToFullscreen ( window , dialogInnerWrapper ) ;
789
+ this . _rotateToFullscreen . addEventListener ( 'exit' , this . _onRotateToFullscreenExit ) ;
790
+ this . _rotateToFullscreen . addEventListener ( 'enter' , this . _onRotateToFullscreenEnter ) ;
791
+ }
792
+ }
748
793
}
749
794
750
795
/**
0 commit comments