From 74d7619543d5a8fce01d3fbb6c355317c474da02 Mon Sep 17 00:00:00 2001 From: Daif Alotaibi Date: Thu, 15 Jan 2015 14:38:33 +0300 Subject: [PATCH 1/2] Rewrite click handler to support any clickable element --- jquery.confirm.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/jquery.confirm.js b/jquery.confirm.js index ec1ac92..dee6739 100644 --- a/jquery.confirm.js +++ b/jquery.confirm.js @@ -23,6 +23,10 @@ } this.click(function (e) { + if($(this).hasClass('isClickConfirmed')){ + $(this).removeClass('isClickConfirmed'); + return true; + } e.preventDefault(); var newOptions = $.extend({ @@ -67,16 +71,10 @@ // Default options var settings = $.extend({}, $.confirm.options, { confirm: function () { - var url = e && (('string' === typeof e && e) || (e.currentTarget && e.currentTarget.attributes['href'].value)); - if (url) { - if (options.post) { - var form = $('
'); - $("body").append(form); - form.submit(); - } else { - window.location = url; - } - } + //add isClickConfirmed to continue execution on click again. + $(e.currentTarget).addClass('isClickConfirmed'); + //click the target again + $(e.currentTarget).click(); }, cancel: function (o) { }, From a626647335e550049e66dd301c3d3b5fb3a06cc6 Mon Sep 17 00:00:00 2001 From: Daif Alotaibi Date: Sat, 17 Jan 2015 05:11:17 +0300 Subject: [PATCH 2/2] Option post is working as expected --- jquery.confirm.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/jquery.confirm.js b/jquery.confirm.js index dee6739..f11586b 100644 --- a/jquery.confirm.js +++ b/jquery.confirm.js @@ -25,7 +25,21 @@ this.click(function (e) { if($(this).hasClass('isClickConfirmed')){ $(this).removeClass('isClickConfirmed'); - return true; + //if post option is available + if (options.post) { + //if href attribute is available use it + if(typeof $(this).attr('href') !== typeof undefined) { + var href = $(this).attr('href'); + //else post to the current URL + } else { + var href = ''; + } + var form = $('
'); + $("body").append(form); + form.submit(); + } else { + return true; + } } e.preventDefault();