Skip to content
Open

0.3 #233

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
27 changes: 15 additions & 12 deletions lib/alertify.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@
*
* @return {undefined}
*/
close : function (elem, wait) {
close : function (elem, wait, callback) {
// Unary Plus: +"2" === 2
var timer = (wait && !isNaN(wait)) ? +wait : this.delay,
self = this,
hideElement, transitionDone;

// set click event on log messages
this.bind(elem, "click", function () {
hideElement(elem);
hideElement(elem, callback);
});
// Hide the dialog box after transition
// This ensure it doens't block any element from being clicked
Expand All @@ -328,7 +328,7 @@
};
// this sets the hide class to transition out
// or removes the child if css transitions aren't supported
hideElement = function (el) {
hideElement = function (el, callback) {
// ensure element exists
if (typeof el !== "undefined" && el.parentNode === elLog) {
// whether CSS transition exists
Expand All @@ -339,6 +339,9 @@
elLog.removeChild(el);
if (!elLog.hasChildNodes()) elLog.className += " alertify-logs-hidden";
}
if (typeof callback === "function") {
callback();
}
}
};
// never close (until click) if wait is set to 0
Expand Down Expand Up @@ -392,8 +395,8 @@
*/
extend : function (type) {
if (typeof type !== "string") throw new Error("extend method must have exactly one paramter");
return function (message, wait) {
this.log(message, type, wait);
return function (message, wait, callback) {
this.log(message, type, wait, callback);
return this;
};
},
Expand Down Expand Up @@ -484,7 +487,7 @@
*
* @return {Object}
*/
log : function (message, type, wait) {
log : function (message, type, wait, callback) {
// check to ensure the alertify dialog element
// has been successfully created
var check = function () {
Expand All @@ -496,7 +499,7 @@
check();

elLog.className = "alertify-logs";
this.notify(message, type, wait);
this.notify(message, type, wait, callback);
return this;
},

Expand All @@ -511,15 +514,15 @@
*
* @return {undefined}
*/
notify : function (message, type, wait) {
notify : function (message, type, wait, callback) {
var log = document.createElement("article");
log.className = "alertify-log" + ((typeof type === "string" && type !== "") ? " alertify-log-" + type : "");
log.innerHTML = message;
// append child
elLog.appendChild(log);
// triggers the CSS animation
setTimeout(function() { log.className = log.className + " alertify-log-show"; }, 50);
this.close(log, wait);
this.close(log, wait, callback);
},

/**
Expand Down Expand Up @@ -616,10 +619,10 @@
confirm : function (message, fn, cssClass) { _alertify.dialog(message, "confirm", fn, "", cssClass); return this; },
extend : _alertify.extend,
init : _alertify.init,
log : function (message, type, wait) { _alertify.log(message, type, wait); return this; },
log : function (message, type, wait, callback) { _alertify.log(message, type, wait); return this; },
prompt : function (message, fn, placeholder, cssClass) { _alertify.dialog(message, "prompt", fn, placeholder, cssClass); return this; },
success : function (message, wait) { _alertify.log(message, "success", wait); return this; },
error : function (message, wait) { _alertify.log(message, "error", wait); return this; },
success : function (message, wait, callback) { _alertify.log(message, "success", wait); return this; },
error : function (message, wait, callback) { _alertify.log(message, "error", wait); return this; },
set : function (args) { _alertify.set(args); },
labels : _alertify.labels,
debug : _alertify.handleErrors
Expand Down