From e5642600d4dba6ad7721c6cbd87af1b2c75d1f3d Mon Sep 17 00:00:00 2001 From: Boniface Pereira Date: Wed, 9 Aug 2017 23:14:22 +0530 Subject: [PATCH] #290 prevent multiple attachments --- js/jquery-confirm.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js/jquery-confirm.js b/js/jquery-confirm.js index 3a91db3..a9269c0 100644 --- a/js/jquery-confirm.js +++ b/js/jquery-confirm.js @@ -29,6 +29,11 @@ var jconfirm, Jconfirm; */ $(this).each(function () { var $this = $(this); + if ($this.attr('jc-attached')) { + console.warn('jConfirm has already binded to this element ', $this[0]); + return; + } + $this.on('click', function (e) { e.preventDefault(); var jcOption = $.extend({}, options); @@ -49,8 +54,10 @@ var jconfirm, Jconfirm; }; } jcOption['closeIcon'] = false; - $.confirm(jcOption); + var instance = $.confirm(jcOption); }); + + $this.attr('jc-attached', true); }); return $(this); }; @@ -1324,10 +1331,8 @@ var jconfirm, Jconfirm; $(window).on('keyup', function () { keyDown = false; }); - jconfirm.lastClicked = false; $(document).on('mousedown', 'button, a', function () { - console.log('hey clicked', this); jconfirm.lastClicked = $(this); }); })(jQuery, window);