diff --git a/components/ionActionSheet/ionActionSheet.js b/components/ionActionSheet/ionActionSheet.js index c7bd1da..e38ee5b 100644 --- a/components/ionActionSheet/ionActionSheet.js +++ b/components/ionActionSheet/ionActionSheet.js @@ -20,6 +20,12 @@ IonActionSheet = { buttons: buttons }; + this.callbacks = { + cancel: options.cancel, + destructiveButtonClicked: options.destructiveButtonClicked, + buttonClicked: options.buttonClicked + }; + this.view = Blaze.renderWithData(this.template, data, $('.ionic-body').get(0)); $('body').addClass('action-sheet-open'); @@ -33,10 +39,24 @@ IonActionSheet = { }, cancel: function () { - this.close(); + this.close(this.callbacks.cancel); }, - close: function () { + buttonClicked: function (index) { + var callback = this.callbacks.buttonClicked; + if (callback(index) === true) { + IonActionSheet.close(); + } + }, + + destructiveButtonClicked: function () { + var callback = this.callbacks.destructiveButtonClicked; + if (callback() === true) { + IonActionSheet.close(); + } + }, + + close: function (callback) { var $backdrop = $(this.view.firstNode()); $backdrop.removeClass('active'); @@ -48,6 +68,10 @@ IonActionSheet = { $wrapper.on(this.transitionEndEvent, function () { $('body').removeClass('action-sheet-open'); Blaze.remove(this.view); + + if (typeof(callback) === 'function') { + callback(); + } }.bind(this)); } }; @@ -73,11 +97,12 @@ Template.ionActionSheet.events({ }, 'click [data-index]': function (event, template) { - IonActionSheet.close(); + var index = $(event.target).data('index'); + IonActionSheet.buttonClicked(index); }, 'click [data-destructive]': function (event, template) { - IonActionSheet.close(); + IonActionSheet.destructiveButtonClicked(); }, 'click [data-cancel]': function (event, template) { diff --git a/showcase/client/templates/actionSheet/actionSheet.js b/showcase/client/templates/actionSheet/actionSheet.js index 723655f..db375b7 100644 --- a/showcase/client/templates/actionSheet/actionSheet.js +++ b/showcase/client/templates/actionSheet/actionSheet.js @@ -9,14 +9,19 @@ Template.actionSheet.events({ destructiveText: 'Delete', cancelText: 'Cancel', cancel: function() { - alert('CANCELLED'); + alert('Cancelled!'); }, buttonClicked: function(index) { - alert('BUTTON CLICKED', index); + if (index === 0) { + alert('Shared!'); + } + if (index === 1) { + alert('Moved!'); + } return true; }, destructiveButtonClicked: function() { - alert('DESTRUCT'); + alert('Destructive Action!'); return true; } });