mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Fixed #79
This commit is contained in:
59
js/ext/angular/src/service/ionicModal.js
vendored
59
js/ext/angular/src/service/ionicModal.js
vendored
@@ -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);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
}]);
|
||||
|
||||
55
js/ext/angular/test/modal.html
Normal file
55
js/ext/angular/test/modal.html
Normal file
@@ -0,0 +1,55 @@
|
||||
<html ng-app="modalTest">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Modal</title>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<script id="modal.html" type="text/ng-template">
|
||||
<div class="modal">
|
||||
<header class="bar bar-header bar-secondary">
|
||||
<h1 class="title">Modal</h1>
|
||||
<button class="button button-clear button-primary" ng-click="closeModal()">Cancel</button>
|
||||
</header>
|
||||
<content has-header="true">
|
||||
Realllllyyy long content
|
||||
<div style="height: 2000px; background-color: red;"></div>
|
||||
</content>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script src="../../../../dist/js/ionic.js"></script>
|
||||
<script src="../../../../dist/js/ionic-angular.js"></script>
|
||||
<script>
|
||||
angular.module('modalTest', ['ionic', 'ngAnimate'])
|
||||
|
||||
.controller('ModalCtrl', function($scope, Modal) {
|
||||
Modal.fromTemplateUrl('modal.html', function(modal) {
|
||||
$scope.modal = modal;
|
||||
}, {
|
||||
scope: $scope,
|
||||
animation: 'slide-in-up'
|
||||
});
|
||||
|
||||
$scope.openModal = function() {
|
||||
$scope.modal.show();
|
||||
};
|
||||
$scope.closeModal = function() {
|
||||
$scope.modal.hide();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user