|
| 1 | +/* global angular */ |
| 2 | +(function(angular) { |
| 3 | + angular.module('angularScreenfull', []); |
| 4 | +})(angular); |
| 5 | +/* global angular, screenfull */ |
| 6 | +(function(angular) { |
| 7 | + angular.module('angularScreenfull') |
| 8 | + .directive('ngsfFullscreen',ngsfFullscreenDirective); |
| 9 | + |
| 10 | + ngsfFullscreenDirective.$inject = ['$parse']; |
| 11 | + function ngsfFullscreenDirective ($parse) { |
| 12 | + return { |
| 13 | + restrict: 'A', |
| 14 | + 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 | + } |
| 22 | + |
| 23 | + // Make this the current fullscreen element |
| 24 | + ctrl.setFullScreenElement(elm[0]); |
| 25 | + } |
| 26 | + }; |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + ngsfFullscreenController.$inject = ['$scope', '$document']; |
| 31 | + function ngsfFullscreenController ($scope, $document) { |
| 32 | + var ctrl = this; |
| 33 | + |
| 34 | + ctrl.setFullScreenElement = setFullScreenElement; |
| 35 | + ctrl.onFullscreenChange = onFullscreenChange; |
| 36 | + ctrl.requestFullscreen = requestFullscreen; |
| 37 | + ctrl.removeFullscreen = removeFullscreen; |
| 38 | + ctrl.toggleFullscreen = toggleFullscreen; |
| 39 | + ctrl.isFullscreen = isFullscreen; |
| 40 | + ctrl.fullscreenEnabled = fullscreenEnabled; |
| 41 | + |
| 42 | + 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 | + } |
| 59 | + } |
| 60 | + |
| 61 | + var _elm; |
| 62 | + |
| 63 | + function setFullScreenElement (elm) { |
| 64 | + _elm = elm; |
| 65 | + } |
| 66 | + |
| 67 | + function onFullscreenChange (handler) { |
| 68 | + return $scope.$on('fullscreenchange', handler); |
| 69 | + } |
| 70 | + |
| 71 | + function requestFullscreen () { |
| 72 | + if (ctrl.fullscreenEnabled()) { |
| 73 | + screenfull.request(_elm); |
| 74 | + $scope.$emit('fullscreenEnabled'); |
| 75 | + return true; |
| 76 | + } |
| 77 | + return false; |
| 78 | + } |
| 79 | + |
| 80 | + function removeFullscreen () { |
| 81 | + if (ctrl.fullscreenEnabled()) { |
| 82 | + if (ctrl.isFullscreen()) { |
| 83 | + ctrl.toggleFullscreen(); |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + function toggleFullscreen () { |
| 90 | + if (ctrl.fullscreenEnabled()) { |
| 91 | + var isFullscreen = screenfull.isFullscreen; |
| 92 | + screenfull.toggle(_elm); |
| 93 | + if (isFullscreen) { |
| 94 | + $scope.$emit('fullscreenDisabled'); |
| 95 | + } else { |
| 96 | + $scope.$emit('fullscreenEnabled'); |
| 97 | + } |
| 98 | + return true; |
| 99 | + } |
| 100 | + return false; |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + function isFullscreen () { |
| 105 | + if (ctrl.fullscreenEnabled()) { |
| 106 | + return screenfull.isFullscreen; |
| 107 | + } |
| 108 | + return false; |
| 109 | + } |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + function fullscreenEnabled () { |
| 114 | + if (typeof screenfull !== 'undefined') { |
| 115 | + return screenfull.enabled; |
| 116 | + } |
| 117 | + return false; |
| 118 | + } |
| 119 | + |
| 120 | + subscribeToEvents(); |
| 121 | + |
| 122 | + } |
| 123 | +})(angular); |
| 124 | + |
| 125 | + |
| 126 | +/* global angular */ |
| 127 | +(function(angular) { |
| 128 | + angular.module('angularScreenfull') |
| 129 | + .directive('showIfFullscreenEnabled', showIfFullscreenEnabledDirective); |
| 130 | + |
| 131 | + showIfFullscreenEnabledDirective.$inject = ['$animate']; |
| 132 | + |
| 133 | + function showIfFullscreenEnabledDirective ($animate) { |
| 134 | + return { |
| 135 | + restrict: 'A', |
| 136 | + 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 | + } |
| 144 | + }; |
| 145 | + } |
| 146 | +})(angular); |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | +/* global angular */ |
| 151 | +(function(angular) { |
| 152 | + angular.module('angularScreenfull') |
| 153 | + |
| 154 | + .directive('showIfFullscreen', showIfFullscreenDirective); |
| 155 | + showIfFullscreenDirective.$inject = ['$animate']; |
| 156 | + function showIfFullscreenDirective ($animate) { |
| 157 | + return { |
| 158 | + restrict: 'A', |
| 159 | + 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 | + } |
| 178 | + }; |
| 179 | + } |
| 180 | +})(angular); |
| 181 | + |
| 182 | +/* global angular */ |
| 183 | +(function(angular) { |
| 184 | + angular.module('angularScreenfull') |
| 185 | + .directive('ngsfToggleFullscreen', ngsfToggleFullscreenDirective); |
| 186 | + |
| 187 | + function ngsfToggleFullscreenDirective () { |
| 188 | + return { |
| 189 | + restrict: 'A', |
| 190 | + require: '^ngsfFullscreen', |
| 191 | + link: function(scope, elm, attrs, fullScreenCtrl) { |
| 192 | + elm.on('click', function() { |
| 193 | + fullScreenCtrl.toggleFullscreen(); |
| 194 | + }); |
| 195 | + } |
| 196 | + }; |
| 197 | + } |
| 198 | +})(angular); |
| 199 | + |
0 commit comments