Skip to content

Commit

Permalink
optional css class name, issue #51
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien-d committed Dec 16, 2012
1 parent a33f479 commit f94cd56
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
18 changes: 10 additions & 8 deletions lib/alertify.js
Expand Up @@ -182,7 +182,8 @@
build : function (item) {
var html = "",
type = item.type,
message = item.message;
message = item.message,
css = item.cssClass || "";

html += "<div class=\"alertify-dialog\">";

Expand Down Expand Up @@ -218,7 +219,7 @@
break;
}

elDialog.className = "alertify alertify-show alertify-" + type;
elDialog.className = "alertify alertify-show alertify-" + type + " " + css;
elCover.className = "alertify-cover";
return html;
},
Expand Down Expand Up @@ -248,10 +249,11 @@
* @param {String} type Type of dialog to create
* @param {Function} fn [Optional] Callback function
* @param {String} placeholder [Optional] Default value for prompt input field
* @param {String} cssClass [Optional] Class(es) to append to dialog box
*
* @return {Object}
*/
dialog : function (message, type, fn, placeholder) {
dialog : function (message, type, fn, placeholder, cssClass) {
// set the current active element
// this allows the keyboard focus to be resetted
// after the dialog box is closed
Expand All @@ -272,7 +274,7 @@
check();
}

queue.push({ type: type, message: message, callback: fn, placeholder: placeholder });
queue.push({ type: type, message: message, callback: fn, placeholder: placeholder, cssClass: cssClass });
if (!isopen) this.setup();

return this;
Expand Down Expand Up @@ -423,7 +425,7 @@

isopen = true;
elDialog.innerHTML = this.build(item);
if (typeof item.placeholder === "string") $("alertify-text").value = item.placeholder;
if (typeof item.placeholder === "string" && item.placeholder !== "") $("alertify-text").value = item.placeholder;
this.addListeners(item.callback);
},

Expand All @@ -446,12 +448,12 @@
};

return {
alert : function (message, fn) { _alertify.dialog(message, "alert", fn); return this; },
confirm : function (message, fn) { _alertify.dialog(message, "confirm", fn); return this; },
alert : function (message, fn, cssClass) { _alertify.dialog(message, "alert", fn, "", cssClass); return this; },
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; },
prompt : function (message, fn, placeholder) { _alertify.dialog(message, "prompt", fn, placeholder); 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; },
set : function (args) { _alertify.set(args); },
Expand Down
2 changes: 1 addition & 1 deletion lib/alertify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions src/alertify.js
Expand Up @@ -170,7 +170,8 @@
build : function (item) {
var html = "",
type = item.type,
message = item.message;
message = item.message,
css = item.cssClass || "";

html += "<div class=\"alertify-dialog\">";

Expand Down Expand Up @@ -206,7 +207,7 @@
break;
}

elDialog.className = "alertify alertify-show alertify-" + type;
elDialog.className = "alertify alertify-show alertify-" + type + " " + css;
elCover.className = "alertify-cover";
return html;
},
Expand Down Expand Up @@ -236,10 +237,11 @@
* @param {String} type Type of dialog to create
* @param {Function} fn [Optional] Callback function
* @param {String} placeholder [Optional] Default value for prompt input field
* @param {String} cssClass [Optional] Class(es) to append to dialog box
*
* @return {Object}
*/
dialog : function (message, type, fn, placeholder) {
dialog : function (message, type, fn, placeholder, cssClass) {
// set the current active element
// this allows the keyboard focus to be resetted
// after the dialog box is closed
Expand All @@ -260,7 +262,7 @@
check();
}

queue.push({ type: type, message: message, callback: fn, placeholder: placeholder });
queue.push({ type: type, message: message, callback: fn, placeholder: placeholder, cssClass: cssClass });
if (!isopen) this.setup();

return this;
Expand Down Expand Up @@ -411,7 +413,7 @@

isopen = true;
elDialog.innerHTML = this.build(item);
if (typeof item.placeholder === "string") $("alertify-text").value = item.placeholder;
if (typeof item.placeholder === "string" && item.placeholder !== "") $("alertify-text").value = item.placeholder;
this.addListeners(item.callback);
},

Expand All @@ -434,12 +436,12 @@
};

return {
alert : function (message, fn) { _alertify.dialog(message, "alert", fn); return this; },
confirm : function (message, fn) { _alertify.dialog(message, "confirm", fn); return this; },
alert : function (message, fn, cssClass) { _alertify.dialog(message, "alert", fn, "", cssClass); return this; },
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; },
prompt : function (message, fn, placeholder) { _alertify.dialog(message, "prompt", fn, placeholder); 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; },
set : function (args) { _alertify.set(args); },
Expand Down

0 comments on commit f94cd56

Please sign in to comment.