forked from code-lts/jquery-fullscreen-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fullscreen.js
101 lines (90 loc) · 2.95 KB
/
jquery.fullscreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @preserve jquery.fullscreen 1.0.0
* https://github.com/kayahr/jquery-fullscreen-plugin
* Copyright (C) 2012 Klaus Reimer <[email protected]>
* Licensed under the MIT license
* (See http://www.opensource.org/licenses/mit-license)
*/
(function() {
/**
* Sets or gets the fullscreen state.
*
* @param {boolean=} state
* True to enable fullscreen mode, false to disable it. If not
* specified then the current fullscreen state is returned.
* @return {boolean|jQuery|null}
* When querying the fullscreen state then true, false or null
* is returned. Null indicates a browser without fullscreen
* support. When setting the state then the current jQuery
* selection is returned for chaining.
* @this {jQuery}
*/
function fullScreen(state)
{
var e, func, doc;
// Do nothing when nothing was selected
if (!this.length) return this;
// We only use the first selected element because it doesn't make sense
// to fullscreen multiple elements.
e = (/** @type {Element} */ this[0]);
// Find the real element and the document (Depends on wether the
// document itself or a HTML element was selected)
if (e instanceof Document)
{
doc = e;
e = doc.documentElement;
}
else
{
doc = e.ownerDocument;
}
// When no state was specified then return the current state.
if (state == null)
{
// When fullscreen mode is not supported then return null
if (!((/** @type {?Function} */ doc["cancelFullScreen"])
|| (/** @type {?Function} */ doc["webkitCancelFullScreen"])
|| (/** @type {?Function} */ doc["mozCancelFullScreen"])))
{
return null;
}
// Return the current fullscreen state
return !!doc["fullScreen"]
|| !!doc["webkitIsFullScreen"]
|| !!doc["mozFullScreen"];
}
// When state was specified then enter or exit fullscreen mode.
if (state)
{
// Enter fullscreen
func = (/** @type {?Function} */ e["requestFullScreen"])
|| (/** @type {?Function} */ e["webkitRequestFullScreen"])
|| (/** @type {?Function} */ e["mozRequestFullScreen"]);
if (func) func.call(e);
return this;
}
else
{
// Exit fullscreen
func = (/** @type {?Function} */ doc["cancelFullScreen"])
|| (/** @type {?Function} */ doc["webkitCancelFullScreen"])
|| (/** @type {?Function} */ doc["mozCancelFullScreen"]);
if (func) func.call(doc);
return this;
}
};
/**
* Toggles the fullscreen mode.
*
* @return {!jQuery}
* The jQuery selection for chaining.
* @this {jQuery}
*/
function toggleFullScreen()
{
return (/** @type {!jQuery} */ fullScreen.call(this,
!fullScreen.call(this)));
};
jQuery.fn["fullScreen"] = fullScreen;
jQuery.fn["toggleFullScreen"] = toggleFullScreen;
})();