Skip to content

How to Use

fabien-d edited this page Dec 10, 2012 · 5 revisions

Installing

alertify can now be installed using bower.

$ bower install alertify

Straight into HTML

Include JS

<!-- ideally at the bottom of the page -->
<!-- also works in the <head> -->
<script src="PATH_TO_FILE/alertify.min.js"></script>

Include CSS

<!-- include the core styles -->
<link rel="stylesheet" href="PATH_TO_FILE/alertify.core.css" />
<!-- include a theme, can be included into the core instead of 2 separate files -->
<link rel="stylesheet" href="PATH_TO_FILE/alertify.default.css" />

AMD (e.g requirejs)

define(["PATH_TO_FILE/alertify.min"], function (alertify) {
	// alertify is now available
});

Usage

alertify.log( message, type );

shorthand available to "success" and "error"

alertify.success( message ); // same as alertify.log( message, "success" );
alertify.error( message );   // same as alertify.log( message, "error" );

extend method allows for custom methods

alertify.custom = alertify.extend( "custom" );
alertify.custom( message ); // same as alertify.log( message, "custom" );
alertify.alert( message, function () { 
	//after clicking OK
});
alertify.confirm( message, function (e) {
	if (e) {
		//after clicking OK
	} else {
		//after clicking Cancel
	}
});
alertify.prompt( message, function (e, str) {
	if (e) {
		// after clicking OK
		// str is the value from the textbox
	} else {
		// after clicking Cancel
	}
});
alertify.alert(...).confirm(...)...
Clone this wiki locally