mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
Lots of action sheet work
This commit is contained in:
50
js/ext/angular/src/service/ionicActionSheet.js
vendored
50
js/ext/angular/src/service/ionicActionSheet.js
vendored
@ -1,6 +1,8 @@
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.ui.actionSheet'])
|
||||
angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ionic.ui.actionSheet', 'ngAnimate'])
|
||||
|
||||
.factory('ActionSheet', ['$rootScope', '$document', '$compile', '$animate', 'TemplateLoader',
|
||||
function($rootScope, $document, $compile, $animate, TemplateLoader) {
|
||||
|
||||
.factory('ActionSheet', ['$rootScope', '$document', '$compile', 'TemplateLoader', function($rootScope, $document, $compile, TemplateLoader) {
|
||||
return {
|
||||
/**
|
||||
* Load an action sheet with the given template string.
|
||||
@ -10,23 +12,38 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
|
||||
*
|
||||
* @param {object} opts the options for this ActionSheet (see docs)
|
||||
*/
|
||||
show: function(opts, $scope) {
|
||||
var scope = $scope && $scope.$new() || $rootScope.$new(true);
|
||||
show: function(opts) {
|
||||
var scope = $rootScope.$new(true);
|
||||
|
||||
angular.extend(scope, opts);
|
||||
|
||||
|
||||
// Compile the template
|
||||
var element = $compile('<action-sheet buttons="buttons"></action-sheet>')(scope);
|
||||
|
||||
// Grab the sheet element for animation
|
||||
var sheetEl = angular.element(element[0].querySelector('.action-sheet'));
|
||||
|
||||
var hideSheet = function(didCancel) {
|
||||
$animate.leave(sheetEl, function() {
|
||||
if(didCancel) {
|
||||
opts.cancel();
|
||||
}
|
||||
});
|
||||
$animate.removeClass(element, 'active', function() {
|
||||
scope.$destroy();
|
||||
});
|
||||
};
|
||||
|
||||
scope.cancel = function() {
|
||||
scope.sheet.hide();
|
||||
//scope.$destroy();
|
||||
opts.cancel();
|
||||
hideSheet(true);
|
||||
};
|
||||
|
||||
scope.buttonClicked = function(index) {
|
||||
// Check if the button click event returned true, which means
|
||||
// we can close the action sheet
|
||||
if((opts.buttonClicked && opts.buttonClicked(index)) === true) {
|
||||
scope.sheet.hide();
|
||||
//scope.$destroy();
|
||||
hideSheet(false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -34,24 +51,21 @@ angular.module('ionic.service.actionSheet', ['ionic.service.templateLoad', 'ioni
|
||||
// Check if the destructive button click event returned true, which means
|
||||
// we can close the action sheet
|
||||
if((opts.destructiveButtonClicked && opts.destructiveButtonClicked()) === true) {
|
||||
scope.sheet.hide();
|
||||
//scope.$destroy();
|
||||
hideSheet(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Compile the template
|
||||
var element = $compile('<action-sheet buttons="buttons"></action-sheet>')(scope);
|
||||
|
||||
var s = element.scope();
|
||||
|
||||
$document[0].body.appendChild(element[0]);
|
||||
|
||||
var sheet = new ionic.views.ActionSheet({el: element[0] });
|
||||
s.sheet = sheet;
|
||||
scope.sheet = sheet;
|
||||
|
||||
sheet.show();
|
||||
$animate.addClass(element, 'active');
|
||||
$animate.enter(sheetEl, element, function() {
|
||||
});
|
||||
|
||||
return sheet;
|
||||
}
|
||||
};
|
||||
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user