1
- angular . module ( 'ionic.service.modal' , [ 'ionic.service.templateLoad' , 'ionic.service.platform' , 'ngAnimate ' ] )
1
+ angular . module ( 'ionic.service.modal' , [ 'ionic.service.templateLoad' , 'ionic.service.platform' , 'ionic.ui.modal ' ] )
2
2
3
3
4
- . factory ( '$ionicModal' , [ '$rootScope' , '$document' , '$compile' , '$animate' , '$q' , '$timeout' , '$ionicPlatform' , '$ionicTemplateLoader' , function ( $rootScope , $document , $compile , $animate , $q , $timeout , $ionicPlatform , $ionicTemplateLoader ) {
4
+ . factory ( '$ionicModal' , [ '$rootScope' , '$document' , '$compile' , '$timeout' , '$ionicPlatform' , '$ionicTemplateLoader' ,
5
+ function ( $rootScope , $document , $compile , $timeout , $ionicPlatform , $ionicTemplateLoader ) {
6
+
5
7
var ModalView = ionic . views . Modal . inherit ( {
6
8
initialize : function ( opts ) {
7
9
ionic . views . Modal . prototype . initialize . call ( this , opts ) ;
8
10
this . animation = opts . animation || 'slide-in-up' ;
9
11
} ,
12
+
10
13
// Show the modal
11
14
show : function ( ) {
12
15
var self = this ;
13
- var element = angular . element ( self . el ) ;
16
+ var modalEl = angular . element ( self . modalEl ) ;
14
17
15
- document . body . classList . add ( 'modal-open' ) ;
18
+ $ document[ 0 ] . body . classList . add ( 'modal-open' ) ;
16
19
17
20
self . _isShown = true ;
18
21
19
- if ( ! element . parent ( ) . length ) {
20
- self . el . classList . add ( self . animation ) ;
22
+ if ( ! self . el . parentElement ) {
23
+ modalEl . addClass ( self . animation ) ;
21
24
$document [ 0 ] . body . appendChild ( self . el ) ;
22
25
}
23
26
24
- element . addClass ( 'ng-enter active' ) ;
25
- element . removeClass ( 'ng-leave ng-leave-active' ) ;
27
+ modalEl . addClass ( 'ng-enter active' )
28
+ . removeClass ( 'ng-leave ng-leave-active' ) ;
26
29
27
30
$timeout ( function ( ) {
28
- element . addClass ( 'ng-enter-active' ) ;
31
+ modalEl . addClass ( 'ng-enter-active' ) ;
29
32
self . scope . $parent && self . scope . $parent . $broadcast ( 'modal.shown' ) ;
30
33
} , 20 ) ;
31
34
@@ -34,25 +37,26 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
34
37
} , 200 ) ;
35
38
36
39
} ,
40
+
37
41
// Hide the modal
38
42
hide : function ( ) {
39
43
this . _isShown = false ;
40
- var element = angular . element ( this . el ) ;
44
+ var modalEl = angular . element ( this . modalEl ) ;
41
45
42
- element . addClass ( 'ng-leave' ) ;
46
+ modalEl . addClass ( 'ng-leave' ) ;
43
47
44
48
$timeout ( function ( ) {
45
- element . addClass ( 'ng-leave-active' ) ;
46
- element . removeClass ( 'ng-enter ng-enter-active active' ) ;
49
+ modalEl . addClass ( 'ng-leave-active' )
50
+ . removeClass ( 'ng-enter ng-enter-active active' ) ;
47
51
} , 20 ) ;
48
52
49
53
$timeout ( function ( ) {
50
- document . body . classList . remove ( 'modal-open' ) ;
51
- } , 400 ) ;
54
+ $ document[ 0 ] . body . classList . remove ( 'modal-open' ) ;
55
+ } , 350 ) ;
52
56
53
57
ionic . views . Modal . prototype . hide . call ( this ) ;
54
58
55
- this . scope . $parent . $broadcast ( 'modal.hidden' ) ;
59
+ this . scope . $parent && this . scope . $parent . $broadcast ( 'modal.hidden' ) ;
56
60
57
61
this . _deregisterBackButton && this . _deregisterBackButton ( ) ;
58
62
} ,
@@ -61,12 +65,12 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
61
65
remove : function ( ) {
62
66
var self = this ;
63
67
self . hide ( ) ;
64
- self . scope . $parent . $broadcast ( 'modal.removed' ) ;
68
+ self . scope . $parent && self . scope . $parent . $broadcast ( 'modal.removed' ) ;
65
69
66
70
$timeout ( function ( ) {
67
71
self . scope . $destroy ( ) ;
68
72
self . el && self . el . parentElement && self . el . parentElement . removeChild ( self . el ) ;
69
- } , 1000 ) ;
73
+ } , 750 ) ;
70
74
} ,
71
75
72
76
isShown : function ( ) {
@@ -79,9 +83,10 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
79
83
var scope = options . scope && options . scope . $new ( ) || $rootScope . $new ( true ) ;
80
84
81
85
// Compile the template
82
- var element = $compile ( templateString ) ( scope ) ;
86
+ var element = $compile ( '<ion-modal>' + templateString + '</ion-modal>' ) ( scope ) ;
83
87
84
88
options . el = element [ 0 ] ;
89
+ options . modalEl = options . el . querySelector ( '.modal' ) ;
85
90
var modal = new ModalView ( options ) ;
86
91
87
92
modal . scope = scope ;
0 commit comments