(function($) { 'use strict'; var $document = $(document); var $body = $('body'); var $roots = $('html').add($body); var cache = {}; $.modal = function(settings) { function Modal() { var modal = this; var modalCreated = false; modal.isActive = false; var config = $.extend({ content: '', // content to show initial contentUrl: null, // content from an external url (ajax-loaded) useCache: true, // don't repeat ajax-load every time youtubeId: null, // show youtube-iframe class: '', // custom class for modal closeBtn: true, // show x-close-btn layerClose: true, // modal closes when layer is clicked closingSelectors: null, // custom selectors for elements to close modal showOnInit: true, // show modal when created fadeInDuration: 400, // how fast modal fades in fadeOutDuration: 400, // how fast modal fades out beforeModalOpen: null, // callback before modal appears - returns modal afterModalOpen: null, // callback after modal appears - returns modal beforeModalClose: null, // callback before modal disappears - returns modal afterModalClose: null // callback after modal disappears - returns modal }, settings); var init = function() { if (config.showOnInit) modal.open(); }; var createModal = function() { var closingX = ''; var modalClass = 'modal ' + config.class; if (config.youtubeId) { modalClass = modalClass + ' modal-youtube'; } modal.$wrapper = $('
', { class: 'modal-wrapper' }); modal.$layer = $('
', { class: 'modal-layer' }); modal.$modal = $('
', { class: modalClass }); if (config.closeBtn) { modal.$closeBtn = $('