finished action sheet component

This commit is contained in:
Nick Wientge 2014-12-17 08:40:24 -08:00
parent a4f1a26c7e
commit 4ace2246c5
2 changed files with 37 additions and 7 deletions

View file

@ -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) {

View file

@ -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;
}
});