| 1 |
/** |
| 2 |
* Keep fullscreen off on PB form CPTs without writing the global |
| 3 |
* `fullscreenMode` preference. Strip `is-fullscreen-mode` from body and |
| 4 |
* re-strip on MutationObserver (PB CPTs only). |
| 5 |
*/ |
| 6 |
|
| 7 |
import { useEffect } from '@wordpress/element'; |
| 8 |
import { useSelect } from '@wordpress/data'; |
| 9 |
import { registerPlugin } from '@wordpress/plugins'; |
| 10 |
|
| 11 |
const PB_CPTS = [ 'wppb-rf-cpt', 'wppb-epf-cpt' ]; |
| 12 |
const FULLSCREEN_CLASS = 'is-fullscreen-mode'; |
| 13 |
|
| 14 |
const ForceDisableFullscreen = () => { |
| 15 |
const postType = useSelect( |
| 16 |
( select ) => select( 'core/editor' ).getCurrentPostType(), |
| 17 |
[] |
| 18 |
); |
| 19 |
const isOurPostType = PB_CPTS.includes( postType ); |
| 20 |
|
| 21 |
useEffect( () => { |
| 22 |
if ( ! isOurPostType ) return undefined; |
| 23 |
|
| 24 |
const body = document.body; |
| 25 |
if ( ! body ) return undefined; |
| 26 |
|
| 27 |
const strip = () => { |
| 28 |
if ( body.classList.contains( FULLSCREEN_CLASS ) ) { |
| 29 |
body.classList.remove( FULLSCREEN_CLASS ); |
| 30 |
} |
| 31 |
}; |
| 32 |
|
| 33 |
strip(); |
| 34 |
|
| 35 |
const observer = new MutationObserver( strip ); |
| 36 |
observer.observe( body, { attributes: true, attributeFilter: [ 'class' ] } ); |
| 37 |
|
| 38 |
return () => observer.disconnect(); |
| 39 |
}, [ isOurPostType ] ); |
| 40 |
|
| 41 |
return null; |
| 42 |
}; |
| 43 |
|
| 44 |
registerPlugin( 'wppb-fb-force-disable-fullscreen', { render: ForceDisableFullscreen } ); |
| 45 |
|