-
Notifications
You must be signed in to change notification settings - Fork 50
/
popModal.min.js
42 lines (42 loc) · 18.7 KB
/
popModal.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
popModal - 1.26 [27.10.17]
Author: vadimsva
Github: https://github.com/vadimsva/popModal
*/
$(function(){(function(a){a.fn.popModal=function(c){function f(){function b(a){var b=Math.max(u,v,w);return("bottomLeft"==a?0<v:"bottomRight"==a?0<u:0<w)?a:0<v&&v==b?"bottomLeft":0<u&&u==b?"bottomRight":0<w&&w==b?"bottomCenter":a}if(e.inline)var g=d.position().left,c=d.position().top;else g=d.offset().left,c=d.offset().top;var k=parseInt(d.css("marginLeft"));parseInt(d.css("paddingLeft"));var f=parseInt(d.css("marginTop")),p=d.outerHeight(),m=d.outerWidth(),n=h.outerWidth(),q=h.outerHeight(),l,r=
d.offset().left,A=a(window).width()-d.offset().left-m,C=d.offset().top,D=r-10-n,u=m+r-n,E=A-10-n,v=m+A-n,w=Math.min(m/2+A-n/2,m/2+r-n/2);r=C-q/2;if(/^top/.test(e.placement)||""==e.placement)e.placement="bottomLeft";/^bottom/.test(e.placement)?l=b(e.placement):/^left/.test(e.placement)?l=0<D?"leftCenter"==e.placement&&0<r?"leftCenter":"leftTop":b("bottomLeft"):/^right/.test(e.placement)&&(l=0<E?"rightCenter"==e.placement&&0<r?"rightCenter":"rightTop":b("bottomRight"));h.removeAttr("class").addClass("popModal animated "+
l);switch(l){case "bottomLeft":h.css({top:c+f+p+10+"px",left:g+k+"px"}).addClass("fadeInBottom");break;case "bottomRight":h.css({top:c+f+p+10+"px",left:g+k+m-n+"px"}).addClass("fadeInBottom");break;case "bottomCenter":h.css({top:c+f+p+10+"px",left:g+k+(m-n)/2+"px"}).addClass("fadeInBottom");break;case "leftTop":h.css({top:c+f+"px",left:g+k-n-10+"px"}).addClass("fadeInLeft");break;case "rightTop":h.css({top:c+f+"px",left:g+k+m+10+"px"}).addClass("fadeInRight");break;case "leftCenter":h.css({top:c+
f+p/2-q/2+"px",left:g+k-n-10+"px"}).addClass("fadeInLeft");break;case "rightCenter":h.css({top:c+f+p/2-q/2+"px",left:g+k+m+10+"px"}).addClass("fadeInRight")}}function g(){h=a("div[data-popmodal]");d.removeAttr("data-popmodal_id");h.length&&(b(),q||(q=h.css("animationDuration"),q=void 0!==q?1E3*q.replace("s",""):0),setTimeout(function(){a(".popModal_source").replaceWith(a(".popModal_content").children());h.remove();a("html.popModalOpen").off(".popModalEvent").removeClass("popModalOpen")},q))}function b(){var a=
h.attr("class"),b=a.replace("fadeIn","fadeOut");h.removeClass(a).addClass(b)}var d=a(this),h,n="",p="",m,e,q,k,l={init:function(b){e=a.extend({html:"",placement:"bottomLeft",showCloseBut:!0,onDocumentClickClose:!0,onDocumentClickClosePrevent:"",overflowContent:!1,inline:!0,asMenu:!1,size:"",onOkBut:function(){return!0},onCancelBut:function(){},onLoad:function(){},onClose:function(){}},b);if(0!==a("body").find("div[data-popmodal]").length&&a("body").find("div[data-popmodal]").attr("data-popmodal_id")==
d.attr("data-popmodal_id"))g();else{a("html.popModalOpen").off(".popModalEvent").removeClass("popModalOpen");a(".popModal_source").replaceWith(a(".popModal_content").children());a(".popModal").remove();e.asMenu?m=" popModal_asMenu":(m="",e.showCloseBut&&(n=a('<button type="button" class="close">×</button>')),e.overflowContent&&(p=" popModal_contentOverflow"));k=(new Date).getMilliseconds();d.attr("data-popmodal_id",k);b=a('<div class="popModal animated" style="'+("fixed"==d.css("position")?
"position:fixed;":"")+'" data-popmodal_id="'+k+'" data-popmodal="open"></div>');var c=a('<div class="popModal_content'+p+m+'"></div>');b.append(n,c);if(a.isPlainObject(e.html)){c.append(e.html.loadingText);var l={url:e.html.url};e.html.method&&(l.method=e.html.method);e.html.data&&(l.data=e.html.data);e.html.dataType&&(l.dataType=e.html.dataType);a.ajax(l).done(function(a){c.empty().append(a)}).fail(function(){e.html.errorText&&c.empty().append(e.html.errorText)})}else"object"==a.type(e.html)?e.html.after(a('<div class="popModal_source"></div>')):
"string"==a.type(e.html)&&(e.html=a("<div></div>").append(e.html)),c.append(e.html);500>=a(window).width()&&(e.inline=!0);e.inline?d.after(b):a("body").append(b);c[0].scrollWidth>c[0].offsetWidth&&""==e.size&&(b.css({maxWidth:"400px"}),c.addClass("popModal_contentOverflow"));if(a.isPlainObject(e.size)||/^{/i.test(e.size))/^{/i.test(e.size)&&(e.size=a.parseJSON(e.size.replace(new RegExp(/'/,"g"),'"'))),e.size.width&&b.css({maxWidth:e.size.width+"px"}),e.size.height&&(c.addClass("popModal_contentOverflow"),
c.css({maxHeight:e.size.height+"px"}));h=a("div[data-popmodal]");b=h.find(".popModal_footer");0!=b.length&&h.find(".popModal_content").css({marginBottom:b.outerHeight()+15+"px"});if(e.onLoad&&a.isFunction(e.onLoad))e.onLoad(h);a(e.html).trigger("load",{el:h});h.on("destroyed",function(){if(e.onClose&&a.isFunction(e.onClose))e.onClose(h);a(e.html).trigger("close",{el:h})});f();if(e.onDocumentClickClose)a("html").on("click.popModalEvent",function(b){a(this).addClass("popModalOpen");h.is(":hidden")&&
g();var c=a(b.target);c.parents().addBack().is(".popModal")||c.parents().addBack().is(d)||(b=parseInt(c.parents().filter(function(){return"auto"!==a(this).css("zIndex")}).first().css("zIndex")),isNaN(b)&&(b=0),""!==e.onDocumentClickClosePrevent&&c.is(e.onDocumentClickClosePrevent)&&(b=9999),c=c.css("zIndex"),"auto"==c&&(c=0),b<c&&(b=c),b<=h.css("zIndex")&&g())});a(window).resize(function(){f()});h.find(".close").on("click",function(){g();a(this).off("click")});h.find('[data-popmodal-but="close"]').on("click",
function(){g();a(this).off("click")});h.find('[data-popmodal-but="ok"]').on("click",function(b){var c;e.onOkBut&&a.isFunction(e.onOkBut)&&(c=e.onOkBut(b,h));!1!==c&&g();a(this).off("click");a(e.html).trigger("okbut",{event:b,el:h})});h.find('[data-popmodal-but="cancel"]').on("click",function(b){if(e.onCancelBut&&a.isFunction(e.onCancelBut))e.onCancelBut(b,h);g();a(this).off("click");a(e.html).trigger("cancelbut",{event:b,el:h})});a("html").on("keydown.popModalEvent",function(a){27==a.keyCode&&g()})}return h},
hide:function(){g()}};if(l[c])return l[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return l.init.apply(this,arguments)};a("* [data-popmodal-bind]").bind("click",function(){var c=a(this).attr("data-popmodal-bind");c={html:a(c)};void 0!==a(this).attr("data-placement")&&(c.placement=a(this).attr("data-placement"));void 0!==a(this).attr("data-showclose-but")&&(c.showCloseBut=/^true$/i.test(a(this).attr("data-showclose-but")));void 0!==a(this).attr("data-overflowcontent")&&
(c.overflowContent=/^false$/i.test(a(this).attr("data-overflowcontent")));void 0!==a(this).attr("data-ondocumentclick-close")&&(c.onDocumentClickClose=/^true$/i.test(a(this).attr("data-ondocumentclick-close")));void 0!==a(this).attr("data-ondocumentclick-close-prevent")&&(c.onDocumentClickClosePrevent=a(this).attr("data-ondocumentclick-close-prevent"));void 0!==a(this).attr("data-inline")&&(c.inline=/^true$/i.test(a(this).attr("data-inline")));void 0!==a(this).attr("data-asmenu")&&(c.asMenu=/^false$/i.test(a(this).attr("data-asmenu")));
void 0!==a(this).attr("data-size")&&(c.size=a(this).attr("data-size"));a(this).popModal(c)});a.event.special.destroyed={remove:function(a){a.handler&&a.handler()}}})(jQuery);(function(a){a.fn.notifyModal=function(c){function f(){var b=a(".notifyModal");b.removeClass("open");setTimeout(function(){b.remove();-1!=d.duration&&clearTimeout(notifDur);if(d.onClose&&a.isFunction(d.onClose))d.onClose(b);b.trigger("close",{el:b})},h)}var g=a(this),b,d,h,n={init:function(c){d=a.extend({duration:2500,placement:"center",
type:"notify",overlay:!0,icon:!1,onLoad:function(){},onClose:function(){}},c);a(".notifyModal").remove();c=a('<div class="notifyModal '+d.placement+" "+(d.overlay?"overlay":"")+" "+d.type+" "+(d.icon?"icon":"")+'"></div>');var m=a('<div class="notifyModal_content"></div>'),e=a('<button type="button" class="close">×</button>');g=void 0===g[0]?g.selector:g[0].innerHTML;m.append(e,g);c.append(m);a("body").append(c);b=a(".notifyModal");h||(h=b.css("transitionDuration"),h=void 0!==h?1E3*h.replace("s",
""):0);if(d.onLoad&&a.isFunction(d.onLoad))d.onLoad(b);c.trigger("load",{el:b});b.addClass("open");b.click(function(){f()});-1!=d.duration&&(notifDur=setTimeout(f,d.duration))},hide:function(){f()}};a("html").keydown(function(a){27==a.keyCode&&f()});if(n[c])return n[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return n.init.apply(this,arguments)};a("* [data-notifymodal-bind]").bind("click",function(){var c=a(this).attr("data-notifymodal-bind"),f={};void 0!==a(this).attr("data-duration")&&
(f.duration=parseInt(a(this).attr("data-duration")));void 0!==a(this).attr("data-placement")&&(f.placement=a(this).attr("data-placement"));void 0!==a(this).attr("data-type")&&(f.type=a(this).attr("data-type"));void 0!==a(this).attr("data-overlay")&&(f.overlay=/^true$/i.test(a(this).attr("data-overlay")));void 0!==a(this).attr("data-icon")&&(f.icon=/^false$/i.test(a(this).attr("data-overlay")));a(c).notifyModal(f)})})(jQuery);(function(a){a.fn.hintModal=function(c){a(".hintModal").off();var f={init:function(){function c(b,
c){var d=b.attr("class");var g=b.outerWidth();var f=c.outerWidth(),m=b.offset().left,e=a(window).width()-b.offset().left-g,q=g+m-f,k=g+e-f,l=Math.min(g/2+e-f/2,g/2+m-f/2);g=b.hasClass("bottomLeft")?"bottomLeft":b.hasClass("bottomCenter")?"bottomCenter":b.hasClass("bottomRight")?"bottomRight":"bottomLeft";void 0===b.data("placement")&&b.data("placement",g);b.removeAttr("class").addClass(d+" "+function(a){var b=Math.max(q,k,l);return("bottomLeft"==a?0<k:"bottomRight"==a?0<q:0<l)?a:0<k&&k==b?"bottomLeft":
0<q&&q==b?"bottomRight":0<l&&l==b?"bottomCenter":a}(b.data("placement")))}a(this).on("mouseenter",function(){var b=a(this).find("> .hintModal_container");1<b[0].textContent.length&&(b.addClass("animated fadeInBottom"),c(a(this),b))});a(this).on("mouseleave",function(){var b=a(this).find("> .hintModal_container");1<b[0].textContent.length&&b.removeClass("animated fadeInBottom")})}};if(f[c])return f[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return f.init.apply(this,
arguments)};a(".hintModal").hintModal();document.addEventListener("DOMNodeInserted",function(c){a(c.target).hasClass("hintModal")&&a(".hintModal").hintModal()},!1)})(jQuery);(function(a){a.fn.dialogModal=function(c){function f(){var b=a(".dialogModal");b.removeClass("open");setTimeout(function(){b.remove();a("body").removeClass("dialogModalOpen").css({paddingRight:""});a("html.dialogModalOpen").off(".dialogModalEvent").removeClass("dialogModalOpen");b.find(".dialogPrev").off("click");b.find(".dialogNext").off("click")},
h);a(".dialogModal_source").replaceWith(n.children())}var g=a(this),b,d,h,n=a("<div></div>"),p={init:function(c){function e(){b.find('[data-dialogmodal-but="close"]').on("click",function(){f();a(this).off("click")});b.find('[data-dialogmodal-but="ok"]').on("click",function(c){var e;d.onOkBut&&a.isFunction(d.onOkBut)&&(e=d.onOkBut(c,b,k+1));!1!==e&&f();a(this).off("click");g.trigger("okbut",{event:c,el:b,current:k+1})});b.find('[data-dialogmodal-but="cancel"]').on("click",function(c){if(d.onCancelBut&&
a.isFunction(d.onCancelBut))d.onCancelBut(c,b,k+1);f();a(this).off("click");g.trigger("cancelbut",{event:c,el:b,current:k+1})});b.find('[data-dialogmodal-but="prev"]').on("click",function(){b.find(".dialogPrev").click()});b.find('[data-dialogmodal-but="next"]').on("click",function(){b.find(".dialogNext").click()})}function m(){y.empty().append(g[k].innerHTML);t.find("span").html(g.find(".dialogModal_header")[k].innerHTML);e();if(d.onChange&&a.isFunction(d.onChange))d.onChange(b,k+1);g.trigger("change",
{el:b,current:k+1})}d=a.extend({topOffset:0,top:0,onDocumentClickClose:!1,onOkBut:function(){return!0},onCancelBut:function(){},onLoad:function(){},onClose:function(){},onChange:function(){}},c);a("html.dialogModalOpen").off(".dialogModalEvent").removeClass("dialogModalOpen");a(".dialogModal .dialogPrev, .dialogModal .dialogNext").off("click");a(".dialogModal").remove();0!=d.top&&(d.top="calc("+d.top+" + 60px)");var k=0,l=g.length-1;c=a('<div class="dialogModal '+(0!=d.top?" modal":"")+'" style="top:'+
(isNaN(d.topOffset)?d.topOffset:d.topOffset+"px")+'"></div>');var p=a('<div class="dialogModal_container" style="top:'+(isNaN(d.top)?d.top:d.top+"px")+'"></div>'),x=a('<div class="dialogModal_top animated"></div>'),t=a('<div class="dialogModal_header"></div>'),y=a('<div class="dialogModal_body animated"></div>'),B=a('<button type="button" class="close">×</button>');c.append(p);p.append(x,y);x.append(t);t.append(B);y.append(g[k].innerHTML);g.each(function(){n.append(a(this))});g.parent().append(a('<div class="dialogModal_source"></div>'));
0<l&&t.append(a('<div class="dialogNext">›</div><div class="dialogPrev notactive">‹</div>'));t.append("<span>"+g.find(".dialogModal_header")[k].innerHTML+"</span>");a("body").append(c).addClass("dialogModalOpen");0==d.top&&(c=c.outerWidth()-p[0].scrollWidth,x.css({right:c+"px"}));b=a(".dialogModal");h||(h=b.css("transitionDuration"),h=void 0!==h?1E3*h.replace("s",""):0);if(d.onLoad&&a.isFunction(d.onLoad))d.onLoad(b,k+1);g.trigger("load",{el:b,current:k+1});b.on("destroyed",function(){if(d.onClose&&
a.isFunction(d.onClose))d.onClose(b,k+1);g.trigger("close",{el:b,current:k+1})});b.addClass("open");setTimeout(function(){0!=d.top&&p.css({opacity:1});x.addClass("fadeInTopBig");y.addClass("fadeInTopBig")},h+100);e();if(d.onDocumentClickClose)a(".dialogModal_container").on("click.dialogModalEvent",function(b){a(this).addClass("dialogModalOpen");b=a(b.target);b.parents().addBack().is(".dialogModal_body")||b.parents().addBack().is(".dialogModal_header")||f()});b.find(".dialogPrev").on("click",function(){0<
k&&(--k,k<l&&b.find(".dialogNext").removeClass("notactive"),0===k&&b.find(".dialogPrev").addClass("notactive"),m())});b.find(".dialogNext").on("click",function(){k<l&&(++k,0<k&&b.find(".dialogPrev").removeClass("notactive"),k==l&&b.find(".dialogNext").addClass("notactive"),m())});b.find(".close").on("click",function(){f();a(this).off("click")});a("html").on("keydown.dialogModalEvent",function(a){27==a.keyCode?f():37==a.keyCode?b.find(".dialogPrev").click():39==a.keyCode&&b.find(".dialogNext").click()})},
hide:function(){f()}};if(p[c])return p[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return p.init.apply(this,arguments)};a("* [data-dialogmodal-bind]").bind("click",function(){var c=a(this).attr("data-dialogmodal-bind"),f={};void 0!==a(this).attr("data-topoffset")&&(f.topOffset=a(this).attr("data-topoffset"));void 0!==a(this).attr("data-top")&&(f.top=a(this).attr("data-top"));void 0!==a(this).attr("data-ondocumentclick-close")&&(f.onDocumentClickClose=/^false$/i.test(a(this).attr("data-ondocumentclick-close")));
a(c).dialogModal(f)});a.event.special.destroyed={remove:function(a){a.handler&&a.handler()}}})(jQuery);(function(a){a.fn.titleModal=function(c){a(".titleModal").off();var f={init:function(){var c,b,d=a(".titleModal");d.on("mouseenter",function(){c=a(this);if(void 0!==c.attr("title")||"ellipsis"==c.css("textOverflow")||"clip"==c.css("textOverflow")){var d=void 0!==c.attr("title")?c.attr("title"):c.text();c.removeAttr("title");c.attr("data-title",d);var f=a('<div class="titleModal_container animated"></div>');
b=a(".titleModal_container");var g=c.attr("data-placement");void 0===g&&(g="bottom");b&&b.remove();c.after(f.append(d));d=g;b=a(".titleModal_container");f=c.position().left;g=c.position().top;var m=c.css("marginLeft"),e=c.css("marginTop"),q=c.outerHeight(),k=c.outerWidth(),l=b.outerWidth(),z=b.outerHeight();switch(d){case "bottom":b.css({top:g+parseInt(e)+q-5+"px",left:f+parseInt(m)+(k-l)/2+"px"}).addClass("fadeInBottom");break;case "top":b.css({top:g+parseInt(e)-z+"px",left:f+parseInt(m)+(k-l)/2+
"px"}).addClass("top fadeInTop");break;case "left":b.css({top:g+parseInt(e)+q/2-z/2+"px",left:f+parseInt(m)-l-10+"px"}).addClass("left fadeInLeft");break;case "right":b.css({top:g+parseInt(e)+q/2-z/2+"px",left:f+parseInt(m)+k+10+"px"}).addClass("right fadeInRight")}}});d.on("mouseleave",function(){c=a(this);if(void 0!==c.attr("data-title")){var d=c.attr("data-title");c.removeAttr("data-title");c.attr("title",d);d=b.attr("class");var f=d.replace("fadeIn","fadeOut");b.removeClass(d).addClass(f);b.remove()}})}};
if(f[c])return f[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return f.init.apply(this,arguments)};a(".titleModal").titleModal();document.addEventListener("DOMNodeInserted",function(c){a(c.target).hasClass("titleModal")&&a(".titleModal").titleModal()},!1)})(jQuery);(function(a){a.fn.confirmModal=function(c){function f(){var b=a(".confirmModal");b.removeClass("open");setTimeout(function(){b.remove();a("body").removeClass("confirmModalOpen").css({paddingRight:""});
a("html.confirmModalOpen").off(".confirmModalEvent").removeClass("confirmModalOpen")},h);a(".confirmModal_source").replaceWith(n.children())}var g=a(this),b,d,h,n=a("<div></div>"),p={init:function(c){d=a.extend({topOffset:0,top:0,onOkBut:function(){return!0},onCancelBut:function(){},onLoad:function(){},onClose:function(){}},c);a("html.confirmModalOpen").off(".confirmModalEvent").removeClass("confirmModalOpen");a(".confirmModal").remove();c=a('<div class="confirmModal" style="top:'+(isNaN(d.topOffset)?
d.topOffset:d.topOffset+"px")+'"></div>');var e=a('<div class="confirmModal_body animated'+(0!=d.top?" modal":"")+'" style="top:'+(isNaN(d.top)?d.top:d.top+"px")+'"></div>');c.append(e);e.append(g[0].innerHTML);g.each(function(){n.append(a(this))});g.parent().append(a('<div class="confirmModal_source"></div>'));a("body").append(c).addClass("confirmModalOpen");b=a(".confirmModal");h||(h=b.css("transitionDuration"),h=void 0!==h?1E3*h.replace("s",""):0);if(d.onLoad&&a.isFunction(d.onLoad))d.onLoad(b);
g.trigger("load",{el:b});b.on("destroyed",function(){if(d.onClose&&a.isFunction(d.onClose))d.onClose(b);g.trigger("close",{el:b})});b.addClass("open");setTimeout(function(){e.addClass("fadeInTopBig");setTimeout(function(){e.removeClass("fadeInTopBig").addClass("open")},h+100)},h+100);(function(){function c(){e.addClass("needConfirm");setTimeout(function(){e.removeClass("needConfirm")},h+100)}b.find('[data-confirmmodal-but="close"]').on("click",function(){f();a(this).off("click")});b.find('[data-confirmmodal-but="ok"]').on("click",
function(c){var e;d.onOkBut&&a.isFunction(d.onOkBut)&&(e=d.onOkBut(c,b));!1!==e&&f();g.trigger("okbut",{event:c,el:b});a(this).off("click")});b.find('[data-confirmmodal-but="cancel"]').on("click",function(c){if(d.onCancelBut&&a.isFunction(d.onCancelBut))d.onCancelBut(c,b);g.trigger("cancelbut",{event:c,el:b});f();a(this).off("click")});b.on("click",function(b){a(b.target).parents().addBack().is(e)||c()});a("html").on("keydown.confirmModalEvent",function(a){27==a.keyCode&&c()})})()},hide:function(){f()}};
if(p[c])return p[c].apply(this,Array.prototype.slice.call(arguments,1));if("object"===typeof c||!c)return p.init.apply(this,arguments)};a("* [data-confirmmodal-bind]").bind("click",function(){var c=a(this).attr("data-confirmmodal-bind"),f={};void 0!==a(this).attr("data-topoffset")&&(f.topOffset=a(this).attr("data-topoffset"));void 0!==a(this).attr("data-top")&&(f.top=a(this).attr("data-top"));a(c).confirmModal(f)});a.event.special.destroyed={remove:function(a){a.handler&&a.handler()}}})(jQuery)});