From 3801326e4042a86816041ade62573902a1e52312 Mon Sep 17 00:00:00 2001 From: thatcher Date: Wed, 6 Mar 2013 15:36:52 -0500 Subject: [PATCH] pulling full screen api detection out into is own file per ians suggestion --- Gruntfile.js | 1 + src/fullscreen.js | 78 +++++++++++++++++++++++++++++++++++++++++++ src/openseadragon.js | 79 +------------------------------------------- 3 files changed, 80 insertions(+), 78 deletions(-) create mode 100644 src/fullscreen.js diff --git a/Gruntfile.js b/Gruntfile.js index bd21d089..c3006fbd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -13,6 +13,7 @@ module.exports = function(grunt) { minified = "build/openseadragon/openseadragon.min.js", sources = [ "src/openseadragon.js", + "src/fullscreen.js", "src/eventhandler.js", "src/mousetracker.js", "src/control.js", diff --git a/src/fullscreen.js b/src/fullscreen.js new file mode 100644 index 00000000..16c3a4d0 --- /dev/null +++ b/src/fullscreen.js @@ -0,0 +1,78 @@ +/** + * Determines the appropriate level of native full screen support we can get + * from the browser. + * Thanks to John Dyer for the implementation and research + * http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ + * Also includes older IE support based on + * http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen/7525760 + * @name $.supportsFullScreen + */ +(function( $ ) { + var fullScreenApi = { + supportsFullScreen: false, + isFullScreen: function() { return false; }, + requestFullScreen: function() {}, + cancelFullScreen: function() {}, + fullScreenEventName: '', + prefix: '' + }, + browserPrefixes = 'webkit moz o ms khtml'.split(' '); + + // check for native support + if (typeof document.cancelFullScreen != 'undefined') { + fullScreenApi.supportsFullScreen = true; + } else { + // check for fullscreen support by vendor prefix + for (var i = 0, il = browserPrefixes.length; i < il; i++ ) { + fullScreenApi.prefix = browserPrefixes[i]; + + if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) { + fullScreenApi.supportsFullScreen = true; + + break; + } + } + } + + // update methods to do something useful + if (fullScreenApi.supportsFullScreen) { + fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange'; + + fullScreenApi.isFullScreen = function() { + switch (this.prefix) { + case '': + return document.fullScreen; + case 'webkit': + return document.webkitIsFullScreen; + default: + return document[this.prefix + 'FullScreen']; + } + }; + fullScreenApi.requestFullScreen = function( element ) { + return (this.prefix === '') ? + element.requestFullScreen() : + element[this.prefix + 'RequestFullScreen'](); + + }; + fullScreenApi.cancelFullScreen = function( element ) { + return (this.prefix === '') ? + document.cancelFullScreen() : + document[this.prefix + 'CancelFullScreen'](); + }; + } else if ( typeof window.ActiveXObject !== "undefined" ){ + // Older IE. + fullScreenApi.requestFullScreen = function(){ + var wscript = new ActiveXObject("WScript.Shell"); + if ( wscript !== null ) { + wscript.SendKeys("{F11}"); + } + return false; + }; + fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen; + } + + + // export api + $.extend( $, fullScreenApi ); + +})( OpenSeadragon ); \ No newline at end of file diff --git a/src/openseadragon.js b/src/openseadragon.js index a353d372..cd9700ca 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1655,84 +1655,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ })(); - /** - * Determines the appropriate level of native full screen support we can get - * from the browser. - * Thanks to John Dyer for the implementation and research - * http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/ - * Also includes older IE support based on - * http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen/7525760 - * @name $.supportsFullScreen - */ - (function() { - var fullScreenApi = { - supportsFullScreen: false, - isFullScreen: function() { return false; }, - requestFullScreen: function() {}, - cancelFullScreen: function() {}, - fullScreenEventName: '', - prefix: '' - }, - browserPrefixes = 'webkit moz o ms khtml'.split(' '); - - // check for native support - if (typeof document.cancelFullScreen != 'undefined') { - fullScreenApi.supportsFullScreen = true; - } else { - // check for fullscreen support by vendor prefix - for (var i = 0, il = browserPrefixes.length; i < il; i++ ) { - fullScreenApi.prefix = browserPrefixes[i]; - - if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) { - fullScreenApi.supportsFullScreen = true; - - break; - } - } - } - - // update methods to do something useful - if (fullScreenApi.supportsFullScreen) { - fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange'; - - fullScreenApi.isFullScreen = function() { - switch (this.prefix) { - case '': - return document.fullScreen; - case 'webkit': - return document.webkitIsFullScreen; - default: - return document[this.prefix + 'FullScreen']; - } - }; - fullScreenApi.requestFullScreen = function( element ) { - return (this.prefix === '') ? - element.requestFullScreen() : - element[this.prefix + 'RequestFullScreen'](); - - }; - fullScreenApi.cancelFullScreen = function( element ) { - return (this.prefix === '') ? - document.cancelFullScreen() : - document[this.prefix + 'CancelFullScreen'](); - }; - } else if ( typeof window.ActiveXObject !== "undefined" ){ - // Older IE. - fullScreenApi.requestFullScreen = function(){ - var wscript = new ActiveXObject("WScript.Shell"); - if ( wscript !== null ) { - wscript.SendKeys("{F11}"); - } - return false; - }; - fullScreenApi.cancelFullScreen = fullScreenApi.requestFullScreen; - } - - - // export api - $.extend( $, fullScreenApi ); - - })(); + //TODO: $.console is often used inside a try/catch block which generally