Comparing version 1.4.0 to 1.5.0
@@ -6,4 +6,27 @@ /** | ||
var ESC_KEY_NAMESPACE = 'rkd-modal-escape'; | ||
/** | ||
* Get global rkdModal config value by key | ||
* | ||
* @param {string} key Key to retrieve value for | ||
* | ||
* @return {mixed} | ||
*/ | ||
var getRkdConfig = function(key) { | ||
if (!window.rkdModal || !(key in window.rkdModal)) { | ||
return null; | ||
} | ||
return window.rkdModal[key]; | ||
}; | ||
/** | ||
* Detect if ESC key should close modal | ||
* | ||
* Default: true | ||
* | ||
* @return {boolean} True if closing withg ESC key is enabled | ||
*/ | ||
var isEscKeyEnabled = function() { | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
return getRkdConfig('escKey') === null ? true : getRkdConfig('escKey') !== false; | ||
}; | ||
@@ -44,5 +67,15 @@ | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function(e) { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
var close = true; | ||
// Detect if background click should close modal | ||
if ($(e.target).is('.modal-fade-screen') && getRkdConfig('backgroundClickClose') === false) { | ||
close = false; | ||
} | ||
if (close) { | ||
closeModal($modal); | ||
} | ||
}); | ||
@@ -49,0 +82,0 @@ |
@@ -1,2 +0,2 @@ | ||
var ESC_KEY=27,ESC_KEY_NAMESPACE="rkd-modal-escape",isEscKeyEnabled=function(){return!window.rkdModal||window.rkdModal.escKey};$(function(){var a=function(a){$(document).trigger("rkd-modal:before:open",a),a.addClass("modal-open"),a.find("input.modal-state").prop("checked",!0).trigger("change"),isEscKeyEnabled()&&$(document).on("keyup."+ESC_KEY_NAMESPACE,function(c){c.keyCode===ESC_KEY&&b(a)}),$(document).trigger("rkd-modal:after:open",a)},b=function(a){$(document).trigger("rkd-modal:before:close",a),a.removeClass("modal-open"),a.find("input.modal-state").prop("checked",!1).trigger("change"),isEscKeyEnabled()&&$(document).unbind("keyup."+ESC_KEY_NAMESPACE),$(document).trigger("rkd-modal:after:close",a)};$(document).on("click",".modal-fade-screen, .modal-close",function(){var a=$(this).closest(".modal");b(a)}),$(document).on("click",".modal-inner",function(a){a.stopPropagation()}),$(document).on("click",".rkd-modal",function(b){b.preventDefault();var c=$("#"+$(this).data("rkd-modal-id"));a(c)}),$(document).on("click",".rkd-modal-ajax, .rkd-modal-this",function(b){b.preventDefault();var c,d=$(this).data("rkd-modal-id");d?c=$("#"+d):(c=createAjaxModal(),$(this).data("rkd-modal-id",c.attr("id")));var e=c.find(".loading");if(a(c),$(this).hasClass("rkd-modal-this"))return c.find(".modal-content").html($(this).html()),$(document).trigger("rkd-modal:content:loaded",c),void e.hide();if(!c.hasClass("content-loaded")){var f=$(this).data("rkd-modal-selector");e.show(),$.ajax($(this).attr("href")).done(function(a){f?a=$(a).find(f):$(a).find(".rkd-modal-content")&&(a=$(a).find(".rkd-modal-content")),c.find(".modal-content").html(a),$(document).trigger("rkd-modal:content:loaded",c),c.addClass("content-loaded")}).fail(function(){c.find(".modal-content").html("Something went wrong. Please try again later.")}).always(function(){e.hide()})}})});var createAjaxModal=function(){var a="_"+Math.random().toString(36).substr(2,9),b='<div class="modal rkd-modal" id="'+a+'"><input class="modal-state" type="checkbox" /><div class="modal-fade-screen"><div class="modal-inner"><!-- Close button--><div class="modal-close"></div><!-- Loader --><div class="sk-three-bounce loading"><div class="sk-child sk-bounce1"></div><div class="sk-child sk-bounce2"></div><div class="sk-child sk-bounce3"></div></div><!-- Content will be loaded in here with AJAX --><div class="modal-content"></div></div></div></div>';return $("body").append(b),$("#"+a)}; | ||
var ESC_KEY=27,ESC_KEY_NAMESPACE="rkd-modal-escape",getRkdConfig=function(a){return window.rkdModal&&a in window.rkdModal?window.rkdModal[a]:null},isEscKeyEnabled=function(){return null===getRkdConfig("escKey")||getRkdConfig("escKey")!==!1};$(function(){var a=function(a){$(document).trigger("rkd-modal:before:open",a),a.addClass("modal-open"),a.find("input.modal-state").prop("checked",!0).trigger("change"),isEscKeyEnabled()&&$(document).on("keyup."+ESC_KEY_NAMESPACE,function(c){c.keyCode===ESC_KEY&&b(a)}),$(document).trigger("rkd-modal:after:open",a)},b=function(a){$(document).trigger("rkd-modal:before:close",a),a.removeClass("modal-open"),a.find("input.modal-state").prop("checked",!1).trigger("change"),isEscKeyEnabled()&&$(document).unbind("keyup."+ESC_KEY_NAMESPACE),$(document).trigger("rkd-modal:after:close",a)};$(document).on("click",".modal-fade-screen, .modal-close",function(a){var c=$(this).closest(".modal"),d=!0;$(a.target).is(".modal-fade-screen")&&getRkdConfig("backgroundClickClose")===!1&&(d=!1),d&&b(c)}),$(document).on("click",".modal-inner",function(a){a.stopPropagation()}),$(document).on("click",".rkd-modal",function(b){b.preventDefault();var c=$("#"+$(this).data("rkd-modal-id"));a(c)}),$(document).on("click",".rkd-modal-ajax, .rkd-modal-this",function(b){b.preventDefault();var c,d=$(this).data("rkd-modal-id");d?c=$("#"+d):(c=createAjaxModal(),$(this).data("rkd-modal-id",c.attr("id")));var e=c.find(".loading");if(a(c),$(this).hasClass("rkd-modal-this"))return c.find(".modal-content").html($(this).html()),$(document).trigger("rkd-modal:content:loaded",c),void e.hide();if(!c.hasClass("content-loaded")){var f=$(this).data("rkd-modal-selector");e.show(),$.ajax($(this).attr("href")).done(function(a){f?a=$(a).find(f):$(a).find(".rkd-modal-content")&&(a=$(a).find(".rkd-modal-content")),c.find(".modal-content").html(a),$(document).trigger("rkd-modal:content:loaded",c),c.addClass("content-loaded")}).fail(function(){c.find(".modal-content").html("Something went wrong. Please try again later.")}).always(function(){e.hide()})}})});var createAjaxModal=function(){var a="_"+Math.random().toString(36).substr(2,9),b='<div class="modal rkd-modal" id="'+a+'"><input class="modal-state" type="checkbox" /><div class="modal-fade-screen"><div class="modal-inner"><!-- Close button--><div class="modal-close"></div><!-- Loader --><div class="sk-three-bounce loading"><div class="sk-child sk-bounce1"></div><div class="sk-child sk-bounce2"></div><div class="sk-child sk-bounce3"></div></div><!-- Content will be loaded in here with AJAX --><div class="modal-content"></div></div></div></div>';return $("body").append(b),$("#"+a)}; | ||
//# sourceMappingURL=rkd-modal.min.js.map |
{ | ||
"name": "rkd-modal", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Plain content and AJAX supported modal.", | ||
"main": "Gruntfile.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "./node_modules/.bin/cypress open", | ||
"serve": "./node_modules/.bin/node-http-server" | ||
}, | ||
@@ -29,7 +30,8 @@ "repository": { | ||
"bourbon": "^4.3.4", | ||
"bourbon-neat": "^1.9.1", | ||
"grunt": "^1.0.3", | ||
"bourbon-neat": "^3.0.1", | ||
"cypress": "^3.2.0", | ||
"grunt": "^1.0.4", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-cssmin": "^1.0.1", | ||
"grunt-contrib-cssmin": "^3.0.0", | ||
"grunt-contrib-jshint": "^1.1.0", | ||
@@ -39,8 +41,9 @@ "grunt-contrib-sass": "^1.0.0", | ||
"grunt-contrib-watch": "^1.1.0", | ||
"grunt-sass": "^1.1.0", | ||
"grunt-sass": "^3.0.2", | ||
"grunt-sass-lint": "^0.1.0", | ||
"jquery": "^3.3.1", | ||
"jquery": "^3.4.1", | ||
"load-grunt-tasks": "^3.5.0", | ||
"merge": ">=1.2.1", | ||
"sass-lint": "^1.12.1", | ||
"node-http-server": "^8.1.2", | ||
"sass-lint": "^1.13.1", | ||
"spinkit": "^1.2.5" | ||
@@ -47,0 +50,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
[![Build Status](https://travis-ci.org/renekorss/rkd-modal.svg?branch=master)](https://travis-ci.org/renekorss/rkd-modal) | ||
[![npm version](https://badge.fury.io/js/rkd-modal.svg)](https://badge.fury.io/js/rkd-modal) | ||
@@ -93,13 +94,14 @@ [![npm](https://img.shields.io/npm/dt/rkd-modal.svg)](https://www.npmjs.com/package/rkd-modal) | ||
# Disable ESC key from closing modal | ||
# Configure what actions closes modal | ||
Just create `window.rkdModal` global object and set `escKey` to `false`. | ||
Just create `window.rkdModal` global object and set config as you wish. | ||
````javascript | ||
window.rkdModal = { | ||
escKey: false | ||
escKey: false, // Disable/enable ESC key from closing modal. Default: true | ||
backgroundClickClose: false // Disable/enable background click from closing modal. Default: true | ||
}; | ||
```` | ||
It gets validated on every modal open, so you could change this setting whenever you need. | ||
It gets validated on every modal open, so you could change these settings whenever you need. | ||
@@ -106,0 +108,0 @@ # Customise |
@@ -6,4 +6,27 @@ /** | ||
var ESC_KEY_NAMESPACE = 'rkd-modal-escape'; | ||
/** | ||
* Get global rkdModal config value by key | ||
* | ||
* @param {string} key Key to retrieve value for | ||
* | ||
* @return {mixed} | ||
*/ | ||
var getRkdConfig = function(key) { | ||
if (!window.rkdModal || !(key in window.rkdModal)) { | ||
return null; | ||
} | ||
return window.rkdModal[key]; | ||
}; | ||
/** | ||
* Detect if ESC key should close modal | ||
* | ||
* Default: true | ||
* | ||
* @return {boolean} True if closing withg ESC key is enabled | ||
*/ | ||
var isEscKeyEnabled = function() { | ||
return !window.rkdModal || window.rkdModal.escKey; | ||
return getRkdConfig('escKey') === null ? true : getRkdConfig('escKey') !== false; | ||
}; | ||
@@ -44,5 +67,15 @@ | ||
// Close modal on close button and clicking outside of modal | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function() { | ||
$(document).on("click", ".modal-fade-screen, .modal-close", function(e) { | ||
var $modal = $(this).closest('.modal'); | ||
closeModal($modal); | ||
var close = true; | ||
// Detect if background click should close modal | ||
if ($(e.target).is('.modal-fade-screen') && getRkdConfig('backgroundClickClose') === false) { | ||
close = false; | ||
} | ||
if (close) { | ||
closeModal($modal); | ||
} | ||
}); | ||
@@ -49,0 +82,0 @@ |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
72297
29
751
0
114
19