|
2 | 2 | Copyright (c) 2008-2010 Ricardo Quesada
|
3 | 3 | Copyright (c) 2011-2012 cocos2d-x.org
|
4 | 4 | Copyright (c) 2013-2014 Chukong Technologies Inc.
|
5 |
| -
|
| 5 | + |
6 | 6 | http://www.cocos2d-x.org
|
7 |
| -
|
| 7 | + |
8 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 | 9 | of this software and associated documentation files (the "Software"), to deal
|
10 | 10 | in the Software without restriction, including without limitation the rights
|
11 | 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12 | 12 | copies of the Software, and to permit persons to whom the Software is
|
13 | 13 | furnished to do so, subject to the following conditions:
|
14 |
| -
|
| 14 | + |
15 | 15 | The above copyright notice and this permission notice shall be included in
|
16 | 16 | all copies or substantial portions of the Software.
|
17 |
| -
|
| 17 | + |
18 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19 | 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20 | 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32 | 32 | */
|
33 | 33 | cc.screen = /** @lends cc.screen# */{
|
34 | 34 | _supportsFullScreen: false,
|
35 |
| - // the pre fullscreenchange function |
| 35 | + // the pre fullscreenchange function |
36 | 36 | _preOnFullScreenChange: null,
|
37 | 37 | _touchEvent: "",
|
38 |
| - _fn: null, |
39 |
| - // Function mapping for cross browser support |
40 |
| - _fnMap: [ |
41 |
| - [ |
42 |
| - 'requestFullscreen', |
43 |
| - 'exitFullscreen', |
44 |
| - 'fullscreenchange', |
45 |
| - 'fullscreenEnabled', |
46 |
| - 'fullscreenElement' |
47 |
| - ], |
48 |
| - [ |
49 |
| - 'requestFullScreen', |
50 |
| - 'exitFullScreen', |
51 |
| - 'fullScreenchange', |
52 |
| - 'fullScreenEnabled', |
53 |
| - 'fullScreenElement' |
54 |
| - ], |
55 |
| - [ |
56 |
| - 'webkitRequestFullScreen', |
57 |
| - 'webkitCancelFullScreen', |
58 |
| - 'webkitfullscreenchange', |
59 |
| - 'webkitIsFullScreen', |
60 |
| - 'webkitCurrentFullScreenElement' |
61 |
| - ], |
62 |
| - [ |
63 |
| - 'mozRequestFullScreen', |
64 |
| - 'mozCancelFullScreen', |
65 |
| - 'mozfullscreenchange', |
66 |
| - 'mozFullScreen', |
67 |
| - 'mozFullScreenElement' |
68 |
| - ], |
69 |
| - [ |
70 |
| - 'msRequestFullscreen', |
71 |
| - 'msExitFullscreen', |
72 |
| - 'MSFullscreenChange', |
73 |
| - 'msFullscreenEnabled', |
74 |
| - 'msFullscreenElement' |
75 |
| - ] |
76 |
| - ], |
77 |
| - |
| 38 | + _fn: null, |
| 39 | + // Function mapping for cross browser support |
| 40 | + _fnMap: [ |
| 41 | + [ |
| 42 | + 'requestFullscreen', |
| 43 | + 'exitFullscreen', |
| 44 | + 'fullscreenchange', |
| 45 | + 'fullscreenEnabled', |
| 46 | + 'fullscreenElement' |
| 47 | + ], |
| 48 | + [ |
| 49 | + 'requestFullScreen', |
| 50 | + 'exitFullScreen', |
| 51 | + 'fullScreenchange', |
| 52 | + 'fullScreenEnabled', |
| 53 | + 'fullScreenElement' |
| 54 | + ], |
| 55 | + [ |
| 56 | + 'webkitRequestFullScreen', |
| 57 | + 'webkitCancelFullScreen', |
| 58 | + 'webkitfullscreenchange', |
| 59 | + 'webkitIsFullScreen', |
| 60 | + 'webkitCurrentFullScreenElement' |
| 61 | + ], |
| 62 | + [ |
| 63 | + 'mozRequestFullScreen', |
| 64 | + 'mozCancelFullScreen', |
| 65 | + 'mozfullscreenchange', |
| 66 | + 'mozFullScreen', |
| 67 | + 'mozFullScreenElement' |
| 68 | + ], |
| 69 | + [ |
| 70 | + 'msRequestFullscreen', |
| 71 | + 'msExitFullscreen', |
| 72 | + 'MSFullscreenChange', |
| 73 | + 'msFullscreenEnabled', |
| 74 | + 'msFullscreenElement' |
| 75 | + ] |
| 76 | + ], |
| 77 | + |
78 | 78 | /**
|
79 | 79 | * initialize
|
80 | 80 | * @function
|
81 | 81 | */
|
82 | 82 | init: function () {
|
83 |
| - this._fn = {}; |
84 |
| - var i, val, map = this._fnMap, valL; |
85 |
| - for (i = 0, l = map.length; i < l; i++ ) { |
86 |
| - val = map[ i ]; |
87 |
| - if ( val && val[1] in document ) { |
88 |
| - for ( i = 0, valL = val.length; i < valL; i++ ) { |
89 |
| - this._fn[ map[0][ i ] ] = val[ i ]; |
90 |
| - } |
91 |
| - break; |
92 |
| - } |
93 |
| - } |
| 83 | + this._fn = {}; |
| 84 | + var i, val, map = this._fnMap, valL; |
| 85 | + for (i = 0, l = map.length; i < l; i++) { |
| 86 | + val = map[i]; |
| 87 | + if (val && val[1] in document) { |
| 88 | + for (i = 0, valL = val.length; i < valL; i++) { |
| 89 | + this._fn[map[0][i]] = val[i]; |
| 90 | + } |
| 91 | + break; |
| 92 | + } |
| 93 | + } |
94 | 94 |
|
95 |
| - this._supportsFullScreen = (this._fn.requestFullscreen != undefined); |
| 95 | + this._supportsFullScreen = (typeof this._fn.requestFullscreen !== 'undefined'); |
96 | 96 | this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
|
97 | 97 | },
|
98 |
| - |
| 98 | + |
99 | 99 | /**
|
100 | 100 | * return true if it's full now.
|
101 | 101 | * @returns {Boolean}
|
102 | 102 | */
|
103 |
| - fullScreen: function() { |
104 |
| - return this._supportsFullScreen && document[this._fn.fullscreenElement]; |
| 103 | + fullScreen: function () { |
| 104 | + return this._supportsFullScreen && document[this._fn.fullscreenElement]; |
105 | 105 | },
|
106 |
| - |
| 106 | + |
107 | 107 | /**
|
108 | 108 | * change the screen to full mode.
|
109 | 109 | * @param {Element} element
|
110 | 110 | * @param {Function} onFullScreenChange
|
111 | 111 | */
|
112 | 112 | requestFullScreen: function (element, onFullScreenChange) {
|
113 |
| - if (!this._supportsFullScreen) return; |
| 113 | + if (!this._supportsFullScreen) { |
| 114 | + return; |
| 115 | + } |
114 | 116 |
|
115 |
| - element = element || document.documentElement; |
116 |
| - element[ this._fn.requestFullscreen ](); |
| 117 | + element = element || document.documentElement; |
| 118 | + element[this._fn.requestFullscreen](); |
117 | 119 |
|
118 |
| - if (onFullScreenChange) { |
119 |
| - var eventName = this._fn.fullscreenchange; |
120 |
| - if (this._preOnFullScreenChange) |
121 |
| - document.removeEventListener(eventName, this._preOnFullScreenChange); |
122 |
| - this._preOnFullScreenChange = onFullScreenChange; |
| 120 | + if (onFullScreenChange) { |
| 121 | + var eventName = this._fn.fullscreenchange; |
| 122 | + if (this._preOnFullScreenChange) { |
| 123 | + document.removeEventListener(eventName, this._preOnFullScreenChange); |
| 124 | + } |
| 125 | + this._preOnFullScreenChange = onFullScreenChange; |
123 | 126 | cc._addEventListener(document, eventName, onFullScreenChange, false);
|
124 |
| - } |
| 127 | + } |
125 | 128 |
|
126 |
| - return element[ this._fn.requestFullscreen ](); |
| 129 | + return element[this._fn.requestFullscreen](); |
127 | 130 | },
|
128 |
| - |
| 131 | + |
129 | 132 | /**
|
130 | 133 | * exit the full mode.
|
131 | 134 | * @return {Boolean}
|
132 | 135 | */
|
133 | 136 | exitFullScreen: function () {
|
134 |
| - return this._supportsFullScreen ? document[ this._fn.exitFullscreen ]() : true; |
| 137 | + return this._supportsFullScreen ? document[this._fn.exitFullscreen]() : true; |
135 | 138 | },
|
136 |
| - |
| 139 | + |
137 | 140 | /**
|
138 | 141 | * Automatically request full screen with a touch/click event
|
139 | 142 | * @param {Element} element
|
140 | 143 | * @param {Function} onFullScreenChange
|
141 | 144 | */
|
142 | 145 | autoFullScreen: function (element, onFullScreenChange) {
|
143 |
| - element = element || document.body; |
144 |
| - var touchTarget = cc._canvas || element; |
| 146 | + element = element || document.body; |
| 147 | + var touchTarget = cc._canvas || element; |
145 | 148 | var theScreen = this;
|
146 | 149 | // Function bind will be too complicated here because we need the callback function's reference to remove the listener
|
147 | 150 | function callback() {
|
|
0 commit comments