-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmModal.min.js
1 lines (1 loc) · 3.19 KB
/
mModal.min.js
1
(function(a){a.fn.mModal=function(c){var g=a.extend({modal:null,contentUrl:"",callbacks:[],appearAnimation:"fade",disappearAnimation:"fade",appearSlideDirection:"down",disappearSlideDirection:"up",animateResize:true,closeButton:true},c);if(g.modal==null||typeof g.modal=="undefined"){console.error("The given modal was not set or found!");return false}var h=a(this);var f=g.modal.find(".mModal-content");var e=g.modal.find(".mModal-buttons").children();var b=(g.closeButton)?a('<div class="mModal-close"></div>').appendTo(g.modal):a();var d=null;g.modal.off("click").click(function(i){i.stopImmediatePropagation()}).hide();e.outerWidth(g.modal.width()/e.length);g.modal.openModal=function(){if(g.contentUrl.length>0){var j=g.contentUrl.match(/(http(s)?:\/\/)?(www\.)?youtu(\.)?be(.+)?v=(.+)/i);if(j!=null){var i=a('<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'+j[6]+'?rel=0&showinfo=0&autoplay=1" frameborder="0"></iframe>').appendTo(f).hide();i.load(function(){a(this).delay(100).fadeIn("slow")})}else{f.load(g.contentUrl)}f.outerHeight(g.modal.outerHeight());g.modal.centerModal()}d=g.modal.wrap(a('<div class="mModal-cover"></div>')).parent();d.off("click").click(function(k){g.modal.closeModal()}).hide();if(g.appearAnimation=="slide"){d.fadeIn("fast",function(){g.modal.show();var k=(a(window).outerWidth()/2)-(g.modal.outerWidth()/2);var l=(a(window).outerHeight()/2)-(g.modal.outerHeight()/2);var n=(g.appearSlideDirection=="left"||g.appearSlideDirection=="right")?(g.appearSlideDirection=="left"?(a(window).outerWidth()):(-k)):k;var m=(g.appearSlideDirection=="up"||g.appearSlideDirection=="down")?(g.appearSlideDirection=="up"?(a(window).outerHeight()):(-l)):l;g.modal.css({left:n,top:m});g.modal.stop(true,false).animate({left:k,top:l})})}else{d.fadeIn("fast");g.modal.show()}e.off("click").click(function(l){l.preventDefault();var k=a(this).attr("data-mModalCallback");if(typeof k=="undefined"){return false}if(typeof g.callbacks[k]!="undefined"){g.callbacks[k](g.modal)}})};g.modal.centerModal=function(){var i=(a(window).outerWidth()/2)-(g.modal.outerWidth()/2);var j=(a(window).outerHeight()/2)-(g.modal.outerHeight()/2);if(g.animateResize==true){g.modal.stop(true,false).animate({left:i,top:j},"fast","swing")}else{g.modal.css({left:i,top:j})}};g.modal.closeModal=function(){if(g.disappearAnimation=="slide"){var i=(a(window).outerWidth()/2)-(g.modal.outerWidth()/2);var l=(a(window).outerHeight()/2)-(g.modal.outerHeight()/2);var k=(g.disappearSlideDirection=="left"||g.disappearSlideDirection=="right")?(g.disappearSlideDirection=="left"?(-i):(a(window).outerWidth())):i;var j=(g.disappearSlideDirection=="up"||g.disappearSlideDirection=="down")?(g.disappearSlideDirection=="up"?(-l):(a(window).outerHeight())):l;g.modal.stop(true,false).animate({left:k,top:j},"fast","swing",function(){d.fadeOut("fast",function(){g.modal.hide();g.modal.unwrap();if(g.contentUrl.length>0){f.empty()}})})}else{d.fadeOut("fast",function(){g.modal.hide();g.modal.unwrap();if(g.contentUrl.length>0){f.empty()}})}};h.click(function(i){i.preventDefault();g.modal.openModal()});b.off("click").click(function(i){i.preventDefault();g.modal.closeModal()});a(window).resize(function(i){g.modal.centerModal()}).trigger("resize")}}(jQuery));