From e0c7979aa52199b15252b2870508bff9ae8b2ef5 Mon Sep 17 00:00:00 2001 From: Pavel Strashkin Date: Mon, 12 May 2014 22:34:34 -0700 Subject: [PATCH] feat ($ionicActionSheet): pass button object to buttonClicked Closes #1369. Right now `buttonClicked` accepts only the index of the pressed button that means you have to work with indices to decide which one it is. In case you move buttons around to get better UX, you'd have to be very careful with those indices. It's easier to add `id` property to buttons and simply check for it. Index-agnostic solution is more maintainable and leads to less changes to the code when the buttons order is being changed. --- js/angular/service/actionSheet.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/angular/service/actionSheet.js b/js/angular/service/actionSheet.js index 469d8c76c8..27223c6757 100644 --- a/js/angular/service/actionSheet.js +++ b/js/angular/service/actionSheet.js @@ -69,8 +69,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad * - `{string=}` `destructiveText` The text for a 'danger' on the action sheet. * - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped. * - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked, - * with the index of the button that was clicked. Return true to close the action sheet, - * or false to keep it opened. + * with the index of the button that was clicked and the button object. Return true to close + * the action sheet, or false to keep it opened. * - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked. * Return true to close the action sheet, or false to keep it opened. */ @@ -80,7 +80,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad extend(scope, { cancel: angular.noop, buttonClicked: angular.noop, - destructiveButtonClicked: angular.noop + destructiveButtonClicked: angular.noop, + buttons: [] }, opts); // Compile the template @@ -121,7 +122,7 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad 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) { + if((opts.buttonClicked && opts.buttonClicked(index, opts.buttons[index])) === true) { hideSheet(false); } };