// Generated by CoffeeScript 1.4.0 /* * * jQuery Modals by Gary Hepting * https://github.com/ghepting/modal * * Based on Avgrund by Hakim El Hattab <3 * */ (function() { (function($) { var elems, modals; if ($('div#iframeModal').length < 1) { $('body').append('
'); $('div#iframeModal').prepend('').prepend(''); } $('a.modal').each(function() { $(this).attr('data-url', $(this).attr('href')); return $(this).attr('href', '#iframeModal'); }); $('a.modal').on("click", function(e) { $('div#iframeModal iframe').replaceWith(''); e.preventDefault(); return false; }); elems = []; $.fn.modal = function() { this.each(function() { $(this).not('#iframeModal').wrapInner(''); $(this).prepend('').prepend('').appendTo('body'); return $('[href=#' + $(this).attr('id') + ']').on("click", function(e) { modals.open($(this).attr('href')); e.preventDefault(); return false; }); }); $('div.modal .close').on("click", function() { return modals.close(); }); return $('div.modal .fullscreen').on("click", function() { return modals.fullscreen($(this).parent('div.modal')); }); }; modals = (function() { var close, fullscreen, open; $('html').addClass('modal-ready'); if ($("#overlay").length < 1) { $('body').append(''); } $('#overlay, div.modal .close').bind("click", function(e) { return close(); }); open = function(elem) { $(window).bind("keydown", function(e) { var keyCode; keyCode = (e.which ? e.which : e.keyCode); if (keyCode === 27) { return close(); } }); $(elem).addClass("active"); if (!$(elem).hasClass('iframe')) { $(elem).css({ width: 'auto', height: 'auto' }); $(elem).css({ height: $(elem).outerHeight() }); } $(elem).css({ top: '50%', left: '50%', 'margin-top': ($(elem).outerHeight() / -2) + 'px', 'margin-left': ($(elem).outerWidth() / -2) + 'px' }); setTimeout(function() { return $('html').addClass("modal-active"); }, 0); setTimeout(function() { return $('html').removeClass('modal-ready'); }, 400); }; close = function() { var modal; modal = $('div.modal.active'); $(window).unbind("keydown"); $('html').removeClass("modal-active").addClass('modal-ready'); if (modal.hasClass('iframe')) { $('div#iframeModal iframe').replaceWith(''); modal.css({ width: '80%', height: '80%' }); } else { modal.css({ width: 'auto', height: 'auto' }); } modal.css({ top: '10%', left: '10%', 'max-width': '80%', 'max-height': '80%', 'margin-top': 0, 'margin-left': 0 }); modal.removeClass("active").removeClass("fullscreen"); $('i.fullscreen', modal).removeClass('icon-resize-small').addClass('icon-resize-full'); }; fullscreen = function(elem) { if ($('div.modal.active').hasClass('fullscreen')) { $('div.modal i.fullscreen').removeClass('icon-resize-small').addClass('icon-resize-full'); if ($('div.modal.active').hasClass('iframe')) { $('div.modal.active').css({ width: '80%', height: '80%' }); } else { $('div.modal.active').css({ width: 'auto', height: 'auto' }); $('div.modal.active').css({ height: $('div.modal.active').outerHeight() }); } $('div.modal.active').removeClass('fullscreen').css({ 'max-width': '80%', 'max-height': '80%' }); $('div.modal.active').delay(100).css({ top: '50%', left: '50%', 'margin-top': ($('div.modal.active').outerHeight() / -2) + 'px', 'margin-left': ($('div.modal.active').outerWidth() / -2) + 'px' }); } else { $('div.modal i.fullscreen').addClass('icon-resize-small').removeClass('icon-resize-full'); $('div.modal.active').addClass('fullscreen').css({ top: 0, left: 0, 'margin-top': 0, 'margin-left': 0, width: '100%', height: '100%', 'max-width': '100%', 'max-height': '100%' }); } }; return { open: open, close: close, fullscreen: fullscreen }; })(); return $(window).resize(function() { return $('div.modal.active').each(function() { if (!$(this).hasClass('fullscreen')) { $(this).removeClass('active').css({ top: '50%', left: '50%', 'margin-top': ($(this).outerHeight() / -2) + 'px', 'margin-left': ($(this).outerWidth() / -2) + 'px' }).addClass('active'); if (!$(this).hasClass('iframe')) { $(this).css({ height: 'auto' }); return $(this).css({ height: $(this).outerHeight() }); } } }); }); })(jQuery); }).call(this);