This commit is contained in:
Max Lynch
2013-11-06 16:38:12 -06:00
parent 0f515802e5
commit e8f4eeeac8
13 changed files with 372 additions and 6591 deletions

View File

@ -1,7 +1,35 @@
angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
.factory('Modal', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
.factory('Modal', ['$rootScope', '$document', '$compile', '$animate', 'TemplateLoader', function($rootScope, $document, $compile, $animate, TemplateLoader) {
var ModalView = ionic.views.Modal.inherit({
initialize: function(opts) {
ionic.views.Modal.prototype.initialize.call(this, opts);
this.animation = opts.animation;
},
// Show the modal
show: function() {
var element = angular.element(this.el);
if(!element.parent().length) {
$animate.enter(element, angular.element($document[0].body));
}
$animate.addClass(element, this.animation);
},
// Hide the modal
hide: function() {
var element = angular.element(this.el);
$animate.removeClass(element, this.animation);
},
// Remove and destroy the modal scope
remove: function() {
var element = angular.element(this.el);
$animate.leave(angular.element(this.el), function() {
scope.$destroy();
});
}
});
return {
/**
* Load a modal with the given template string.
@ -9,32 +37,33 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
* A new isolated scope will be created for the
* modal and the new element will be appended into the body.
*/
fromTemplate: function(templateString, $scope) {
// Create a new isolated scope for the modal
var scope = $scope && $scope.$new() || $rootScope.$new(true);
fromTemplate: function(templateString, options) {
options = options || {};
// Create a new scope for the modal
var scope = options.scope && options.scope.$new() || $rootScope.$new(true);
// Compile the template
var element = $compile(templateString)(scope);
$document[0].body.appendChild(element[0]);
var modal = new ionic.views.Modal({el: element[0] });
scope.modal = modal;
options.el = element[0];
var modal = new ModalView(options);
return modal;
},
fromTemplateUrl: function(url, cb, $scope) {
fromTemplateUrl: function(url, cb, options) {
TemplateLoader.load(url).then(function(templateString) {
// Create a new isolated scope for the modal
var scope = $scope && $scope.$new() || $rootScope.$new(true);
options = options || {};
// Create a new scope for the modal
var scope = options.scope && options.scope.$new() || $rootScope.$new(true);
// Compile the template
var element = $compile(templateString)(scope);
$document[0].body.appendChild(element[0]);
var modal = new ionic.views.Modal({ el: element[0] });
scope.modal = modal;
options.el = element[0];
var modal = new ModalView(options);
cb(modal);
});
}
},
};
}]);