Lots of little tweaks

This commit is contained in:
Max Lynch
2013-11-08 18:43:20 -06:00
parent 6ab1f49688
commit a46060f070
5 changed files with 57 additions and 54 deletions

View File

@ -5,7 +5,7 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
var ModalView = ionic.views.Modal.inherit({
initialize: function(opts) {
ionic.views.Modal.prototype.initialize.call(this, opts);
this.animation = opts.animation;
this.animation = opts.animation || 'slide-in-up';
},
// Show the modal
show: function() {
@ -30,6 +30,25 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
}
});
var createModal = function(templateString, 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);
options.el = element[0];
var modal = new ModalView(options);
// If this wasn't a defined scope, we can assign 'modal' to the isolated scope
// we created
if(!options.scope) {
scope.modal = modal;
}
return modal;
};
return {
/**
* Load a modal with the given template string.
@ -38,30 +57,12 @@ angular.module('ionic.service.modal', ['ionic.service.templateLoad'])
* modal and the new element will be appended into the body.
*/
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);
options.el = element[0];
var modal = new ModalView(options);
var modal = createModal(templateString, options || {});
return modal;
},
fromTemplateUrl: function(url, cb, options) {
TemplateLoader.load(url).then(function(templateString) {
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);
options.el = element[0];
var modal = new ModalView(options);
var modal = createModal(templateString, options || {});
cb(modal);
});
},

View File

@ -5,15 +5,16 @@
<!-- Sets initial viewport load and disables zooming -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular-animate.js"></script>
</head>
<body>
<content has-header="true" ng-controller="ModalCtrl">
<button class="button button-primary" ng-click="openModal()">Open</button>
<content has-header="true">
<div ng-controller="ModalCtrl">
<button class="button button-primary" ng-click="openModal()">Open</button>
</div>
</content>
<script id="modal.html" type="text/ng-template">