55 * Licensed under the MIT license
66 * (See http://www.opensource.org/licenses/mit-license)
77 */
8-
8+
99( function ( jQuery ) {
1010
1111/**
1212 * Sets or gets the fullscreen state.
13- *
13+ *
1414 * @param {boolean= } state
1515 * True to enable fullscreen mode, false to disable it. If not
1616 * specified then the current fullscreen state is returned.
1717 * @return {boolean|Element|jQuery|null }
1818 * When querying the fullscreen state then the current fullscreen
1919 * element (or true if browser doesn't support it) is returned
2020 * when browser is currently in full screen mode. False is returned
21- * if browser is not in full screen mode. Null is returned if
22- * browser doesn't support fullscreen mode at all. When setting
23- * the fullscreen state then the current jQuery selection is
21+ * if browser is not in full screen mode. Null is returned if
22+ * browser doesn't support fullscreen mode at all. When setting
23+ * the fullscreen state then the current jQuery selection is
2424 * returned for chaining.
2525 * @this {jQuery}
2626 */
2727function fullScreen ( state )
2828{
2929 var e , func , doc ;
30-
30+
3131 // Do nothing when nothing was selected
3232 if ( ! this . length ) return this ;
33-
33+
3434 // We only use the first selected element because it doesn't make sense
3535 // to fullscreen multiple elements.
3636 e = ( /** @type {Element } */ this [ 0 ] ) ;
37-
37+
3838 // Find the real element and the document (Depends on whether the
3939 // document itself or a HTML element was selected)
4040 if ( e . ownerDocument )
@@ -46,7 +46,7 @@ function fullScreen(state)
4646 doc = e ;
4747 e = doc . documentElement ;
4848 }
49-
49+
5050 // When no state was specified then return the current state.
5151 if ( state == null )
5252 {
@@ -59,14 +59,11 @@ function fullScreen(state)
5959 {
6060 return null ;
6161 }
62-
62+
6363 // Check fullscreen state
64- state = ! ! doc [ "fullscreenElement" ]
65- || ! ! doc [ "msFullscreenElement" ]
66- || ! ! doc [ "webkitIsFullScreen" ]
67- || ! ! doc [ "mozFullScreen" ] ;
64+ state = fullScreenState ( doc ) ;
6865 if ( ! state ) return state ;
69-
66+
7067 // Return current fullscreen element or "true" if browser doesn't
7168 // support this
7269 return ( /** @type {?Element } */ doc [ "fullscreenElement" ] )
@@ -76,7 +73,7 @@ function fullScreen(state)
7673 || ( /** @type {?Element } */ doc [ "mozFullScreenElement" ] )
7774 || state ;
7875 }
79-
76+
8077 // When state was specified then enter or exit fullscreen mode.
8178 if ( state )
8279 {
@@ -86,7 +83,7 @@ function fullScreen(state)
8683 || ( /** @type {?Function } */ e [ "webkitRequestFullScreen" ] )
8784 || ( /** @type {?Function } */ e [ "msRequestFullscreen" ] )
8885 || ( /** @type {?Function } */ e [ "mozRequestFullScreen" ] ) ;
89- if ( func )
86+ if ( func )
9087 {
9188 func . call ( e ) ;
9289 }
@@ -100,21 +97,31 @@ function fullScreen(state)
10097 || ( /** @type {?Function } */ doc [ "webkitCancelFullScreen" ] )
10198 || ( /** @type {?Function } */ doc [ "msExitFullscreen" ] )
10299 || ( /** @type {?Function } */ doc [ "mozCancelFullScreen" ] ) ;
103- if ( func ) func . call ( doc ) ;
100+ if ( func && fullScreenState ( doc ) ) func . call ( doc ) ;
104101 return this ;
105102 }
106103}
107104
105+ /**
106+ * Check fullscreen state
107+ *
108+ * @param {Document } doc The content document
109+ * @return {Boolean }
110+ */
111+ function fullScreenState ( doc ) {
112+ return ! ! ( doc [ "fullscreenElement" ] || doc [ "msFullscreenElement" ] || doc [ "webkitIsFullScreen" ] || doc [ "mozFullScreen" ] ) ;
113+ }
114+
108115/**
109116 * Toggles the fullscreen mode.
110- *
117+ *
111118 * @return {!jQuery }
112119 * The jQuery selection for chaining.
113120 * @this {jQuery}
114121 */
115122function toggleFullScreen ( )
116123{
117- return ( /** @type {!jQuery } */ fullScreen . call ( this ,
124+ return ( /** @type {!jQuery } */ fullScreen . call ( this ,
118125 ! fullScreen . call ( this ) ) ) ;
119126}
120127
@@ -148,7 +155,7 @@ function fullScreenErrorHandler(event)
148155function installFullScreenHandlers ( )
149156{
150157 var e , change , error ;
151-
158+
152159 // Determine event name
153160 e = document ;
154161 if ( e [ "webkitCancelFullScreen" ] )
@@ -166,7 +173,7 @@ function installFullScreenHandlers()
166173 change = "mozfullscreenchange" ;
167174 error = "mozfullscreenerror" ;
168175 }
169- else
176+ else
170177 {
171178 change = "fullscreenchange" ;
172179 error = "fullscreenerror" ;
0 commit comments