jquery.fullscreen

jquery fullscreen plugin

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/2858/26079/jqueryfullscreen.js

  1. // ==UserScript==
  2. // @name jquery.fullscreen
  3. // @namespace private-face
  4. // @description jquery fullscreen plugin
  5. // @source https://github.com/private-face/jquery.fullscreen
  6. // @copyright Vladimir Zhuravlev
  7. // @version 0.4.0
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. /*
  13. * jQuery.fullscreen library v0.4.0
  14. * Copyright (c) 2013 Vladimir Zhuravlev
  15. *
  16. * @license https://github.com/private-face/jquery.fullscreen/blob/master/LICENSE
  17. *
  18. * Date: Wed Dec 11 22:45:17 ICT 2013
  19. **/
  20.  
  21. function loadjQueryFullscreen(){
  22. ;(function($) {
  23.  
  24. function defined(a) {
  25. return typeof a !== 'undefined';
  26. }
  27.  
  28. function extend(child, parent, prototype) {
  29. var F = function() {};
  30. F.prototype = parent.prototype;
  31. child.prototype = new F();
  32. child.prototype.constructor = child;
  33. parent.prototype.constructor = parent;
  34. child._super = parent.prototype;
  35. if (prototype) {
  36. $.extend(child.prototype, prototype);
  37. }
  38. }
  39.  
  40. var SUBST = [
  41. ['', ''], // spec
  42. ['exit', 'cancel'], // firefox & old webkits expect cancelFullScreen instead of exitFullscreen
  43. ['screen', 'Screen'] // firefox expects FullScreen instead of Fullscreen
  44. ];
  45.  
  46. var VENDOR_PREFIXES = ['', 'o', 'ms', 'moz', 'webkit', 'webkitCurrent'];
  47.  
  48. function native(obj, name) {
  49. var prefixed;
  50.  
  51. if (typeof obj === 'string') {
  52. name = obj;
  53. obj = document;
  54. }
  55.  
  56. for (var i = 0; i < SUBST.length; ++i) {
  57. name = name.replace(SUBST[i][0], SUBST[i][1]);
  58. for (var j = 0; j < VENDOR_PREFIXES.length; ++j) {
  59. prefixed = VENDOR_PREFIXES[j];
  60. prefixed += j === 0 ? name : name.charAt(0).toUpperCase() + name.substr(1);
  61. if (defined(obj[prefixed])) {
  62. return obj[prefixed];
  63. }
  64. }
  65. }
  66.  
  67. return void 0;
  68. }var ua = navigator.userAgent;
  69. var fsEnabled = native('fullscreenEnabled');
  70. var IS_ANDROID_CHROME = ua.indexOf('Android') !== -1 && ua.indexOf('Chrome') !== -1;
  71. var IS_NATIVELY_SUPPORTED =
  72. !IS_ANDROID_CHROME &&
  73. defined(native('fullscreenElement')) &&
  74. (!defined(fsEnabled) || fsEnabled === true);
  75.  
  76. var version = $.fn.jquery.split('.');
  77. var JQ_LT_17 = (parseInt(version[0]) < 2 && parseInt(version[1]) < 7);
  78.  
  79. var FullScreenAbstract = function() {
  80. this.__options = null;
  81. this._fullScreenElement = null;
  82. this.__savedStyles = {};
  83. };
  84.  
  85. FullScreenAbstract.prototype = {
  86. _DEFAULT_OPTIONS: {
  87. styles: {
  88. 'boxSizing': 'border-box',
  89. 'MozBoxSizing': 'border-box',
  90. 'WebkitBoxSizing': 'border-box'
  91. },
  92. toggleClass: null
  93. },
  94. __documentOverflow: '',
  95. __htmlOverflow: '',
  96. _preventDocumentScroll: function() {
  97. this.__documentOverflow = $('body')[0].style.overflow;
  98. this.__htmlOverflow = $('html')[0].style.overflow;
  99. $('body, html').css('overflow', 'hidden');
  100. },
  101. _allowDocumentScroll: function() {
  102. $('body')[0].style.overflow = this.__documentOverflow;
  103. $('html')[0].style.overflow = this.__htmlOverflow;
  104. },
  105. _fullScreenChange: function() {
  106. if (!this.isFullScreen()) {
  107. this._allowDocumentScroll();
  108. this._revertStyles();
  109. this._triggerEvents();
  110. this._fullScreenElement = null;
  111. } else {
  112. this._preventDocumentScroll();
  113. this._triggerEvents();
  114. }
  115. },
  116. _fullScreenError: function(e) {
  117. this._revertStyles();
  118. this._fullScreenElement = null;
  119. if (e) {
  120. $(document).trigger('fscreenerror', [e]);
  121. }
  122. },
  123. _triggerEvents: function() {
  124. $(this._fullScreenElement).trigger(this.isFullScreen() ? 'fscreenopen' : 'fscreenclose');
  125. $(document).trigger('fscreenchange', [this.isFullScreen(), this._fullScreenElement]);
  126. },
  127. _saveAndApplyStyles: function() {
  128. var $elem = $(this._fullScreenElement);
  129. this.__savedStyles = {};
  130. for (var property in this.__options.styles) {
  131. // save
  132. this.__savedStyles[property] = this._fullScreenElement.style[property];
  133. // apply
  134. this._fullScreenElement.style[property] = this.__options.styles[property];
  135. }
  136. if (this.__options.toggleClass) {
  137. $elem.addClass(this.__options.toggleClass);
  138. }
  139. },
  140. _revertStyles: function() {
  141. var $elem = $(this._fullScreenElement);
  142. for (var property in this.__options.styles) {
  143. this._fullScreenElement.style[property] = this.__savedStyles[property];
  144. }
  145. if (this.__options.toggleClass) {
  146. $elem.removeClass(this.__options.toggleClass);
  147. }
  148. },
  149. open: function(elem, options) {
  150. // do nothing if request is for already fullscreened element
  151. if (elem === this._fullScreenElement) {
  152. return;
  153. }
  154. // exit active fullscreen before opening another one
  155. if (this.isFullScreen()) {
  156. this.exit();
  157. }
  158. // save fullscreened element
  159. this._fullScreenElement = elem;
  160. // apply options, if any
  161. this.__options = $.extend(true, {}, this._DEFAULT_OPTIONS, options);
  162. // save current element styles and apply new
  163. this._saveAndApplyStyles();
  164. },
  165. exit: null,
  166. isFullScreen: null,
  167. isNativelySupported: function() {
  168. return IS_NATIVELY_SUPPORTED;
  169. }
  170. };
  171. var FullScreenNative = function() {
  172. FullScreenNative._super.constructor.apply(this, arguments);
  173. this.exit = $.proxy(native('exitFullscreen'), document);
  174. this._DEFAULT_OPTIONS = $.extend(true, {}, this._DEFAULT_OPTIONS, {
  175. 'styles': {
  176. 'width': '100%',
  177. 'height': '100%'
  178. }
  179. });
  180. $(document)
  181. .bind(this._prefixedString('fullscreenchange') + ' MSFullscreenChange', $.proxy(this._fullScreenChange, this))
  182. .bind(this._prefixedString('fullscreenerror') + ' MSFullscreenError', $.proxy(this._fullScreenError, this));
  183. };
  184.  
  185. extend(FullScreenNative, FullScreenAbstract, {
  186. VENDOR_PREFIXES: ['', 'o', 'moz', 'webkit'],
  187. _prefixedString: function(str) {
  188. return $.map(this.VENDOR_PREFIXES, function(s) {
  189. return s + str;
  190. }).join(' ');
  191. },
  192. open: function(elem, options) {
  193. FullScreenNative._super.open.apply(this, arguments);
  194. var requestFS = native(elem, 'requestFullscreen');
  195. requestFS.call(elem);
  196. },
  197. exit: $.noop,
  198. isFullScreen: function() {
  199. return native('fullscreenElement') !== null;
  200. },
  201. element: function() {
  202. return native('fullscreenElement');
  203. }
  204. });
  205. var FullScreenFallback = function() {
  206. FullScreenFallback._super.constructor.apply(this, arguments);
  207. this._DEFAULT_OPTIONS = $.extend({}, this._DEFAULT_OPTIONS, {
  208. 'styles': {
  209. 'position': 'fixed',
  210. 'zIndex': '2147483647',
  211. 'left': 0,
  212. 'top': 0,
  213. 'bottom': 0,
  214. 'right': 0
  215. }
  216. });
  217. this.__delegateKeydownHandler();
  218. };
  219.  
  220. extend(FullScreenFallback, FullScreenAbstract, {
  221. __isFullScreen: false,
  222. __delegateKeydownHandler: function() {
  223. var $doc = $(document);
  224. $doc.delegate('*', 'keydown.fullscreen', $.proxy(this.__keydownHandler, this));
  225. var data = JQ_LT_17 ? $doc.data('events') : $._data(document).events;
  226. var events = data['keydown'];
  227. if (!JQ_LT_17) {
  228. events.splice(0, 0, events.splice(events.delegateCount - 1, 1)[0]);
  229. } else {
  230. data.live.unshift(data.live.pop());
  231. }
  232. },
  233. __keydownHandler: function(e) {
  234. if (this.isFullScreen() && e.which === 27) {
  235. this.exit();
  236. return false;
  237. }
  238. return true;
  239. },
  240. _revertStyles: function() {
  241. FullScreenFallback._super._revertStyles.apply(this, arguments);
  242. // force redraw (fixes bug in IE7 with content dissapearing)
  243. this._fullScreenElement.offsetHeight;
  244. },
  245. open: function(elem) {
  246. FullScreenFallback._super.open.apply(this, arguments);
  247. this.__isFullScreen = true;
  248. this._fullScreenChange();
  249. },
  250. exit: function() {
  251. this.__isFullScreen = false;
  252. this._fullScreenChange();
  253. },
  254. isFullScreen: function() {
  255. return this.__isFullScreen;
  256. },
  257. element: function() {
  258. return this.__isFullScreen ? this._fullScreenElement : null;
  259. }
  260. });$.fullscreen = IS_NATIVELY_SUPPORTED
  261. ? new FullScreenNative()
  262. : new FullScreenFallback();
  263.  
  264. $.fn.fullscreen = function(options) {
  265. var elem = this[0];
  266.  
  267. options = $.extend({
  268. toggleClass: null,
  269. overflow: 'hidden'
  270. }, options);
  271. options.styles = {
  272. overflow: options.overflow
  273. };
  274. delete options.overflow;
  275.  
  276. if (elem) {
  277. $.fullscreen.open(elem, options);
  278. }
  279.  
  280. return this;
  281. };
  282. })(jQuery);
  283. }
  284. if (window.document.readyState === 'complete') {
  285. loadjQueryFullscreen();
  286. } else {
  287. window.addEventListener('load',loadjQueryFullscreen, false);
  288. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址