Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return false from ui.Confirmation callback cancels dialog close #48

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions build/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var active;
exports.Dialog = Dialog;

/**
* Return a new `Dialog` with the given
* Return a new `Dialog` with the given
* (optional) `title` and `msg`.
*
* @param {String} title or msg
Expand Down Expand Up @@ -330,9 +330,9 @@ Dialog.prototype.hide = function(ms){
// hide / remove
this.el.addClass('hide');
if (this._effect) {
setTimeout(function(self){
setTimeout(function(){
self.remove();
}, 500, this);
}, 500);
} else {
self.remove();
}
Expand Down Expand Up @@ -448,7 +448,7 @@ Overlay.prototype.hide = function(){
exports.Confirmation = Confirmation;

/**
* Return a new `Confirmation` dialog with the given
* Return a new `Confirmation` dialog with the given
* `title` and `msg`.
*
* @param {String} title or msg
Expand Down Expand Up @@ -529,10 +529,11 @@ Confirmation.prototype.ok = function(text){
* @api public
*/

Confirmation.prototype.show = function(fn){
Confirmation.prototype.show = function(fn, async){
ui.Dialog.prototype.show.call(this);
this.el.find('.ok').focus();
this.callback = fn || function(){};
this.async = async || false;
return this;
};

Expand Down Expand Up @@ -562,15 +563,29 @@ Confirmation.prototype.render = function(options){
actions.find('.cancel').click(function(e){
e.preventDefault();
self.emit('cancel');
self.callback(false);
if(self.async){
self.callback(false, function () {
self.hide();
});
}
else {
(self.callback(false) !== false && self.hide());
}
self.callback(false)
self.hide();
});

actions.find('.ok').click(function(e){
e.preventDefault();
self.emit('ok');
self.callback(true);
self.hide();
if(self.async){
self.callback(true, function(){
self.hide();
});
}
else{
(self.callback(true) !== false && self.hide());
}
});
};

Expand Down Expand Up @@ -1148,9 +1163,9 @@ Notification.prototype.hide = function(ms){
// hide / remove
this.el.addClass('hide');
if (this._effect) {
setTimeout(function(self){
setTimeout(function(){
self.remove();
}, 500, this);
}, 500);
} else {
self.remove();
}
Expand Down Expand Up @@ -1297,7 +1312,7 @@ exports.Menu = Menu;
*/

exports.menu = function(){
return new Menu();
return new Menu;
};

/**
Expand Down
25 changes: 19 additions & 6 deletions lib/components/confirmation/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
exports.Confirmation = Confirmation;

/**
* Return a new `Confirmation` dialog with the given
* Return a new `Confirmation` dialog with the given
* `title` and `msg`.
*
* @param {String} title or msg
Expand Down Expand Up @@ -87,10 +87,11 @@ Confirmation.prototype.ok = function(text){
* @api public
*/

Confirmation.prototype.show = function(fn){
Confirmation.prototype.show = function(fn, async){
ui.Dialog.prototype.show.call(this);
this.el.find('.ok').focus();
this.callback = fn || function(){};
this.async = async || false;
return this;
};

Expand Down Expand Up @@ -120,14 +121,26 @@ Confirmation.prototype.render = function(options){
actions.find('.cancel').click(function(e){
e.preventDefault();
self.emit('cancel');
self.callback(false);
self.hide();
if(self.async){
self.callback(false, function () {
self.hide();
});
}
else {
(self.callback(false) !== false && self.hide());
}
});

actions.find('.ok').click(function(e){
e.preventDefault();
self.emit('ok');
self.callback(true);
self.hide();
if(self.async){
self.callback(true, function(){
self.hide();
});
}
else{
(self.callback(true) !== false && self.hide());
}
});
};
2 changes: 1 addition & 1 deletion lib/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var active;
exports.Dialog = Dialog;

/**
* Return a new `Dialog` with the given
* Return a new `Dialog` with the given
* (optional) `title` and `msg`.
*
* @param {String} title or msg
Expand Down