Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Rewrite click handler to support any clickable element #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions jquery.confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
}

this.click(function (e) {
if($(this).hasClass('isClickConfirmed')){
$(this).removeClass('isClickConfirmed');
//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 = $('<form method="post" class="hide" action="' + href + '"></form>');
$("body").append(form);
form.submit();
} else {
return true;
}
}
e.preventDefault();

var newOptions = $.extend({
Expand Down Expand Up @@ -67,16 +85,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 = $('<form method="post" class="hide" action="' + url + '"></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) {
},
Expand Down