@@ -281,84 +281,79 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
281
281
buttons : [ ]
282
282
} , options || { } ) ;
283
283
284
- var popupPromise = $ionicTemplateLoader . compile ( {
285
- template : POPUP_TPL ,
286
- scope : options . scope && options . scope . $new ( ) ,
287
- appendTo : $ionicBody . get ( )
284
+ var self = { } ;
285
+ self . scope = ( options . scope || $rootScope ) . $new ( ) ;
286
+ self . element = jqLite ( POPUP_TPL ) ;
287
+ self . responseDeferred = $q . defer ( ) ;
288
+
289
+ $ionicBody . get ( ) . appendChild ( self . element [ 0 ] ) ;
290
+ $compile ( self . element ) ( self . scope ) ;
291
+
292
+ extend ( self . scope , {
293
+ title : options . title ,
294
+ buttons : options . buttons ,
295
+ subTitle : options . subTitle ,
296
+ cssClass : options . cssClass ,
297
+ $buttonTapped : function ( button , event ) {
298
+ var result = ( button . onTap || noop ) ( event ) ;
299
+ event = event . originalEvent || event ; //jquery events
300
+
301
+ if ( ! event . defaultPrevented ) {
302
+ self . responseDeferred . resolve ( result ) ;
303
+ }
304
+ }
288
305
} ) ;
289
- var contentPromise = options . templateUrl ?
290
- $ionicTemplateLoader . load ( options . templateUrl ) :
291
- $q . when ( options . template || options . content || '' ) ;
292
306
293
- return $q . all ( [ popupPromise , contentPromise ] ) . then ( function ( results ) {
294
- var self = results [ 0 ] ;
295
- var content = results [ 1 ] ;
296
- var responseDeferred = $q . defer ( ) ;
297
-
298
- self . responseDeferred = responseDeferred ;
299
-
300
- //Can't ng-bind-html for popup-body because it can be insecure html
301
- //(eg an input in case of prompt)
302
- var body = jqLite ( self . element [ 0 ] . querySelector ( '.popup-body' ) ) ;
303
- if ( content ) {
304
- body . html ( content ) ;
305
- $compile ( body . contents ( ) ) ( self . scope ) ;
307
+ $q . when (
308
+ options . templateUrl ?
309
+ $ionicTemplateLoader . load ( options . templateUrl ) :
310
+ ( options . template || options . content || '' )
311
+ ) . then ( function ( template ) {
312
+ var popupBody = jqLite ( self . element [ 0 ] . querySelector ( '.popup-body' ) ) ;
313
+ if ( template ) {
314
+ popupBody . html ( template ) ;
315
+ $compile ( popupBody . contents ( ) ) ( self . scope ) ;
306
316
} else {
307
- body . remove ( ) ;
317
+ popupBody . remove ( ) ;
308
318
}
319
+ } ) ;
309
320
310
- extend ( self . scope , {
311
- title : options . title ,
312
- buttons : options . buttons ,
313
- subTitle : options . subTitle ,
314
- cssClass : options . cssClass ,
315
- $buttonTapped : function ( button , event ) {
316
- var result = ( button . onTap || noop ) ( event ) ;
317
- event = event . originalEvent || event ; //jquery events
318
-
319
- if ( ! event . defaultPrevented ) {
320
- responseDeferred . resolve ( result ) ;
321
- }
322
- }
323
- } ) ;
324
-
325
- self . show = function ( ) {
326
- if ( self . isShown || self . removed ) return ;
321
+ self . show = function ( ) {
322
+ if ( self . isShown || self . removed ) return ;
327
323
328
- self . isShown = true ;
329
- ionic . requestAnimationFrame ( function ( ) {
330
- //if hidden while waiting for raf, don't show
331
- if ( ! self . isShown ) return ;
324
+ self . isShown = true ;
325
+ ionic . requestAnimationFrame ( function ( ) {
326
+ //if hidden while waiting for raf, don't show
327
+ if ( ! self . isShown ) return ;
332
328
333
- self . element . removeClass ( 'popup-hidden' ) ;
334
- self . element . addClass ( 'popup-showing active' ) ;
335
- focusInput ( self . element ) ;
336
- } ) ;
337
- } ;
329
+ self . element . removeClass ( 'popup-hidden' ) ;
330
+ self . element . addClass ( 'popup-showing active' ) ;
331
+ focusInput ( self . element ) ;
332
+ } ) ;
333
+ } ;
338
334
339
- self . hide = function ( callback ) {
340
- callback = callback || noop ;
341
- if ( ! self . isShown ) return callback ( ) ;
335
+ self . hide = function ( callback ) {
336
+ callback = callback || noop ;
337
+ if ( ! self . isShown ) return callback ( ) ;
342
338
343
- self . isShown = false ;
344
- self . element . removeClass ( 'active' ) ;
345
- self . element . addClass ( 'popup-hidden' ) ;
346
- $timeout ( callback , 250 ) ;
347
- } ;
339
+ self . isShown = false ;
340
+ self . element . removeClass ( 'active' ) ;
341
+ self . element . addClass ( 'popup-hidden' ) ;
342
+ $timeout ( callback , 250 , false ) ;
343
+ } ;
348
344
349
- self . remove = function ( ) {
350
- if ( self . removed ) return ;
345
+ self . remove = function ( ) {
346
+ if ( self . removed ) return ;
351
347
352
- self . hide ( function ( ) {
353
- self . element . remove ( ) ;
354
- self . scope . $destroy ( ) ;
355
- } ) ;
348
+ self . hide ( function ( ) {
349
+ self . element . remove ( ) ;
350
+ self . scope . $destroy ( ) ;
351
+ } ) ;
356
352
357
- self . removed = true ;
358
- } ;
353
+ self . removed = true ;
354
+ } ;
359
355
360
- return self ;
361
- } ) ;
356
+ return self ;
362
357
}
363
358
364
359
function onHardwareBackButton ( ) {
@@ -367,69 +362,62 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB
367
362
}
368
363
369
364
function showPopup ( options ) {
370
- var resultDeferred ;
371
- var popupPromise = $ionicPopup . _createPopup ( options ) ;
365
+ var popup = $ionicPopup . _createPopup ( options ) ;
366
+ var showDelay = 0 ;
372
367
373
368
if ( popupStack . length > 0 ) {
374
369
popupStack [ popupStack . length - 1 ] . hide ( ) ;
375
- resultDeferred = $timeout ( doShowPopup , config . stackPushDelay ) ;
370
+ showDelay = config . stackPushDelay ;
376
371
} else {
377
372
//Add popup-open & backdrop if this is first popup
378
373
$ionicBody . addClass ( 'popup-open' ) ;
379
- console . log ( "RETAIN" ) ;
380
374
$ionicBackdrop . retain ( ) ;
381
375
//only show the backdrop on the first popup
382
376
$ionicPopup . _backButtonActionDone = $ionicPlatform . registerBackButtonAction (
383
377
onHardwareBackButton ,
384
378
IONIC_BACK_PRIORITY . popup
385
379
) ;
386
- resultDeferred = doShowPopup ( ) ;
387
380
}
388
381
389
- resultDeferred . close = function popupClose ( result ) {
390
- popupPromise . then ( function ( popup ) {
391
- if ( ! popup . removed ) popup . responseDeferred . resolve ( result ) ;
392
- } ) ;
382
+ // Expose a 'close' method on the returned promise
383
+ popup . responseDeferred . promise . close = function popupClose ( result ) {
384
+ if ( ! popup . removed ) popup . responseDeferred . resolve ( result ) ;
393
385
} ;
386
+ //DEPRECATED: notify the promise with an object with a close method
387
+ popup . responseDeferred . notify ( { close : popup . responseDeferred . close } ) ;
394
388
395
- return resultDeferred ;
389
+ doShow ( ) ;
396
390
397
- function doShowPopup ( ) {
398
- return popupPromise . then ( function ( popup ) {
399
- popupStack . push ( popup ) ;
400
- popup . show ( ) ;
391
+ return popup . responseDeferred . promise ;
401
392
402
- //DEPRECATED: notify the promise with an object with a close method
403
- popup . responseDeferred . notify ( {
404
- close : resultDeferred . close
405
- } ) ;
393
+ function doShow ( ) {
394
+ popupStack . push ( popup ) ;
395
+ $timeout ( popup . show , showDelay , false ) ;
406
396
407
- return popup . responseDeferred . promise . then ( function ( result ) {
408
- var index = popupStack . indexOf ( popup ) ;
409
- if ( index !== - 1 ) {
410
- popupStack . splice ( index , 1 ) ;
411
- }
412
- popup . remove ( ) ;
413
- $ionicBackdrop . release ( ) ;
414
-
415
- if ( popupStack . length > 0 ) {
416
- popupStack [ popupStack . length - 1 ] . show ( ) ;
417
- } else {
418
- //Remove popup-open & backdrop if this is last popup
419
- $timeout ( function ( ) {
420
- // wait to remove this due to a 300ms delay native
421
- // click which would trigging whatever was underneath this
422
- if ( ! popupStack . length ) {
423
- $ionicBody . removeClass ( 'popup-open' ) ;
424
- }
425
- } , 400 , false ) ;
397
+ popup . responseDeferred . promise . then ( function ( result ) {
398
+ var index = popupStack . indexOf ( popup ) ;
399
+ if ( index !== - 1 ) {
400
+ popupStack . splice ( index , 1 ) ;
401
+ }
426
402
427
- ( $ionicPopup . _backButtonActionDone || noop ) ( ) ;
428
- }
403
+ if ( popupStack . length > 0 ) {
404
+ popupStack [ popupStack . length - 1 ] . show ( ) ;
405
+ } else {
406
+ $ionicBackdrop . release ( ) ;
407
+ //Remove popup-open & backdrop if this is last popup
408
+ $timeout ( function ( ) {
409
+ // wait to remove this due to a 300ms delay native
410
+ // click which would trigging whatever was underneath this
411
+ if ( ! popupStack . length ) {
412
+ $ionicBody . removeClass ( 'popup-open' ) ;
413
+ }
414
+ } , 400 , false ) ;
415
+ ( $ionicPopup . _backButtonActionDone || noop ) ( ) ;
416
+ }
429
417
430
- return result ;
431
- } ) ;
418
+ popup . remove ( ) ;
432
419
420
+ return result ;
433
421
} ) ;
434
422
435
423
}
0 commit comments