-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cole
committed
Aug 1, 2024
1 parent
0f08d3f
commit 1fa7e28
Showing
5 changed files
with
79 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,71 @@ | ||
import { createReactivePlugin } from '../../utils/create' | ||
|
||
const native = { | ||
request: ['requestFullscreen', 'msRequestFullscreen', 'mozRequestFullScreen', 'webkitRequestFullscreen'].find((request) => !!document.documentElement[request]), | ||
exit: ['exitFullscreen', 'msExitFullscreen', 'mozCancelFullScreen', 'webkitExitFullscreen'].find((exit) => !!document[exit]) | ||
} | ||
|
||
function getFullElement () { | ||
return (document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement || null) | ||
} | ||
|
||
function promisify (target, event) { | ||
try { | ||
const result = target[event]() | ||
return result || Promise.resolve() | ||
} catch (err) { | ||
return Promise.reject(err) | ||
} | ||
} | ||
|
||
export default createReactivePlugin({ | ||
isActive: false, | ||
activeEl: null | ||
}, { | ||
request (target) { | ||
const el = target || document.documentElement | ||
if (this.activeEl === el) return Promise.resolve() | ||
// -- | ||
const result = this.activeEl !== null && el.contains(this.activeEl) === true | ||
? this.exit() | ||
: Promise.resolve() | ||
|
||
return result.finally(() => promisify(el, native.request)) | ||
}, | ||
exit () { | ||
return this.isActive === true | ||
? promisify(document, native.exit) | ||
: Promise.resolve() | ||
}, | ||
toggle (target) { | ||
return this.isActive === true | ||
? this.exit() | ||
: this.request(target) | ||
}, | ||
install (app, options, $site) { | ||
$site && ($site.fullscreen = this) | ||
|
||
const onUpdateActiveEl = () => { | ||
this.activeEl = this.isActive === false ? null : getFullElement() | ||
} | ||
|
||
const onChange = () => { | ||
this.isActive = this.isActive === false | ||
onUpdateActiveEl() | ||
} | ||
|
||
this.isActive = !!getFullElement() | ||
this.isActive === true && onUpdateActiveEl() | ||
|
||
// ;['fullscreenchange', 'MSFullscreenChange', 'mozfullscreenchange', 'webkitfullscreenchange'].forEach((type) => { | ||
// addEvt(document, type, onChange) | ||
// }) | ||
|
||
;['onfullscreenchange', 'onmsfullscreenchange', 'onmozfullscreenchange', 'onwebkitfullscreenchange'].forEach((event) => { | ||
document[event] = onChange | ||
}) | ||
} | ||
}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import Fullscreen from './fullscreen' | ||
import Screen from './screen' | ||
|
||
export { | ||
Fullscreen, | ||
Screen | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.