mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
15
js/ext/angular/src/service/ionicModal.js
vendored
15
js/ext/angular/src/service/ionicModal.js
vendored
@@ -9,13 +9,16 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
|
||||
},
|
||||
// Show the modal
|
||||
show: function() {
|
||||
var _this = this;
|
||||
var self = this;
|
||||
var element = angular.element(this.el);
|
||||
|
||||
self._isShown = true;
|
||||
|
||||
if(!element.parent().length) {
|
||||
element.addClass(this.animation);
|
||||
$animate.enter(element, angular.element($document[0].body), null, function() {
|
||||
});
|
||||
ionic.views.Modal.prototype.show.call(_this);
|
||||
ionic.views.Modal.prototype.show.call(self);
|
||||
} else {
|
||||
$animate.addClass(element, this.animation, function() {
|
||||
});
|
||||
@@ -23,7 +26,7 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
|
||||
|
||||
if(!this.didInitEvents) {
|
||||
var onHardwareBackButton = function() {
|
||||
_this.hide();
|
||||
self.hide();
|
||||
};
|
||||
|
||||
self.scope.$on('$destroy', function() {
|
||||
@@ -41,6 +44,7 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
|
||||
},
|
||||
// Hide the modal
|
||||
hide: function() {
|
||||
this._isShown = false;
|
||||
var element = angular.element(this.el);
|
||||
$animate.removeClass(element, this.animation);
|
||||
|
||||
@@ -53,10 +57,15 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad', 'ionic.serv
|
||||
remove: function() {
|
||||
var self = this,
|
||||
element = angular.element(this.el);
|
||||
this._isShown = false;
|
||||
$animate.leave(angular.element(this.el), function() {
|
||||
self.scope.$parent.$broadcast('modal.removed', self);
|
||||
self.scope.$destroy();
|
||||
});
|
||||
},
|
||||
|
||||
isShown: function() {
|
||||
return !!this._isShown;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -32,13 +32,36 @@ describe('Ionic Modal', function() {
|
||||
});
|
||||
|
||||
timeout.flush();
|
||||
|
||||
waitsFor(function() {
|
||||
return done;
|
||||
}, "Modal should be loaded", 100);
|
||||
|
||||
expect(done).toBe(true);
|
||||
});
|
||||
|
||||
it('should set isShown on show/hide', function() {
|
||||
var m = modal.fromTemplate('<div class="modal">hello</div>');
|
||||
expect(m.isShown()).toBe(false);
|
||||
m.show();
|
||||
expect(m.isShown()).toBe(true);
|
||||
m.hide();
|
||||
expect(m.isShown()).toBe(false);
|
||||
});
|
||||
|
||||
it('should set isShown on remove', function() {
|
||||
var m = modal.fromTemplate('<div class="modal">hello</div>');
|
||||
expect(m.isShown()).toBe(false);
|
||||
m.show();
|
||||
expect(m.isShown()).toBe(true);
|
||||
m.remove();
|
||||
expect(m.isShown()).toBe(false);
|
||||
});
|
||||
|
||||
it('should animate leave and destroy scope on remove', inject(function($animate) {
|
||||
var m = modal.fromTemplate('<div class="modal"></div>');
|
||||
spyOn($animate, 'leave').andCallFake(function(el, cb) { cb(); });
|
||||
spyOn(m.scope, '$destroy');
|
||||
m.remove();
|
||||
expect($animate.leave).toHaveBeenCalled();
|
||||
expect(m.scope.$destroy).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('Should close on hardware back button', function() {
|
||||
var template = '<div class="modal"></div>';
|
||||
var modalInstance = modal.fromTemplate(template);
|
||||
|
||||
Reference in New Issue
Block a user