diff --git a/README.md b/README.md index bda6f4c..cefa329 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ -# Modal v1.17.1 +# Modal v1.17.2 Library for opening content in a modal window. Built to be used with web applications and ajax. - Requires jQuery 1.7+ +### new in 1.17.2 + +Added option for preventing modal close when clicking outside of the modal + ### new in 1.17.1 Added support for nested modals. Modal windows will get appended after the last. when nested modals are closed, the previous modal will be displayed until the last one is closed which will destroy the modal elements. @@ -55,6 +59,7 @@ ajax : false, width : false, centered : false, allowClose : true, +allowCloseOverlay : true, afterInit : $.noop, afterOpen : $.noop, afterClose : $.noop, diff --git a/dist/jquery.modal.min.js b/dist/jquery.modal.min.js index a57153a..d89e4d5 100644 --- a/dist/jquery.modal.min.js +++ b/dist/jquery.modal.min.js @@ -1 +1 @@ -!function(t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(window.jQuery)}(function(a){"use strict";var n=function(t,s){this.namespace="modal-"+a.fn.modal2.count,this.$container=a(s.container),this.$selector=t,this.settings=s,this.modalOpen=!1,this.$modal=null,this.$modalInside=null,this.$overlay=null,this.$selector?a(this.$selector).off("click.modal").on("click.modal",a.proxy(this.show,this)):this.show(),a.fn.modal2.count++};n.prototype.addEvents=function(){var s=this;a(this.settings.closeModalName).on("click."+this.namespace,a.proxy(this.close,this)),a(document).on("keydown."+this.namespace,a.proxy(this.close,this)),this.$modal.on("click."+this.namespace,function(t){a(t.target).closest("."+s.settings.modalContentName).length||s.close()})},n.prototype.removeEvents=function(){a(this.settings.closeModalName).off("."+this.namespace),this.$modalInside.off("."+this.namespace),this.$modal.off("."+this.namespace),a(document).off("."+this.namespace)},n.prototype.show=function(t){"object"==typeof t&&t.preventDefault&&(t.preventDefault(),t.stopPropagation()),this.settings.html?(this.append(this.settings.html),this.open(),this.settings.afterInit.call(this,a(this.$selector))):a(this.$selector).data("target")?(this.append(a(a(this.$selector).data("target")).html()),this.open(),this.settings.afterInit.call(this,a(this.$selector))):this.settings.ajax&&"string"==typeof this.settings.ajax.url?(this.append(),this.load(this.settings.ajax.url),this.settings.afterInit.call(this,a(this.$selector))):a(this.$selector).attr("href")?(this.append(),this.load(a(this.$selector).attr("href")),this.settings.afterInit.call(this,a(this.$selector))):this.close()},n.prototype.close=function(t){var s,e=this,o=!1;if(this.modalOpen){if("object"==typeof t){if(o=t.type,"keydown"===t.type&&(27!==t.keyCode||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey))return;t.preventDefault(),t.stopPropagation()}s=this.$modal.children("."+this.settings.modalDialogName).length,(this.settings.allowClose||"closeModal"===o||"ajaxComplete"===o)&&(this.settings.onBeforeClose.call(this,a(this.$selector)),this.modalOpen=!1,1'),this.$overlay=e.length&&e||a('
'),this.$modalDialog=a('
'),this.$modalInside=a('
'),this.$closeBtn=a(this.settings.closeModalName,this.$modalInside),this.$modalDialog.append(this.$modalInside),this.$modal.append(this.$modalDialog),t&&this.$modalInside.empty().append(t),this.settings.centered&&this.$modal.addClass("modal-centered"),"body"===this.settings.container&&this.$modal.addClass("fixed"),this.settings.width&&this.$modalDialog.css({"max-width":this.settings.width}),this.$container.append(this.$overlay),this.$container.append(this.$modal),this.$overlay.show(),this.$modal.show()};var s=function(t,s){var e=a(t);if((t=e).is(document)&&(t=!1),"object"==typeof s||void 0===s){var o=new n(t,s);e.data("modal",o)}else if("string"==typeof s){var i=e.data("modal");"object"==typeof i&&"close"===s&&a.isFunction(i.close)&&i.close()}};return a.fn.modal2=function(t){return"string"!=typeof t&&(t=a.extend(!0,{},a.fn.modal2.defaults,t)),this.each(function(){return s(this,t),this})},a.modal2=function(t){return"string"!=typeof t&&(t=a.extend(!0,{},a.fn.modal2.defaults,t)),s(document,t),this},a.fn.modal2.count=0,a.fn.modal2.defaults={closeModalName:'[data-dismiss="modal2"]',backdropName:"modal-backdrop",modalDialogName:"modal-dialog",modalContentName:"modal-content",modalSkin:"default",modalName:"modal",container:"body",html:!1,ajax:!1,width:!1,centered:!1,allowClose:!0,afterInit:a.noop,afterOpen:a.noop,afterClose:a.noop,onBeforeClose:a.noop},a.modal2}); \ No newline at end of file +!function(t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(window.jQuery)}(function(a){"use strict";var n=function(t,s){this.namespace="modal-"+a.fn.modal2.count,this.$container=a(s.container),this.$selector=t,this.settings=s,this.modalOpen=!1,this.$modal=null,this.$modalInside=null,this.$overlay=null,this.$selector?a(this.$selector).off("click.modal").on("click.modal",a.proxy(this.show,this)):this.show(),a.fn.modal2.count++};n.prototype.addEvents=function(){var s=this;a(this.settings.closeModalName).on("click."+this.namespace,a.proxy(this.close,this)),a(document).on("keydown."+this.namespace,a.proxy(this.close,this)),this.settings.allowCloseOverlay&&this.$modal.on("click."+this.namespace,function(t){a(t.target).closest("."+s.settings.modalContentName).length||s.close()})},n.prototype.removeEvents=function(){a(this.settings.closeModalName).off("."+this.namespace),this.$modalInside.off("."+this.namespace),this.$modal.off("."+this.namespace),a(document).off("."+this.namespace)},n.prototype.show=function(t){"object"==typeof t&&t.preventDefault&&(t.preventDefault(),t.stopPropagation()),this.settings.html?(this.append(this.settings.html),this.open(),this.settings.afterInit.call(this,a(this.$selector))):a(this.$selector).data("target")?(this.append(a(a(this.$selector).data("target")).html()),this.open(),this.settings.afterInit.call(this,a(this.$selector))):this.settings.ajax&&"string"==typeof this.settings.ajax.url?(this.append(),this.load(this.settings.ajax.url),this.settings.afterInit.call(this,a(this.$selector))):a(this.$selector).attr("href")?(this.append(),this.load(a(this.$selector).attr("href")),this.settings.afterInit.call(this,a(this.$selector))):this.close()},n.prototype.close=function(t){var s,e=this,o=!1;if(this.modalOpen){if("object"==typeof t){if(o=t.type,"keydown"===t.type&&(27!==t.keyCode||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey))return;t.preventDefault(),t.stopPropagation()}s=this.$modal.children("."+this.settings.modalDialogName).length,(this.settings.allowClose||"closeModal"===o||"ajaxComplete"===o)&&(this.settings.onBeforeClose.call(this,a(this.$selector)),this.modalOpen=!1,1'),this.$overlay=e.length&&e||a('
'),this.$modalDialog=a('
'),this.$modalInside=a('
'),this.$closeBtn=a(this.settings.closeModalName,this.$modalInside),this.$modalDialog.append(this.$modalInside),this.$modal.append(this.$modalDialog),t&&this.$modalInside.empty().append(t),this.settings.centered&&this.$modal.addClass("modal-centered"),"body"===this.settings.container&&this.$modal.addClass("fixed"),this.settings.width&&this.$modalDialog.css({"max-width":this.settings.width}),this.$container.append(this.$overlay),this.$container.append(this.$modal),this.$overlay.show(),this.$modal.show()};var s=function(t,s){var e=a(t);if((t=e).is(document)&&(t=!1),"object"==typeof s||void 0===s){var o=new n(t,s);e.data("modal",o)}else if("string"==typeof s){var i=e.data("modal");"object"==typeof i&&"close"===s&&a.isFunction(i.close)&&i.close()}};return a.fn.modal2=function(t){return"string"!=typeof t&&(t=a.extend(!0,{},a.fn.modal2.defaults,t)),this.each(function(){return s(this,t),this})},a.modal2=function(t){return"string"!=typeof t&&(t=a.extend(!0,{},a.fn.modal2.defaults,t)),s(document,t),this},a.fn.modal2.count=0,a.fn.modal2.defaults={closeModalName:'[data-dismiss="modal2"]',modalContentName:"modal-content",modalDialogName:"modal-dialog",backdropName:"modal-backdrop",allowCloseOverlay:!0,onBeforeClose:a.noop,modalSkin:"default",modalName:"modal",afterClose:a.noop,container:"body",afterInit:a.noop,afterOpen:a.noop,allowClose:!0,centered:!1,width:!1,html:!1,ajax:!1},a.modal2}); \ No newline at end of file diff --git a/src/jquery.modal.js b/src/jquery.modal.js index d22cd87..f6b8f4a 100755 --- a/src/jquery.modal.js +++ b/src/jquery.modal.js @@ -42,11 +42,13 @@ $(this.settings.closeModalName).on('click.' + this.namespace, $.proxy(this.close, this)); $(document).on('keydown.' + this.namespace, $.proxy(this.close, this)); - this.$modal.on('click.' + this.namespace, function (e) { - if (!$(e.target).closest('.' + self.settings.modalContentName).length) { - self.close(); - } - }); + if (this.settings.allowCloseOverlay) { + this.$modal.on('click.' + this.namespace, function (e) { + if (!$(e.target).closest('.' + self.settings.modalContentName).length) { + self.close(); + } + }); + } }; Modal.prototype.removeEvents = function () { @@ -341,21 +343,22 @@ // Set options obj $.fn.modal2.defaults = { closeModalName: '[data-dismiss="modal2"]', - backdropName: 'modal-backdrop', - modalDialogName: 'modal-dialog', modalContentName: 'modal-content', + modalDialogName: 'modal-dialog', + backdropName: 'modal-backdrop', + allowCloseOverlay: true, + onBeforeClose: $.noop, modalSkin: 'default', modalName: 'modal', + afterClose: $.noop, container: 'body', - html: false, - ajax: false, - width: false, - centered: false, - allowClose: true, afterInit: $.noop, afterOpen: $.noop, - afterClose: $.noop, - onBeforeClose: $.noop + allowClose: true, + centered: false, + width: false, + html: false, + ajax: false, }; // return for module loader