Skip to content

Commit 0912292

Browse files
committed
Added prompt functionality to IonPopup
1 parent ed3d3f1 commit 0912292

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

components/ionPopup/ionPopup.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ IonPopup = {
1818
if (options.templateName) {
1919
innerTemplate = Template[options.templateName].renderFunction().value;
2020
} else {
21-
innerTemplate = options.template;
21+
innerTemplate = '<span>' + options.template + '</span>';
2222
}
2323

2424
var data = {
@@ -66,15 +66,52 @@ IonPopup = {
6666
{
6767
text: options.okText ? options.okText : 'Ok',
6868
type: options.okType ? options.okType : 'button-positive',
69-
onTap: function() {
69+
onTap: function (event) {
7070
if (options.onOk) options.onOk(event);
7171
return true;
7272
}
7373
},
7474
{
7575
text: options.cancelText ? options.cancelText : 'Cancel',
7676
type: options.cancelType ? options.cancelType : 'button-default',
77-
onTap: function() {
77+
onTap: function (event) {
78+
if (options.onCancel) options.onCancel(event);
79+
return true;
80+
}
81+
}
82+
]
83+
});
84+
},
85+
86+
prompt: function (options) {
87+
88+
if (options.templateName) {
89+
template = Template[options.templateName].renderFunction().value;
90+
} else {
91+
template = '<span>' + options.template + '</span>';
92+
}
93+
94+
template += '<input type="' + options.inputType + '" placeholder="' +
95+
options.inputPlaceholder + '" name="prompt" >';
96+
97+
IonPopup.show({
98+
title: options.title,
99+
subTitle: options.subtitle,
100+
template: template,
101+
buttons: [
102+
{
103+
text: options.okText ? options.okText : 'Ok',
104+
type: options.okType ? options.okType : 'button-positive',
105+
onTap: function (event, template) {
106+
var inputVal = $(template.firstNode).find('[name=prompt]').val();
107+
if (options.onOk) options.onOk(event, inputVal);
108+
return true;
109+
}
110+
},
111+
{
112+
text: options.cancelText ? options.cancelText : 'Cancel',
113+
type: options.cancelType ? options.cancelType : 'button-default',
114+
onTap: function (event) {
78115
if (options.onCancel) options.onCancel(event);
79116
return true;
80117
}
@@ -94,10 +131,10 @@ IonPopup = {
94131
}.bind(this), 100);
95132
},
96133

97-
buttonClicked: function (index, event) {
134+
buttonClicked: function (index, event, template) {
98135
var callback = this.buttons[index].onTap;
99136
if(callback){
100-
if (callback(event) === true) {
137+
if (callback(event, template) === true) {
101138
IonPopup.close();
102139
}
103140
}
@@ -126,7 +163,7 @@ Template.ionPopup.events({
126163

127164
'click [data-index]': function (event, template) {
128165
var index = $(event.target).data('index');
129-
IonPopup.buttonClicked(index, event);
166+
IonPopup.buttonClicked(index, event, template);
130167
}
131168

132169
});

0 commit comments

Comments
 (0)