Implementing a more versatile approach to unsafe links.

This update enables you to configure anchor elements with a data-unsafe-url="Are you sure?" attribute, allowing the customization of the confirmation message.
This commit is contained in:
Sipke Schoorstra
2014-10-20 21:00:49 -07:00
parent 245a296c3f
commit 57b09bc697

View File

@@ -210,7 +210,7 @@
$(function () {
var magicToken = $("input[name=__RequestVerificationToken]").first();
if (!magicToken) { return; } // no sense in continuing if form POSTS will fail
$("body").on("click", "a[itemprop~=UnsafeUrl]", function() {
$("body").on("click", "a[itemprop~=UnsafeUrl], a[data-unsafe-url]", function() {
var _this = $(this);
var hrefParts = _this.attr("href").split("?");
var form = $("<form action=\"" + hrefParts[0] + "\" method=\"POST\" />");
@@ -226,6 +226,14 @@
form.css({ "position": "absolute", "left": "-9999em" });
$("body").append(form);
var unsafeUrlPrompt = _this.data("unsafe-url");
if (unsafeUrlPrompt && unsafeUrlPrompt.length > 0) {
if (!confirm(unsafeUrlPrompt)) {
return false;
}
}
if (_this.filter("[itemprop~='RemoveUrl']").length == 1) {
if (!confirm(confirmRemoveMessage)) {
return false;