(function($){ // init var acfe = {}; window.acfe = acfe; acfe.modal = { modals: [], // Open open: function($target, args){ args = acf.parseArgs(args, { title: '', footer: false, size: false, destroy: false, onClose: false, }); $target.addClass('-open'); if(args.size){ $target.addClass('-' + args.size); } if(!$target.find('> .acfe-modal-wrapper').length){ $target.wrapInner('
'); } if(!$target.find('> .acfe-modal-wrapper > .acfe-modal-content').length){ $target.find('> .acfe-modal-wrapper').wrapInner('
'); } $target.find('> .acfe-modal-wrapper').prepend('
' + args.title + '
'); $target.find('.acfe-modal-title > .close').click(function(e){ e.preventDefault(); acfe.modal.close(args); }); if(args.footer){ $target.find('> .acfe-modal-wrapper').append(''); $target.find('.acfe-modal-footer > button').click(function(e){ e.preventDefault(); acfe.modal.close(args); }); } acfe.modal.modals.push($target); var $body = $('body'); if(!$body.hasClass('acfe-modal-opened')){ var overlay = $('
').click(function(){ acfe.modal.close(args); }); $body.addClass('acfe-modal-opened').append(overlay); } acfe.modal.multiple(); return $target; }, // Close close: function(args){ var $target = acfe.modal.modals.pop(); $target.find('.acfe-modal-title').remove(); $target.find('.acfe-modal-footer').remove(); $target.removeAttr('style'); $target.removeClass('-open -small -full'); if(args.destroy){ $target.remove(); } if(!acfe.modal.modals.length){ $('.acfe-modal-overlay').remove(); $('body').removeClass('acfe-modal-opened'); } acfe.modal.multiple(); acfe.modal.onClose($target, args); }, // Multiple multiple: function(){ var last = acfe.modal.modals.length - 1; $.each(acfe.modal.modals, function(i){ if(last == i){ $(this).css('margin-left', ''); return; } $(this).css('margin-left', - (500 / (i+1))); }); }, onClose: function($target, args){ if(!args.onClose || !(args.onClose instanceof Function)) return; args.onClose($target); } }; })(jQuery);