Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
/ notie Public archive

Commit 75372a9

Browse files
committed
Allow callback declaration within function objects. Add select cancel callback.
1 parent f2aaf55 commit 75372a9

File tree

5 files changed

+221
-139
lines changed

5 files changed

+221
-139
lines changed

README.md

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,24 @@ notie.alert({
8585
notie.force({
8686
type: Number|String, // optional, default = 5, enum: [1, 2, 3, 4, 5, 'success', 'warning', 'error', 'info', 'neutral']
8787
text: String,
88-
buttonText: String // optional, default = 'OK'
89-
}, callback())
88+
buttonText: String, // optional, default = 'OK'
89+
callback: Function // optional
90+
}, callbackOptional())
9091

9192
notie.confirm({
9293
text: String,
93-
yesText: String, // optional, default = 'Yes'
94-
noText: String // optional, default = 'Cancel'
95-
}, yesCallbackOptional(), noCallbackOptional())
94+
submitText: String, // optional, default = 'Yes'
95+
cancelText: String, // optional, default = 'Cancel'
96+
submitCallback: Function, // optional
97+
cancelCallback: Function // optional
98+
}, submitCallbackOptional(), cancelCallbackOptional())
9699

97100
notie.input({
98101
text: String,
99102
submitText: String, // optional, default = 'Submit'
100103
cancelText: String // optional, default = 'Cancel'
104+
submitCallback: Function(value), // optional
105+
cancelCallback: Function(value), // optional
101106
autocapitalize: 'words', // default: 'none'
102107
autocomplete: 'on', // default: 'off'
103108
autocorrect: 'off', // default: 'off'
@@ -116,7 +121,8 @@ notie.input({
116121

117122
notie.select({
118123
text: String,
119-
cancelText: String,
124+
cancelText: String, // optional, default = 'Cancel'
125+
cancelCallback: Function, // optional
120126
choices: [
121127
{
122128
type: Number|String, // optional, default = 1
@@ -125,12 +131,14 @@ notie.select({
125131
}
126132
...
127133
]
128-
})
134+
}, cancelCallbackOptional())
129135

130136
notie.date({
131137
value: Date,
132138
submitText: String, // optional, default = 'OK'
133-
cancelText: String // optional, default = 'Cancel'
139+
cancelText: String, // optional, default = 'Cancel'
140+
submitCallback: Function(date), // optional
141+
cancelCallback: Function(date) // optional
134142
}, submitCallbackOptional(date), cancelCallbackOptional(date))
135143
```
136144

@@ -149,19 +157,20 @@ notie.alert({ type: 'info', text: 'FYI, blah blah blah.' })
149157
notie.force({
150158
type: 3,
151159
text: 'You cannot do that, sending you back.',
152-
buttonText: 'OK'
153-
}, function () {
154-
notie.alert({ type: 3, text: 'Maybe when you\'re older...' })
160+
buttonText: 'OK',
161+
callback: function () {
162+
notie.alert({ type: 3, text: 'Maybe when you\'re older...' })
163+
}
155164
})
156165

157166
notie.confirm({
158-
text: 'Are you sure you want to do that?',
159-
yesText: 'Yes',
160-
noText: 'Cancel'
161-
}, function () {
162-
notie.alert({ type: 1, text: 'Good choice!' })
163-
}, function () {
164-
notie.alert({ type: 3, text: 'Aw, why not? :(' })
167+
text: 'Are you sure you want to do that?<br><b>That\'s a bold move...</b>',
168+
cancelCallback: function () {
169+
notie.alert({ type: 3, text: 'Aw, why not? :(', time: 2 })
170+
},
171+
submitCallback: function () {
172+
notie.alert({ type: 1, text: 'Good choice! :D', time: 2 })
173+
}
165174
})
166175
notie.confirm({ text: 'Are you sure?' }, function() {
167176
notie.confirm({ text: 'Are you <b>really</b> sure?' }, function() {
@@ -175,13 +184,15 @@ notie.input({
175184
text: 'Please enter your email:',
176185
submitText: 'Submit',
177186
cancelText: 'Cancel',
187+
cancelCallback: function (value) {
188+
notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
189+
},
190+
submitCallback: function (value) {
191+
notie.alert({ type: 1, text: 'You entered: ' + value })
192+
},
178193
value: 'jane@doe.com',
179194
type: 'email',
180195
placeholder: 'name@example.com'
181-
}, function(value) {
182-
notie.alert({ type: 1, text: 'You entered: ' + value })
183-
}, function(value) {
184-
notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
185196
})
186197

187198
notie.input({
@@ -197,18 +208,23 @@ notie.input({
197208

198209
notie.input({
199210
text: 'Please enter the price:',
211+
cancelCallback: function (value) {
212+
notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
213+
},
214+
submitCallback: function (value) {
215+
notie.alert({ type: 1, text: 'You entered: ' + value })
216+
},
200217
type: 'text',
201218
placeholder: '500',
202219
allowed: new RegExp('[^0-9]', 'g')
203-
}, function(value) {
204-
notie.alert({ type: 1, text: 'You entered: ' + value })
205-
}, function(value) {
206-
notie.alert({ type: 3, text: 'You cancelled with this value: ' + value })
207220
})
208221

209222
notie.select({
210223
text: 'Demo item #1, owner is Jane Smith',
211-
cancelText: 'Cancel',
224+
cancelText: 'Close',
225+
cancelCallback: function () {
226+
notie.alert({ type: 5, text: 'Cancel!' })
227+
},
212228
choices: [
213229
{
214230
text: 'Share',
@@ -239,15 +255,17 @@ notie.select({
239255
]
240256
})
241257

242-
notie.date({
243-
value: new Date(2015, 8, 27),
244-
submitText: 'Submit',
245-
cancelText: 'Cancel'
246-
}, function (date) {
247-
notie.alert({ type: 1, text: 'You selected: ' + date.toISOString() })
248-
}, function (date) {
249-
notie.alert({ type: 3, text: 'You cancelled: ' + date.toISOString() })
250-
})
258+
function date() {
259+
notie.date({
260+
value: new Date(2015, 8, 27),
261+
cancelCallback: function (date) {
262+
notie.alert({ type: 3, text: 'You cancelled: ' + date.toISOString() })
263+
},
264+
submitCallback: function (date) {
265+
notie.alert({ type: 1, text: 'You selected: ' + date.toISOString() })
266+
}
267+
})
268+
}
251269
```
252270
253271
#### Use ES6 to inherit `this`:

0 commit comments

Comments
 (0)