-
-
Notifications
You must be signed in to change notification settings - Fork 694
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
1 parent
08139e5
commit 4011361
Showing
9 changed files
with
227 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
yarn.lock | ||
dist/screenfull.test-d.ts |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
export type RawEventNames = { | ||
readonly requestFullscreen: string; | ||
readonly exitFullscreen: string; | ||
readonly fullscreenElement: string; | ||
readonly fullscreenEnabled: string; | ||
readonly fullscreenchange: string; | ||
readonly fullscreenerror: string; | ||
}; | ||
|
||
export type EventName = 'change' | 'error'; | ||
|
||
export interface Screenfull { | ||
/** | ||
A boolean whether fullscreen is active. | ||
*/ | ||
readonly isFullscreen: boolean; | ||
|
||
/** | ||
The element currently in fullscreen, otherwise `null`. | ||
*/ | ||
readonly element: Element | null; | ||
|
||
/** | ||
A boolean whether you are allowed to enter fullscreen. If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`). | ||
*/ | ||
readonly enabled: boolean; | ||
|
||
/** | ||
Exposes the raw properties (prefixed if needed) used internally. | ||
*/ | ||
raw: RawEventNames; | ||
|
||
/** | ||
Make an element fullscreen. | ||
If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`). | ||
Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key. | ||
@param element - Default is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant. | ||
@returns Resolves after the element enters fullscreen. | ||
*/ | ||
request(element?: Element): Promise<void>; | ||
|
||
/** | ||
Brings you out of fullscreen. | ||
@returns Resolves after the element exits fullscreen. | ||
*/ | ||
exit(): Promise<void>; | ||
|
||
/** | ||
Requests fullscreen if not active, otherwise exits. | ||
@returns Resolves after the element enters/exits fullscreen. | ||
*/ | ||
toggle(element?: Element): Promise<void>; | ||
|
||
/** | ||
Add a listener for when the browser switches in and out of fullscreen or when there is an error. | ||
*/ | ||
on(name: EventName, handler: (event: Event) => void): void; | ||
|
||
/** | ||
Remove a previously registered event listener. | ||
*/ | ||
off(name: EventName, handler: (event: Event) => void): void; | ||
|
||
/** | ||
Alias for `.on('change', function)`. | ||
*/ | ||
onchange(handler: (event: Event) => void): void; | ||
|
||
/** | ||
Alias for `.on('error', function)`. | ||
*/ | ||
onerror(handler: (event: Event) => void): void; | ||
} | ||
|
||
/** | ||
Simple wrapper for cross-browser usage of the JavaScript [Fullscreen API](https://developer.mozilla.org/en/DOM/Using_full-screen_mode), which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to. | ||
*/ | ||
declare const screenfull: Screenfull | false; | ||
|
||
export default screenfull; | ||
export as namespace screenfull; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
export type RawEventNames = { | ||
readonly requestFullscreen: string; | ||
readonly exitFullscreen: string; | ||
readonly fullscreenElement: string; | ||
readonly fullscreenEnabled: string; | ||
readonly fullscreenchange: string; | ||
readonly fullscreenerror: string; | ||
}; | ||
|
||
export type EventName = 'change' | 'error'; | ||
|
||
export interface Screenfull { | ||
/** | ||
A boolean whether fullscreen is active. | ||
*/ | ||
readonly isFullscreen: boolean; | ||
|
||
/** | ||
The element currently in fullscreen, otherwise `null`. | ||
*/ | ||
readonly element: Element | null; | ||
|
||
/** | ||
A boolean whether you are allowed to enter fullscreen. If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`). | ||
*/ | ||
readonly enabled: boolean; | ||
|
||
/** | ||
Exposes the raw properties (prefixed if needed) used internally. | ||
*/ | ||
raw: RawEventNames; | ||
|
||
/** | ||
Make an element fullscreen. | ||
If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`). | ||
Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key. | ||
@param element - Default is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant. | ||
@returns Resolves after the element enters fullscreen. | ||
*/ | ||
request(element?: Element): Promise<void>; | ||
|
||
/** | ||
Brings you out of fullscreen. | ||
@returns Resolves after the element exits fullscreen. | ||
*/ | ||
exit(): Promise<void>; | ||
|
||
/** | ||
Requests fullscreen if not active, otherwise exits. | ||
@returns Resolves after the element enters/exits fullscreen. | ||
*/ | ||
toggle(element?: Element): Promise<void>; | ||
|
||
/** | ||
Add a listener for when the browser switches in and out of fullscreen or when there is an error. | ||
*/ | ||
on(name: EventName, handler: (event: Event) => void): void; | ||
|
||
/** | ||
Remove a previously registered event listener. | ||
*/ | ||
off(name: EventName, handler: (event: Event) => void): void; | ||
|
||
/** | ||
Alias for `.on('change', function)`. | ||
*/ | ||
onchange(handler: (event: Event) => void): void; | ||
|
||
/** | ||
Alias for `.on('error', function)`. | ||
*/ | ||
onerror(handler: (event: Event) => void): void; | ||
} | ||
|
||
/** | ||
Simple wrapper for cross-browser usage of the JavaScript [Fullscreen API](https://developer.mozilla.org/en/DOM/Using_full-screen_mode), which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to. | ||
*/ | ||
declare const screenfull: Screenfull | false; | ||
|
||
export default screenfull; | ||
export as namespace screenfull; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {expectType} from 'tsd-check'; | ||
import screenfull from '../dist/screenfull'; | ||
|
||
if (screenfull) { | ||
expectType<boolean>(screenfull.enabled); | ||
expectType<boolean>(screenfull.isFullscreen); | ||
expectType<Element | null>(screenfull.element); | ||
|
||
if (screenfull.enabled) { | ||
const element: Element = document.getElementById('target')!; | ||
|
||
expectType<Promise<void>>(screenfull.request()); | ||
expectType<Promise<void>>(screenfull.request(element)); | ||
expectType<Promise<void>>(screenfull.toggle()); | ||
expectType<Promise<void>>(screenfull.toggle(element)); | ||
expectType<Promise<void>>(screenfull.exit()); | ||
|
||
screenfull.on('change', event => expectType<Event>(event)); | ||
screenfull.on('error', event => expectType<Event>(event)); | ||
screenfull.off('change', event => expectType<Event>(event)); | ||
screenfull.off('error', event => expectType<Event>(event)); | ||
screenfull.onchange(event => expectType<Event>(event)); | ||
screenfull.onerror(event => expectType<Event>(event)); | ||
|
||
expectType<string>(screenfull.raw.requestFullscreen); | ||
expectType<string>(screenfull.raw.exitFullscreen); | ||
expectType<string>(screenfull.raw.fullscreenElement); | ||
expectType<string>(screenfull.raw.fullscreenEnabled); | ||
expectType<string>(screenfull.raw.fullscreenchange); | ||
expectType<string>(screenfull.raw.fullscreenerror); | ||
} | ||
} |