|
1 | 1 | /* global angular */ |
2 | | -(function(angular) { |
3 | | -angular.module('angularScreenfull', []); |
4 | | -})(angular); |
| 2 | +/** |
| 3 | + * @ngdoc overview |
| 4 | + * @name angularScreenfull |
| 5 | + * @id index |
| 6 | + * @description |
| 7 | + * Lalala some text, some other text, moar text |
| 8 | + * @example |
| 9 | + <example module="myApp"> |
| 10 | + <file name="app.js"> |
| 11 | + angular.module('myApp', ['angularScreenfull']); |
| 12 | + </file> |
| 13 | + <file name="index.html"> |
| 14 | + <div ngsf-fullscreen> |
| 15 | + <p>This is a fullscreen element</p> |
| 16 | + <button ngsf-toggle-fullscreen>Toggle fullscreen</button> |
| 17 | + </div> |
| 18 | + </file> |
| 19 | + </example> |
| 20 | + * |
| 21 | + * More more text, bla bla |
| 22 | + *@example |
| 23 | + <example module="myApp"> |
| 24 | + <file name="app.js"> |
| 25 | + angular.module('myApp', ['angularScreenfull']); |
| 26 | + </file> |
| 27 | + <file name="index.html"> |
| 28 | + <div ngsf-fullscreen="fullscreenCtrl"> |
| 29 | + <p>This is another fullscreen element</p> |
| 30 | + <button ng-click="fullscreenCtrl.toggleFullscreen()">Toggle fullscreen</button> |
| 31 | + </div> |
| 32 | + </file> |
| 33 | + </example> |
| 34 | +
|
| 35 | + */ |
| 36 | +(function() { |
| 37 | + angular.module('angularScreenfull', []); |
| 38 | +})(); |
| 39 | + |
5 | 40 | /* global angular, screenfull */ |
6 | | -(function(angular) { |
7 | | - angular.module('angularScreenfull') |
8 | | - .directive('ngsfFullscreen',ngsfFullscreenDirective); |
| 41 | +(function() { |
| 42 | + 'use strict'; |
| 43 | + |
| 44 | + angular |
| 45 | + .module('angularScreenfull') |
| 46 | + .directive('ngsfFullscreen', ngsfFullscreenDirective); |
| 47 | + |
| 48 | + /** |
| 49 | + * @ngdoc directive |
| 50 | + * @name angularScreenfull.directive:ngsfFullscreen |
| 51 | + * @restrict A |
| 52 | + * |
| 53 | + * @description |
| 54 | + * Marks the element that is going to be fullscreen |
| 55 | + * |
| 56 | + * @param {string=} ngsfFullscreen An optional expression to store the fullscreen controller |
| 57 | + * |
| 58 | + * @example |
| 59 | + <example module="myApp"> |
| 60 | + <file name="app.js"> |
| 61 | + angular.module('myApp', ['angularScreenfull']); |
| 62 | + </file> |
| 63 | + <file name="index.html"> |
| 64 | + <div ngsf-fullscreen> |
| 65 | + <p>This is a fullscreen element</p> |
| 66 | + <button ngsf-toggle-fullscreen>Toggle fullscreen</button> |
| 67 | + </div> |
| 68 | + </file> |
| 69 | + </example> |
| 70 | + */ |
9 | 71 |
|
10 | 72 | ngsfFullscreenDirective.$inject = ['$parse']; |
11 | 73 | function ngsfFullscreenDirective ($parse) { |
12 | 74 | return { |
13 | 75 | restrict: 'A', |
14 | 76 | require: 'ngsfFullscreen', |
15 | | - controller: ngsfFullscreenController, |
16 | | - link: function(scope, elm, attrs, ctrl) { |
17 | | - // If the directive has a value, add the controller to the scope under that name |
18 | | - if (attrs.ngsfFullscreen && attrs.ngsfFullscreen !== '') { |
19 | | - var p = $parse(attrs.ngsfFullscreen); |
20 | | - p.assign(scope, ctrl); |
21 | | - } |
| 77 | + controller: NgsfFullscreenController, |
| 78 | + link: link |
| 79 | + }; |
22 | 80 |
|
23 | | - // Make this the current fullscreen element |
24 | | - ctrl.setFullScreenElement(elm[0]); |
| 81 | + function link (scope, elm, attrs, ctrl) { |
| 82 | + // If the directive has a value, add the controller to the scope under that name |
| 83 | + if (attrs.ngsfFullscreen && attrs.ngsfFullscreen !== '') { |
| 84 | + var p = $parse(attrs.ngsfFullscreen); |
| 85 | + p.assign(scope, ctrl); |
25 | 86 | } |
26 | | - }; |
27 | | - } |
28 | 87 |
|
| 88 | + // Make this the current fullscreen element |
| 89 | + ctrl.setFullScreenElement(elm[0]); |
| 90 | + } |
| 91 | + } |
29 | 92 |
|
30 | | - ngsfFullscreenController.$inject = ['$scope', '$document']; |
31 | | - function ngsfFullscreenController ($scope, $document) { |
| 93 | + NgsfFullscreenController.$inject = ['$scope', '$document']; |
| 94 | + function NgsfFullscreenController ($scope, $document) { |
32 | 95 | var ctrl = this; |
33 | 96 |
|
34 | 97 | ctrl.setFullScreenElement = setFullScreenElement; |
|
40 | 103 | ctrl.fullscreenEnabled = fullscreenEnabled; |
41 | 104 |
|
42 | 105 | function subscribeToEvents () { |
43 | | - if (ctrl.fullscreenEnabled()) { |
44 | | - var fullscreenchange = function () { |
45 | | - if (ctrl.isFullscreen()) { |
46 | | - angular.element(_elm).addClass('fullscreen'); |
47 | | - } else { |
48 | | - angular.element(_elm).removeClass('fullscreen'); |
49 | | - } |
50 | | - $scope.$emit('fullscreenchange'); |
51 | | - }; |
52 | | - |
53 | | - $document[0].addEventListener(screenfull.raw.fullscreenchange, fullscreenchange); |
54 | | - $scope.$on('$destroy', function() { |
55 | | - $document[0].removeEventListener(screenfull.raw.fullscreenchange, fullscreenchange); |
56 | | - }); |
57 | | - |
58 | | - } |
| 106 | + var fullscreenchange = function () { |
| 107 | + if (ctrl.isFullscreen()) { |
| 108 | + angular.element(_elm).addClass('fullscreen'); |
| 109 | + } else { |
| 110 | + angular.element(_elm).removeClass('fullscreen'); |
| 111 | + } |
| 112 | + $scope.$emit('fullscreenchange'); |
| 113 | + $scope.$apply(); |
| 114 | + }; |
| 115 | + |
| 116 | + $document[0].addEventListener(screenfull.raw.fullscreenchange, fullscreenchange); |
| 117 | + $scope.$on('$destroy', function() { |
| 118 | + $document[0].removeEventListener(screenfull.raw.fullscreenchange, fullscreenchange); |
| 119 | + }); |
| 120 | + } |
| 121 | + if (ctrl.fullscreenEnabled()) { |
| 122 | + subscribeToEvents(); |
59 | 123 | } |
60 | 124 |
|
| 125 | + //////////////////////////////////////// |
| 126 | + |
61 | 127 | var _elm; |
62 | 128 |
|
63 | 129 | function setFullScreenElement (elm) { |
|
85 | 151 | } |
86 | 152 | } |
87 | 153 |
|
88 | | - |
89 | 154 | function toggleFullscreen () { |
90 | 155 | if (ctrl.fullscreenEnabled()) { |
91 | 156 | var isFullscreen = screenfull.isFullscreen; |
|
100 | 165 | return false; |
101 | 166 | } |
102 | 167 |
|
103 | | - |
104 | 168 | function isFullscreen () { |
105 | 169 | if (ctrl.fullscreenEnabled()) { |
106 | 170 | return screenfull.isFullscreen; |
107 | 171 | } |
108 | 172 | return false; |
109 | 173 | } |
110 | 174 |
|
111 | | - |
112 | | - |
113 | 175 | function fullscreenEnabled () { |
114 | 176 | if (typeof screenfull !== 'undefined') { |
115 | 177 | return screenfull.enabled; |
116 | 178 | } |
117 | 179 | return false; |
118 | 180 | } |
119 | | - |
120 | | - subscribeToEvents(); |
121 | | - |
122 | 181 | } |
123 | | -})(angular); |
| 182 | +})(); |
124 | 183 |
|
125 | 184 |
|
126 | 185 | /* global angular */ |
127 | | -(function(angular) { |
128 | | - angular.module('angularScreenfull') |
129 | | - .directive('showIfFullscreenEnabled', showIfFullscreenEnabledDirective); |
| 186 | +(function() { |
| 187 | + 'use strict'; |
| 188 | + |
| 189 | + angular |
| 190 | + .module('angularScreenfull') |
| 191 | + .directive('showIfFullscreenEnabled', showIfFullscreenEnabledDirective); |
| 192 | + |
| 193 | + /** |
| 194 | + * @ngdoc directive |
| 195 | + * @name angularScreenfull.directive:showIfFullscreenEnabled |
| 196 | + * @restrict A |
| 197 | + * |
| 198 | + * @description |
| 199 | + * Shows or hides the element (using ng-hide) if the browser has fullscreen |
| 200 | + * capabilities. |
| 201 | + * |
| 202 | + */ |
130 | 203 |
|
131 | 204 | showIfFullscreenEnabledDirective.$inject = ['$animate']; |
132 | 205 |
|
133 | 206 | function showIfFullscreenEnabledDirective ($animate) { |
| 207 | + // Directive definition |
134 | 208 | return { |
135 | 209 | restrict: 'A', |
136 | 210 | require: '^ngsfFullscreen', |
137 | | - link: function(scope, elm, attrs,fullScreenCtrl) { |
138 | | - if (fullScreenCtrl.fullscreenEnabled()) { |
139 | | - $animate.removeClass(elm, 'ng-hide'); |
140 | | - } else { |
141 | | - $animate.addClass(elm, 'ng-hide'); |
142 | | - } |
143 | | - } |
| 211 | + link: link |
144 | 212 | }; |
145 | | - } |
146 | | -})(angular); |
147 | | - |
148 | 213 |
|
| 214 | + function link (scope, elm, attrs, fullScreenCtrl) { |
| 215 | + if (fullScreenCtrl.fullscreenEnabled()) { |
| 216 | + $animate.removeClass(elm, 'ng-hide'); |
| 217 | + } else { |
| 218 | + $animate.addClass(elm, 'ng-hide'); |
| 219 | + } |
| 220 | + } |
| 221 | + } |
| 222 | +})(); |
149 | 223 |
|
150 | 224 | /* global angular */ |
151 | | -(function(angular) { |
152 | | - angular.module('angularScreenfull') |
| 225 | +(function() { |
| 226 | + 'use strict'; |
| 227 | + |
| 228 | + angular |
| 229 | + .module('angularScreenfull') |
| 230 | + .directive('showIfFullscreen', showIfFullscreenDirective); |
| 231 | + |
| 232 | + /** |
| 233 | + * @ngdoc directive |
| 234 | + * @name angularScreenfull.directive:showIfFullscreen |
| 235 | + * @restrict A |
| 236 | + * |
| 237 | + * @description |
| 238 | + * Shows or hides the element (using ng-hide) if the closest |
| 239 | + * parent that has the ngsf-fullscreen directive is in fullscreen mode. |
| 240 | + * |
| 241 | + * By default the element shows itself if its fullscreen or hides otherwise, but you can |
| 242 | + * change this behaviour by passing false to the directive |
| 243 | + * |
| 244 | + * @param {boolean=} showIfFullscreen If false it inverts the show/hide behaviour. Defaults to true. |
| 245 | + * |
| 246 | + */ |
153 | 247 |
|
154 | | - .directive('showIfFullscreen', showIfFullscreenDirective); |
155 | 248 | showIfFullscreenDirective.$inject = ['$animate']; |
| 249 | + |
156 | 250 | function showIfFullscreenDirective ($animate) { |
| 251 | + // Directive definition |
157 | 252 | return { |
158 | 253 | restrict: 'A', |
159 | 254 | require: '^ngsfFullscreen', |
160 | | - link: function(scope, elm, attrs,fullScreenCtrl) { |
161 | | - var hideOrShow = function () { |
162 | | - |
163 | | - var show = fullScreenCtrl.isFullscreen(); |
164 | | - if (attrs.showIfFullscreen === 'false' || attrs.showIfFullscreen === false) { |
165 | | - show = !show; |
166 | | - } |
167 | | - |
168 | | - if ( show ) { |
169 | | - $animate.removeClass(elm, 'ng-hide'); |
170 | | - } else { |
171 | | - $animate.addClass(elm, 'ng-hide'); |
172 | | - } |
173 | | - }; |
174 | | - hideOrShow(); |
175 | | - var unwatch = fullScreenCtrl.onFullscreenChange(hideOrShow); |
176 | | - scope.$on('$destroy', unwatch); |
177 | | - } |
| 255 | + link: link |
178 | 256 | }; |
| 257 | + |
| 258 | + function link (scope, elm, attrs, fullScreenCtrl) { |
| 259 | + var hideOrShow = function () { |
| 260 | + |
| 261 | + var show = fullScreenCtrl.isFullscreen(); |
| 262 | + if (attrs.showIfFullscreen === 'false' || attrs.showIfFullscreen === false) { |
| 263 | + show = !show; |
| 264 | + } |
| 265 | + |
| 266 | + if (show) { |
| 267 | + $animate.removeClass(elm, 'ng-hide'); |
| 268 | + } else { |
| 269 | + $animate.addClass(elm, 'ng-hide'); |
| 270 | + } |
| 271 | + }; |
| 272 | + hideOrShow(); |
| 273 | + var unwatch = fullScreenCtrl.onFullscreenChange(hideOrShow); |
| 274 | + scope.$on('$destroy', unwatch); |
| 275 | + } |
179 | 276 | } |
180 | | -})(angular); |
| 277 | +})(); |
181 | 278 |
|
182 | 279 | /* global angular */ |
183 | | -(function(angular) { |
184 | | - angular.module('angularScreenfull') |
185 | | - .directive('ngsfToggleFullscreen', ngsfToggleFullscreenDirective); |
| 280 | +(function() { |
| 281 | + 'use strict'; |
| 282 | + |
| 283 | + angular |
| 284 | + .module('angularScreenfull') |
| 285 | + .directive('ngsfToggleFullscreen', ngsfToggleFullscreenDirective); |
| 286 | + |
| 287 | + /** |
| 288 | + * @ngdoc directive |
| 289 | + * @name angularScreenfull.directive:ngsfToggleFullscreen |
| 290 | + * @restrict A |
| 291 | + * |
| 292 | + * @description |
| 293 | + * Adds a click handler to the element that toggles the nearest ngsf-fullscreen element |
| 294 | + * |
| 295 | + */ |
186 | 296 |
|
187 | 297 | function ngsfToggleFullscreenDirective () { |
| 298 | + // Directive definition |
188 | 299 | return { |
189 | 300 | restrict: 'A', |
190 | 301 | require: '^ngsfFullscreen', |
191 | | - link: function(scope, elm, attrs, fullScreenCtrl) { |
192 | | - elm.on('click', function() { |
193 | | - fullScreenCtrl.toggleFullscreen(); |
194 | | - }); |
195 | | - } |
| 302 | + link: link |
196 | 303 | }; |
197 | | - } |
198 | | -})(angular); |
199 | 304 |
|
| 305 | + function link (scope, elm, attr, fullScreenCtrl) { |
| 306 | + elm.on('click', function() { |
| 307 | + fullScreenCtrl.toggleFullscreen(); |
| 308 | + }); |
| 309 | + } |
| 310 | + } |
| 311 | +})(); |
0 commit comments