Skip to content

Commit

Permalink
Add support for options (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
silltho and sindresorhus authored Dec 24, 2020
1 parent 759746d commit 0092521
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
16 changes: 14 additions & 2 deletions dist/screenfull.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare namespace screenfull {
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.
@param options - [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).
@returns A promise that resolves after the element enters fullscreen.
@example
Expand All @@ -70,6 +71,15 @@ declare namespace screenfull {
}
});
// Fullscreen an element with options
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element, {navigationUI: 'hide'});
}
});
// Fullscreen an element with jQuery
const element = $('#target')[0]; // Get DOM element from jQuery collection
Expand All @@ -80,7 +90,7 @@ declare namespace screenfull {
});
```
*/
request(element?: Element): Promise<void>;
request(element?: Element, options?: FullscreenOptions): Promise<void>;

/**
Brings you out of fullscreen.
Expand All @@ -92,6 +102,8 @@ declare namespace screenfull {
/**
Requests fullscreen if not active, otherwise exits.
@param element - Default is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant.
@param options - [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).
@returns A promise that resolves after the element enters/exits fullscreen.
@example
Expand All @@ -105,7 +117,7 @@ declare namespace screenfull {
});
```
*/
toggle(element?: Element): Promise<void>;
toggle(element?: Element, options?: FullscreenOptions): Promise<void>;

/**
Add a listener for when the browser switches in and out of fullscreen or when there is an error.
Expand Down
10 changes: 5 additions & 5 deletions dist/screenfull.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* screenfull
* v5.0.2 - 2020-02-13
* v5.0.2 - 2020-10-27
* (c) Sindre Sorhus; MIT License
*/
(function () {
Expand Down Expand Up @@ -82,7 +82,7 @@
};

var screenfull = {
request: function (element) {
request: function (element, options) {
return new Promise(function (resolve, reject) {
var onFullScreenEntered = function () {
this.off('change', onFullScreenEntered);
Expand All @@ -93,7 +93,7 @@

element = element || document.documentElement;

var returnPromise = element[fn.requestFullscreen]();
var returnPromise = element[fn.requestFullscreen](options);

if (returnPromise instanceof Promise) {
returnPromise.then(onFullScreenEntered).catch(reject);
Expand Down Expand Up @@ -121,8 +121,8 @@
}
}.bind(this));
},
toggle: function (element) {
return this.isFullscreen ? this.exit() : this.request(element);
toggle: function (element, options) {
return this.isFullscreen ? this.exit() : this.request(element, options);
},
onchange: function (callback) {
this.on('change', callback);
Expand Down
4 changes: 2 additions & 2 deletions dist/screenfull.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ document.getElementById('button').addEventListener('click', () => {
});
```

#### Hide navigation user-interface on mobile devices

```js
const element = document.getElementById('target');

document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element, {navigationUI: 'hide'});
}
});
```

#### Fullscreen an element with jQuery

```js
Expand Down Expand Up @@ -177,11 +189,13 @@ export class ToggleFullscreenDirective {

### API

#### .request()
#### .request(element, options?)

Make an element fullscreen.

Accepts a DOM element. Default is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant.
Accepts a DOM element and [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).

The default element is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant.

If your page is inside an `<iframe>` you will need to add a `allowfullscreen` attribute (+ `webkitallowfullscreen` and `mozallowfullscreen`).

Expand All @@ -195,10 +209,12 @@ Brings you out of fullscreen.

Returns a promise that resolves after the element exits fullscreen.

#### .toggle()
#### .toggle(element, options?)

Requests fullscreen if not active, otherwise exits.

Accepts a DOM element and [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).

Returns a promise that resolves after the element enters/exits fullscreen.

#### .on(event, function)
Expand Down
16 changes: 14 additions & 2 deletions src/screenfull.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare namespace screenfull {
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.
@param options - [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).
@returns A promise that resolves after the element enters fullscreen.
@example
Expand All @@ -70,6 +71,15 @@ declare namespace screenfull {
}
});
// Fullscreen an element with options
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element, {navigationUI: 'hide'});
}
});
// Fullscreen an element with jQuery
const element = $('#target')[0]; // Get DOM element from jQuery collection
Expand All @@ -80,7 +90,7 @@ declare namespace screenfull {
});
```
*/
request(element?: Element): Promise<void>;
request(element?: Element, options?: FullscreenOptions): Promise<void>;

/**
Brings you out of fullscreen.
Expand All @@ -92,6 +102,8 @@ declare namespace screenfull {
/**
Requests fullscreen if not active, otherwise exits.
@param element - Default is `<html>`. If called with another element than the currently active, it will switch to that if it's a decendant.
@param options - [`FullscreenOptions`](https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions).
@returns A promise that resolves after the element enters/exits fullscreen.
@example
Expand All @@ -105,7 +117,7 @@ declare namespace screenfull {
});
```
*/
toggle(element?: Element): Promise<void>;
toggle(element?: Element, options?: FullscreenOptions): Promise<void>;

/**
Add a listener for when the browser switches in and out of fullscreen or when there is an error.
Expand Down
8 changes: 4 additions & 4 deletions src/screenfull.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
};

var screenfull = {
request: function (element) {
request: function (element, options) {
return new Promise(function (resolve, reject) {
var onFullScreenEntered = function () {
this.off('change', onFullScreenEntered);
Expand All @@ -88,7 +88,7 @@

element = element || document.documentElement;

var returnPromise = element[fn.requestFullscreen]();
var returnPromise = element[fn.requestFullscreen](options);

if (returnPromise instanceof Promise) {
returnPromise.then(onFullScreenEntered).catch(reject);
Expand Down Expand Up @@ -116,8 +116,8 @@
}
}.bind(this));
},
toggle: function (element) {
return this.isFullscreen ? this.exit() : this.request(element);
toggle: function (element, options) {
return this.isFullscreen ? this.exit() : this.request(element, options);
},
onchange: function (callback) {
this.on('change', callback);
Expand Down

0 comments on commit 0092521

Please # to comment.