Add support for old webkit. Add fullScreenApi.getFullScreenElement method. Remove old license.

This commit is contained in:
Antoine Vandecreme 2014-03-25 13:29:58 -04:00
parent 6e48de47ed
commit 7055322ee3

View File

@ -32,42 +32,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
* Implementation and research by John Dyer in:
* http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
* John Dyer has released this fullscreen code under the MIT license; see
* <https://github.com/openseadragon/openseadragon/issues/81>.
*
* Copyright (C) 2011 John Dyer
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function( $ ) { (function( $ ) {
/** /**
* Determined native full screen support we can get from the browser. * Determine native full screen support we can get from the browser.
* @member fullScreenApi * @member fullScreenApi
* @memberof OpenSeadragon * @memberof OpenSeadragon
* @type {object} * @type {object}
* @property {Boolean} supportsFullScreen Return true if full screen API is supported. * @property {Boolean} supportsFullScreen Return true if full screen API is supported.
* @property {Function} isFullScreen Return true if currently in full screen mode. * @property {Function} isFullScreen Return true if currently in full screen mode.
* @property {Function} getFullScreenElement Return the element currently in full screen mode.
* @property {Function} requestFullScreen Make a request to go in full screen mode. * @property {Function} requestFullScreen Make a request to go in full screen mode.
* @property {Function} exitFullScreen Make a request to exit full screen mode. * @property {Function} exitFullScreen Make a request to exit full screen mode.
* @property {Function} cancelFullScreen Deprecated, use exitFullScreen instead. * @property {Function} cancelFullScreen Deprecated, use exitFullScreen instead.
@ -78,6 +51,7 @@
var fullScreenApi = { var fullScreenApi = {
supportsFullScreen: false, supportsFullScreen: false,
isFullScreen: function() { return false; }, isFullScreen: function() { return false; },
getFullScreenElement: function() { return null; },
requestFullScreen: function() {}, requestFullScreen: function() {},
exitFullScreen: function() {}, exitFullScreen: function() {},
cancelFullScreen: function() {}, cancelFullScreen: function() {},
@ -87,9 +61,10 @@
// check for native support // check for native support
if ( document.exitFullscreen ) { if ( document.exitFullscreen ) {
// W3C standard
fullScreenApi.supportsFullScreen = true; fullScreenApi.supportsFullScreen = true;
fullScreenApi.isFullScreen = function() { fullScreenApi.getFullScreenElement = function() {
return document.fullscreenElement !== null; return document.fullscreenElement;
}; };
fullScreenApi.requestFullScreen = function( element ) { fullScreenApi.requestFullScreen = function( element ) {
return element.requestFullscreen(); return element.requestFullscreen();
@ -100,9 +75,10 @@
fullScreenApi.fullScreenEventName = "fullscreenchange"; fullScreenApi.fullScreenEventName = "fullscreenchange";
fullScreenApi.fullScreenErrorEventName = "fullscreenerror"; fullScreenApi.fullScreenErrorEventName = "fullscreenerror";
} else if ( document.msExitFullscreen ) { } else if ( document.msExitFullscreen ) {
// IE 11
fullScreenApi.supportsFullScreen = true; fullScreenApi.supportsFullScreen = true;
fullScreenApi.isFullScreen = function() { fullScreenApi.getFullScreenElement = function() {
return document.msFullscreenElement !== null; return document.msFullscreenElement;
}; };
fullScreenApi.requestFullScreen = function( element ) { fullScreenApi.requestFullScreen = function( element ) {
return element.msRequestFullscreen(); return element.msRequestFullscreen();
@ -113,9 +89,10 @@
fullScreenApi.fullScreenEventName = "MSFullscreenChange"; fullScreenApi.fullScreenEventName = "MSFullscreenChange";
fullScreenApi.fullScreenErrorEventName = "MSFullscreenError"; fullScreenApi.fullScreenErrorEventName = "MSFullscreenError";
} else if ( document.webkitExitFullscreen ) { } else if ( document.webkitExitFullscreen ) {
// Recent webkit
fullScreenApi.supportsFullScreen = true; fullScreenApi.supportsFullScreen = true;
fullScreenApi.isFullScreen = function() { fullScreenApi.getFullScreenElement = function() {
return document.webkitIsFullScreen; return document.webkitFullscreenElement;
}; };
fullScreenApi.requestFullScreen = function( element ) { fullScreenApi.requestFullScreen = function( element ) {
return element.webkitRequestFullscreen(); return element.webkitRequestFullscreen();
@ -125,10 +102,25 @@
}; };
fullScreenApi.fullScreenEventName = "webkitfullscreenchange"; fullScreenApi.fullScreenEventName = "webkitfullscreenchange";
fullScreenApi.fullScreenErrorEventName = "webkitfullscreenerror"; fullScreenApi.fullScreenErrorEventName = "webkitfullscreenerror";
} else if ( document.mozCancelFullScreen ) { } else if ( document.webkitCancelFullScreen ) {
// Old webkit
fullScreenApi.supportsFullScreen = true; fullScreenApi.supportsFullScreen = true;
fullScreenApi.isFullScreen = function() { fullScreenApi.getFullScreenElement = function() {
return document.mozFullScreen; return document.webkitCurrentFullScreenElement;
};
fullScreenApi.requestFullScreen = function( element ) {
return element.webkitRequestFullScreen();
};
fullScreenApi.exitFullScreen = function() {
document.webkitCancelFullScreen();
};
fullScreenApi.fullScreenEventName = "webkitfullscreenchange";
fullScreenApi.fullScreenErrorEventName = "webkitfullscreenerror";
} else if ( document.mozCancelFullScreen ) {
// Firefox
fullScreenApi.supportsFullScreen = true;
fullScreenApi.getFullScreenElement = function() {
return document.mozFullScreenElement;
}; };
fullScreenApi.requestFullScreen = function( element ) { fullScreenApi.requestFullScreen = function( element ) {
return element.mozRequestFullScreen(); return element.mozRequestFullScreen();
@ -139,6 +131,9 @@
fullScreenApi.fullScreenEventName = "mozfullscreenchange"; fullScreenApi.fullScreenEventName = "mozfullscreenchange";
fullScreenApi.fullScreenErrorEventName = "mozfullscreenerror"; fullScreenApi.fullScreenErrorEventName = "mozfullscreenerror";
} }
fullScreenApi.isFullScreen = function() {
return fullScreenApi.getFullScreenElement() !== null;
};
fullScreenApi.cancelFullScreen = function() { fullScreenApi.cancelFullScreen = function() {
$.console.error("cancelFullScreen is deprecated. Use exitFullScreen instead."); $.console.error("cancelFullScreen is deprecated. Use exitFullScreen instead.");
fullScreenApi.exitFullScreen(); fullScreenApi.exitFullScreen();