diff --git a/micro-modal.js b/micro-modal.js index 01d84b6..da937a8 100644 --- a/micro-modal.js +++ b/micro-modal.js @@ -19,7 +19,7 @@ }; initialize = function(options) { - var $modal, $modalDialog; + var $modal; options = $.extend({ backdrop: true, keyboard: true, @@ -32,12 +32,10 @@ if (options.vertical) { $modal.addClass('modal-vertical'); } - $modal.on('click', function(e) { - return close.apply(this); - }); - $modalDialog = $modal.children('.modal-dialog'); - return $modalDialog.on('click', function(e) { - return e.stopPropagation(); + return $modal.on('click', function(e) { + if (e.target === e.currentTarget) { + return close.apply(this); + } }); }; diff --git a/package.json b/package.json index cc753a9..8c94f0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "micro-modal", - "version": "1.0.0", + "version": "1.0.1", "author": "Jens Ljungblad", "devDependencies": { "gulp": "~3.8.8", diff --git a/source/micro-modal.coffee b/source/micro-modal.coffee index 5f9e99d..b36b673 100644 --- a/source/micro-modal.coffee +++ b/source/micro-modal.coffee @@ -22,12 +22,13 @@ initialize = (options) -> $modal.addClass 'modal-vertical' if options.vertical # Close modal when clicking the backdrop - $modal.on 'click', (e) -> close.apply this + $modal.on 'click', (e) -> + close.apply this if e.target is e.currentTarget - $modalDialog = $modal.children '.modal-dialog' - - # Prevent closing modal when clicking the dialog - $modalDialog.on 'click', (e) -> e.stopPropagation() + # $modalDialog = $modal.children '.modal-dialog' + # + # # Prevent closing modal when clicking the dialog + # $modalDialog.on 'click', (e) -> e.stopPropagation() open = -> $(this).addClass 'modal-open'