Skip to content

Commit

Permalink
Fix multiple dialogs back to back, issue #166
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien-d committed Oct 8, 2013
1 parent a7f7773 commit b2cb592
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 44 deletions.
82 changes: 47 additions & 35 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h2>Dialogs</h2>
<a href="#" id="focus">Button Focus</a><br>
<a href="#" id="order">Button Order</a>

<h2>Ajax</h2>
<a href="#" id="ajax">Ajax - Multiple Dialog</a>

<h2>Logs</h2>
<a href="#" id="notification">Standard Log</a><br>
<a href="#" id="success">Success Log</a><br>
Expand All @@ -33,15 +36,11 @@ <h2>Logs</h2>
<h2>Themes</h2>
<a href="#" id="bootstrap">Bootstrap Theme</a>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="../lib/alertify.min.js"></script>
<script>
"use strict";
var
$ = function (id) {
return document.getElementById(id);
},
reset = function () {
$("toggleCSS").href = "../themes/alertify.default.css";
function reset () {
$("#toggleCSS").attr("href", "../themes/alertify.default.css");
alertify.set({
labels : {
ok : "OK",
Expand All @@ -51,17 +50,17 @@ <h2>Themes</h2>
buttonReverse : false,
buttonFocus : "ok"
});
};
}

// ==============================
// Standard Dialogs
$("alert").onclick = function () {
$("#alert").on( 'click', function () {
reset();
alertify.alert("This is an alert dialog");
return false;
};
});

$("confirm").onclick = function () {
$("#confirm").on( 'click', function () {
reset();
alertify.confirm("This is a confirm dialog", function (e) {
if (e) {
Expand All @@ -71,9 +70,9 @@ <h2>Themes</h2>
}
});
return false;
};
});

$("prompt").onclick = function () {
$("#prompt").on( 'click', function () {
reset();
alertify.prompt("This is a prompt dialog", function (e, str) {
if (e) {
Expand All @@ -83,44 +82,57 @@ <h2>Themes</h2>
}
}, "Default Value");
return false;
};
});

// ==============================
// Ajax
$("#ajax").on("click", function () {
reset();
alertify.confirm("Confirm?", function (e) {
if (e) {
alertify.alert("Successful AJAX after OK");
} else {
alertify.alert("Successful AJAX after Cancel");
}
});
});

// ==============================
// Standard Dialogs
$("notification").onclick = function () {
$("#notification").on( 'click', function () {
reset();
alertify.log("Standard log message");
return false;
};
});

$("success").onclick = function () {
$("#success").on( 'click', function () {
reset();
alertify.success("Success log message");
return false;
};
});

$("error").onclick = function () {
$("#error").on( 'click', function () {
reset();
alertify.error("Error log message");
return false;
};
});

// ==============================
// Custom Properties
$("delay").onclick = function () {
$("#delay").on( 'click', function () {
reset();
alertify.set({ delay: 10000 });
alertify.log("Hiding in 10 seconds");
return false;
};
});

$("forever").onclick = function () {
$("#forever").on( 'click', function () {
reset();
alertify.log("Will stay until clicked", "", 0);
return false;
};
});

$("labels").onclick = function () {
$("#labels").on( 'click', function () {
reset();
alertify.set({ labels: { ok: "Accept", cancel: "Deny" } });
alertify.confirm("Confirm dialog with custom button labels", function (e) {
Expand All @@ -131,9 +143,9 @@ <h2>Themes</h2>
}
});
return false;
};
});

$("focus").onclick = function () {
$("#focus").on( 'click', function () {
reset();
alertify.set({ buttonFocus: "cancel" });
alertify.confirm("Confirm dialog with cancel button focused", function (e) {
Expand All @@ -144,9 +156,9 @@ <h2>Themes</h2>
}
});
return false;
};
});

$("order").onclick = function () {
$("#order").on( 'click', function () {
reset();
alertify.set({ buttonReverse: true });
alertify.confirm("Confirm dialog with reversed button order", function (e) {
Expand All @@ -157,22 +169,22 @@ <h2>Themes</h2>
}
});
return false;
};
});

// ==============================
// Custom Log
$("custom").onclick = function () {
$("#custom").on( 'click', function () {
reset();
alertify.custom = alertify.extend("custom");
alertify.custom("I'm a custom log message");
return false;
};
});

// ==============================
// Custom Themes
$("bootstrap").onclick = function () {
$("#bootstrap").on( 'click', function () {
reset();
$("toggleCSS").href = "../themes/alertify.bootstrap.css";
$("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
alertify.prompt("Prompt dialog with bootstrap theme", function (e) {
if (e) {
alertify.success("You've clicked OK");
Expand All @@ -181,7 +193,7 @@ <h2>Themes</h2>
}
}, "Default Value");
return false;
};
});
</script>

</body>
Expand Down
3 changes: 1 addition & 2 deletions lib/alertify.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
// keyup handler
key = function (event) {
var keyCode = event.keyCode;
if ((keyCode === keys.SPACE && !hasInput) || keyCode === keys.ENTER) ok(event);
if ((keyCode === keys.SPACE && !hasInput) || (hasInput && keyCode === keys.ENTER)) ok(event);
if (keyCode === keys.ESC && hasCancel) cancel(event);
};

Expand Down Expand Up @@ -414,7 +414,6 @@
// This ensure it doens't block any element from being clicked
transitionDone = function (event) {
event.stopPropagation();
elDialog.className += " alertify-isHidden";
// unbind event so function only gets called once
self.unbind(elDialog, self.transition.type, transitionDone);
};
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.

Loading

0 comments on commit b2cb592

Please sign in to comment.