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

alertify.js click callback to log message #206

Open
wants to merge 1 commit into
base: 0.3
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 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") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency purpose, no brackets and strict equal

if (typeof callback === "function")

callback();
}
}
};
// never close (until click) if wait is set to 0
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