18
18
* For example, if `retain` is called three times, the backdrop will be shown until `release`
19
19
* is called three times.
20
20
*
21
+ * **Notes:**
22
+ * - The backdrop service will broadcast 'backdrop.shown' and 'backdrop.hidden' events from the root scope,
23
+ * this is useful for alerting native components not in html.
24
+ *
21
25
* @usage
22
26
*
23
27
* ```js
24
- * function MyController($scope, $ionicBackdrop, $timeout) {
28
+ * function MyController($scope, $ionicBackdrop, $timeout, $rootScope ) {
25
29
* //Show a backdrop for one second
26
30
* $scope.action = function() {
27
31
* $ionicBackdrop.retain();
28
32
* $timeout(function() {
29
33
* $ionicBackdrop.release();
30
34
* }, 1000);
31
35
* };
36
+ *
37
+ * // Execute action on backdrop disappearing
38
+ * $scope.$on('backdrop.hidden', function() {
39
+ * // Execute action
40
+ * });
41
+ *
42
+ * // Execute action on backdrop appearing
43
+ * $scope.$on('backdrop.shown', function() {
44
+ * // Execute action
45
+ * });
46
+ *
32
47
* }
33
48
* ```
34
49
*/
35
50
IonicModule
36
51
. factory ( '$ionicBackdrop' , [
37
- '$document' , '$timeout' , '$$rAF' ,
38
- function ( $document , $timeout , $$rAF ) {
52
+ '$document' , '$timeout' , '$$rAF' , '$rootScope' ,
53
+ function ( $document , $timeout , $$rAF , $rootScope ) {
39
54
40
55
var el = jqLite ( '<div class="backdrop">' ) ;
41
56
var backdropHolds = 0 ;
@@ -67,6 +82,7 @@ function($document, $timeout, $$rAF) {
67
82
backdropHolds ++ ;
68
83
if ( backdropHolds === 1 ) {
69
84
el . addClass ( 'visible' ) ;
85
+ $rootScope . $broadcast ( 'backdrop.shown' ) ;
70
86
$$rAF ( function ( ) {
71
87
// If we're still at >0 backdropHolds after async...
72
88
if ( backdropHolds >= 1 ) el . addClass ( 'active' ) ;
@@ -76,6 +92,7 @@ function($document, $timeout, $$rAF) {
76
92
function release ( ) {
77
93
if ( backdropHolds === 1 ) {
78
94
el . removeClass ( 'active' ) ;
95
+ $rootScope . $broadcast ( 'backdrop.hidden' ) ;
79
96
$timeout ( function ( ) {
80
97
// If we're still at 0 backdropHolds after async...
81
98
if ( backdropHolds === 0 ) el . removeClass ( 'visible' ) ;
0 commit comments