Add yoob.js' full-screen-detector.
catseye
11 years ago
0 | /* | |
1 | * This file is part of yoob.js version 0.5-PRE | |
2 | * Available from https://github.com/catseye/yoob.js/ | |
3 | * This file is in the public domain. See http://unlicense.org/ for details. | |
4 | */ | |
5 | if (window.yoob === undefined) yoob = {}; | |
6 | ||
7 | /* | |
8 | * A shim (of sorts) which detects when the user has toggled their browser's | |
9 | * full-screen mode (usually but not necessarily by pressing the F11 key) and | |
10 | * fires an 'onchange' event, in which you can resize DOM elements of your | |
11 | * choosing to suit the (non-)full-screen display (or whatever else you wish.) | |
12 | * | |
13 | * Tested in recent Firefox, Chromium, and IE. Sure to fail in older versions | |
14 | * of some of those. | |
15 | */ | |
16 | yoob.FullScreenDetector = function(cfg) { | |
17 | this.init = function(cfg) { | |
18 | this.period = cfg.period || 250; | |
19 | this.onchange = cfg.onchange || function() {}; | |
20 | this.fullScreen = false; | |
21 | this.start(); | |
22 | return this; | |
23 | }; | |
24 | ||
25 | this.start = function() { | |
26 | if (this.intervalId) return; | |
27 | var $this = this; | |
28 | this.intervalId = setInterval(function() { | |
29 | if (!$this.fullScreen) { | |
30 | if (window.fullScreen || | |
31 | ((!window.screenTop) && (!window.screenY))) { | |
32 | $this.fullScreen = true; | |
33 | $this.onchange($this.fullScreen); | |
34 | } | |
35 | } else { | |
36 | if (window.screenTop || window.screenY || | |
37 | (window.fullScreen === false)) { | |
38 | $this.fullScreen = false; | |
39 | $this.onchange($this.fullScreen); | |
40 | } | |
41 | } | |
42 | }, this.period); | |
43 | }; | |
44 | ||
45 | this.stop = function() { | |
46 | if (!this.intervalId) return; | |
47 | clearInterval(this.intervalId); | |
48 | this.intervalId = undefined; | |
49 | }; | |
50 | ||
51 | this.init(cfg); | |
52 | }; |