(function ($) {
var methods = {
init: function (options) {
methods.settings = $.extend({
'fade': false
}, options);
return this.each(function () {
var $target = $(this);
$target.on('click', $target, function (e) {
e.stopPropagation();
e.preventDefault();
methods.generateModal($target);
methods.bindCloseModal();
});
});
},
/**
* @method bindCloseModal
* This binds the escape key and the click of the modal overlay
* to the teardown() method
*/
bindCloseModal : function() {
var $body = $('body');
$body.on('click.modal', function (e) {
e.stopPropagation();
if ($('.modal-outer').has(e.target).length === 0) {
methods.teardown();
}
}).on('keyup.modal', function (e) {
e.stopPropagation();
if (e.keyCode === 27) {
methods.teardown();
}
});
},
/**
* @method teardown
* Destroys the modal
*/
teardown: function () {
var $body = $('body');
var revertModalContent = function () {
// Move the container back out of the modal, since it gets destroyed
if (!methods.settings.fetch) {
$('#' + methods.settings.contentId).hide().appendTo($('body'));
}
};
var destroyModal = function () {
$body.unbind('click.modal');
$body.unbind('keyup.modal');
revertModalContent();
$('.modal-outer').remove();
$('#modal-overlay').remove();
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.