@@ -119,6 +119,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
119
119
stackPushDelay : 75
120
120
} ;
121
121
var popupStack = [ ] ;
122
+
122
123
var $ionicPopup = {
123
124
/**
124
125
* @ngdoc method
@@ -288,8 +289,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
288
289
$ionicTemplateLoader . load ( options . templateUrl ) :
289
290
$q . when ( options . template || options . content || '' ) ;
290
291
291
- return $q . all ( [ popupPromise , contentPromise ] )
292
- . then ( function ( results ) {
292
+ return $q . all ( [ popupPromise , contentPromise ] ) . then ( function ( results ) {
293
293
var self = results [ 0 ] ;
294
294
var content = results [ 1 ] ;
295
295
var responseDeferred = $q . defer ( ) ;
@@ -322,7 +322,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
322
322
} ) ;
323
323
324
324
self . show = function ( ) {
325
- if ( self . isShown ) return ;
325
+ if ( self . isShown || self . removed ) return ;
326
326
327
327
self . isShown = true ;
328
328
ionic . requestAnimationFrame ( function ( ) {
@@ -334,6 +334,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
334
334
focusInput ( self . element ) ;
335
335
} ) ;
336
336
} ;
337
+
337
338
self . hide = function ( callback ) {
338
339
callback = callback || noop ;
339
340
if ( ! self . isShown ) return callback ( ) ;
@@ -343,6 +344,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
343
344
self . element . addClass ( 'popup-hidden' ) ;
344
345
$timeout ( callback , 250 ) ;
345
346
} ;
347
+
346
348
self . remove = function ( ) {
347
349
if ( self . removed ) return ;
348
350
@@ -359,74 +361,79 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
359
361
}
360
362
361
363
function onHardwareBackButton ( e ) {
362
- popupStack [ 0 ] && popupStack [ 0 ] . responseDeferred . resolve ( ) ;
364
+ var last = popupStack [ popupStack . length - 1 ] ;
365
+ last && last . responseDeferred . resolve ( ) ;
363
366
}
364
367
365
368
function showPopup ( options ) {
369
+ var resultDeferred ;
366
370
var popupPromise = $ionicPopup . _createPopup ( options ) ;
367
- var previousPopup = popupStack [ 0 ] ;
368
371
369
- if ( previousPopup ) {
370
- previousPopup . hide ( ) ;
372
+ if ( popupStack . length > 0 ) {
373
+ popupStack [ popupStack . length - 1 ] . hide ( ) ;
374
+ resultDeferred = $timeout ( doShowPopup , config . stackPushDelay ) ;
375
+ } else {
376
+ //Add popup-open & backdrop if this is first popup
377
+ $ionicBody . addClass ( 'popup-open' ) ;
378
+ $ionicBackdrop . retain ( ) ;
379
+ //only show the backdrop on the first popup
380
+ $ionicPopup . _backButtonActionDone = $ionicPlatform . registerBackButtonAction (
381
+ onHardwareBackButton ,
382
+ PLATFORM_BACK_BUTTON_PRIORITY_POPUP
383
+ ) ;
384
+ resultDeferred = doShowPopup ( ) ;
371
385
}
372
386
373
- var resultPromise = $timeout ( noop , previousPopup ? config . stackPushDelay : 0 )
374
- . then ( function ( ) { return popupPromise ; } )
375
- . then ( function ( popup ) {
376
- if ( ! previousPopup ) {
377
- //Add popup-open & backdrop if this is first popup
378
- $ionicBody . addClass ( 'popup-open' ) ;
379
- $ionicBackdrop . retain ( ) ;
380
- //only show the backdrop on the first popup
381
- $ionicPopup . _backButtonActionDone = $ionicPlatform . registerBackButtonAction (
382
- onHardwareBackButton ,
383
- PLATFORM_BACK_BUTTON_PRIORITY_POPUP
384
- ) ;
385
- }
386
- popupStack . unshift ( popup ) ;
387
- popup . show ( ) ;
388
-
389
- //DEPRECATED: notify the promise with an object with a close method
390
- popup . responseDeferred . notify ( {
391
- close : resultPromise . close
387
+ resultDeferred . close = function popupClose ( result ) {
388
+ popupPromise . then ( function ( popup ) {
389
+ if ( ! popup . removed ) popup . responseDeferred . resolve ( result ) ;
392
390
} ) ;
391
+ } ;
393
392
394
- return popup . responseDeferred . promise . then ( function ( result ) {
395
- var index = popupStack . indexOf ( popup ) ;
396
- if ( index !== - 1 ) {
397
- popupStack . splice ( index , 1 ) ;
398
- }
399
- popup . remove ( ) ;
400
-
401
- var previousPopup = popupStack [ 0 ] ;
402
- if ( previousPopup ) {
403
- previousPopup . show ( ) ;
404
- } else {
405
- //Remove popup-open & backdrop if this is last popup
406
- $timeout ( function ( ) {
407
- // wait to remove this due to a 300ms delay native
408
- // click which would trigging whatever was underneath this
409
- $ionicBody . removeClass ( 'popup-open' ) ;
410
- } , 400 ) ;
411
- $timeout ( function ( ) {
412
- $ionicBackdrop . release ( ) ;
413
- } , config . stackPushDelay || 0 ) ;
414
- ( $ionicPopup . _backButtonActionDone || noop ) ( ) ;
415
- }
416
- return result ;
417
- } ) ;
418
- } ) ;
393
+ return resultDeferred ;
394
+
395
+ function doShowPopup ( ) {
396
+ return popupPromise . then ( function ( popup ) {
397
+ popupStack . push ( popup ) ;
398
+ popup . show ( ) ;
399
+
400
+ //DEPRECATED: notify the promise with an object with a close method
401
+ popup . responseDeferred . notify ( {
402
+ close : resultDeferred . close
403
+ } ) ;
404
+
405
+ return popup . responseDeferred . promise . then ( function ( result ) {
406
+ var index = popupStack . indexOf ( popup ) ;
407
+ if ( index !== - 1 ) {
408
+ popupStack . splice ( index , 1 ) ;
409
+ }
410
+ popup . remove ( ) ;
411
+
412
+ if ( popupStack . length > 0 ) {
413
+ popupStack [ popupStack . length - 1 ] . show ( ) ;
414
+ } else {
415
+ //Remove popup-open & backdrop if this is last popup
416
+ $timeout ( function ( ) {
417
+ // wait to remove this due to a 300ms delay native
418
+ // click which would trigging whatever was underneath this
419
+ if ( ! popupStack . length ) {
420
+ $ionicBody . removeClass ( 'popup-open' ) ;
421
+ }
422
+ } , 400 , false ) ;
423
+ $timeout ( function ( ) {
424
+ if ( ! popupStack . length ) $ionicBackdrop . release ( ) ;
425
+ } , config . stackPushDelay || 0 , false ) ;
426
+
427
+ ( $ionicPopup . _backButtonActionDone || noop ) ( ) ;
428
+ }
429
+
430
+ return result ;
431
+ } ) ;
419
432
420
- function close ( result ) {
421
- popupPromise . then ( function ( popup ) {
422
- if ( ! popup . removed ) {
423
- popup . responseDeferred . resolve ( result ) ;
424
- }
425
433
} ) ;
434
+
426
435
}
427
- resultPromise . close = close ;
428
436
429
- return resultPromise ;
430
437
}
431
438
432
439
function focusInput ( element ) {
0 commit comments