1818 * For example, if `retain` is called three times, the backdrop will be shown until `release`
1919 * is called three times.
2020 *
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+ *
2125 * @usage
2226 *
2327 * ```js
24- * function MyController($scope, $ionicBackdrop, $timeout) {
28+ * function MyController($scope, $ionicBackdrop, $timeout, $rootScope ) {
2529 * //Show a backdrop for one second
2630 * $scope.action = function() {
2731 * $ionicBackdrop.retain();
2832 * $timeout(function() {
2933 * $ionicBackdrop.release();
3034 * }, 1000);
3135 * };
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+ *
3247 * }
3348 * ```
3449 */
3550IonicModule
3651. factory ( '$ionicBackdrop' , [
37- '$document' , '$timeout' , '$$rAF' ,
38- function ( $document , $timeout , $$rAF ) {
52+ '$document' , '$timeout' , '$$rAF' , '$rootScope' ,
53+ function ( $document , $timeout , $$rAF , $rootScope ) {
3954
4055 var el = jqLite ( '<div class="backdrop">' ) ;
4156 var backdropHolds = 0 ;
@@ -67,6 +82,7 @@ function($document, $timeout, $$rAF) {
6782 backdropHolds ++ ;
6883 if ( backdropHolds === 1 ) {
6984 el . addClass ( 'visible' ) ;
85+ $rootScope . $broadcast ( 'backdrop.shown' ) ;
7086 $$rAF ( function ( ) {
7187 // If we're still at >0 backdropHolds after async...
7288 if ( backdropHolds >= 1 ) el . addClass ( 'active' ) ;
@@ -76,6 +92,7 @@ function($document, $timeout, $$rAF) {
7692 function release ( ) {
7793 if ( backdropHolds === 1 ) {
7894 el . removeClass ( 'active' ) ;
95+ $rootScope . $broadcast ( 'backdrop.hidden' ) ;
7996 $timeout ( function ( ) {
8097 // If we're still at 0 backdropHolds after async...
8198 if ( backdropHolds === 0 ) el . removeClass ( 'visible' ) ;
0 commit comments