3d1f29a66823a803b77d4650f8f8b2d11390ab78
2 * jQuery fullscreen plugin v2.0.0
3 * https://github.com/theopolisme/jquery-fullscreen/tree/v2.0.0
5 * Documentation at <https://github.com/theopolisme/jquery-fullscreen/blob/v2.0.0/README.md>
7 * Copyright (c) 2013 Theopolisme <theopolismewiki@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 fsClass
= 'jq-fullscreened';
28 * On fullscreenchange, trigger a jq-fullscreen-change event
29 * The event is given an object, which contains the fullscreened DOM element (element), if any
30 * and a boolean value (fullscreen) indicating if we've entered or exited fullscreen mode
31 * Also remove the 'fullscreened' class from elements that are no longer fullscreen
33 function handleFullscreenChange () {
34 var fullscreenElement
= document
.fullscreenElement
||
35 document
.mozFullScreenElement
||
36 document
.webkitFullscreenElement
||
37 document
.msFullscreenElement
;
39 if ( !fullscreenElement
) {
40 $( '.' + fsClass
).data( 'isFullscreened', false ).removeClass( fsClass
);
43 $( document
).trigger( $.Event( 'jq-fullscreen-change', { element
: fullscreenElement
, fullscreen
: !!fullscreenElement
} ) );
47 * Enters full screen with the "this" element in focus.
48 * Check the .data( 'isFullscreened' ) of the return value to check
49 * success or failure, if you're into that sort of thing.
53 function enterFullscreen () {
54 var element
= this.get(0),
55 $element
= this.first();
57 if ( element
.requestFullscreen
) {
58 element
.requestFullscreen();
59 } else if ( element
.mozRequestFullScreen
) {
60 element
.mozRequestFullScreen();
61 } else if ( element
.webkitRequestFullscreen
) {
62 element
.webkitRequestFullscreen();
63 } else if ( element
.msRequestFullscreen
) {
64 element
.msRequestFullscreen();
66 // Unable to make fullscreen
67 $element
.data( 'isFullscreened', false );
70 // Add the fullscreen class and data attribute to `element`
71 $element
.addClass( fsClass
).data( 'isFullscreened', true );
74 $element
.data( 'isFullscreened', false );
80 * Brings the "this" element out of fullscreen.
81 * Check the .data( 'isFullscreened' ) of the return value to check
82 * success or failure, if you're into that sort of thing.
86 function exitFullscreen () {
87 var fullscreenElement
= ( document
.fullscreenElement
||
88 document
.mozFullScreenElement
||
89 document
.webkitFullscreenElement
||
90 document
.msFullscreenElement
);
92 // Ensure that we only exit fullscreen if exitFullscreen() is being called on the same element that is currently fullscreen
93 if ( fullscreenElement
&& this.get(0) === fullscreenElement
) {
94 if ( document
.exitFullscreen
) {
95 document
.exitFullscreen();
96 } else if ( document
.mozCancelFullScreen
) {
97 document
.mozCancelFullScreen();
98 } else if ( document
.webkitCancelFullScreen
) {
99 document
.webkitCancelFullScreen();
100 } else if ( document
.msCancelFullScreen
) {
101 document
.msCancelFullScreen();
103 // Unable to cancel fullscreen mode
106 // We don't need to remove the fullscreen class here,
107 // because it will be removed in handleFullscreenChange.
108 // But we should change the data on the element so the
109 // caller can check for success.
110 this.first().data( 'isFullscreened', false );
117 * Set up fullscreen handling and install necessary event handlers.
118 * Return false if fullscreen is not supported.
120 setupFullscreen = function () {
121 if ( $.support
.fullscreen
) {
122 // When the fullscreen mode is changed, trigger the
123 // fullscreen events (and when exiting,
124 // also remove the fullscreen class)
125 $( document
).on( 'fullscreenchange webkitfullscreenchange mozfullscreenchange msfullscreenchange', handleFullscreenChange
);
126 // Convenience wrapper so that one only needs to listen for
127 // 'fullscreenerror', not all of the prefixed versions
128 $( document
).on( 'webkitfullscreenerror mozfullscreenerror msfullscreenerror', function () {
129 $( document
).trigger( $.Event( 'fullscreenerror' ) );
131 // Fullscreen has been set up, so always return true
132 setupFullscreen = function () { return true; };
135 // Always return false from now on, since fullscreen is not supported
136 setupFullscreen = function() { return false; };
142 * Set up fullscreen handling if necessary, then make the first element
143 * matching the given selector fullscreen
147 $.fn
.enterFullscreen = function () {
148 if ( setupFullscreen() ) {
149 $.fn
.enterFullscreen
= enterFullscreen
;
150 return this.enterFullscreen();
152 $.fn
.enterFullscreen = function () { return this; };
158 * Set up fullscreen handling if necessary, then cancel fullscreen mode
159 * for the first element matching the given selector.
163 $.fn
.exitFullscreen = function () {
164 if ( setupFullscreen() ) {
165 $.fn
.exitFullscreen
= exitFullscreen
;
166 return this.exitFullscreen();
168 $.fn
.exitFullscreen = function () { return this; };
173 $.support
.fullscreen
= document
.fullscreenEnabled
||
174 document
.webkitFullscreenEnabled
||
175 document
.mozFullScreenEnabled
||
176 document
.msFullscreenEnabled
;