Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (17 sloc) 4.5 KB
/*=================================================================================================
* @name: Popelt
* @type: jQuery
* @author: (c) Elton Jain - @eltonjain
* @demo: http://welbour.com
* @version: 1.0
* @requires jQuery 1.9.1
*=================================================================================================*/
(function(b){var n=[],r=0,g=null,l=null;window.Popelt=function(y){function z(){var c="."+f+"."+e,h="."+m+"."+e;b(c).on("click","."+w,d.close);a.closeClass&&(a.closeClass=a.closeClass.replace(".",""),b(c).on("click","."+a.closeClass,d.close));if(!0===a.closeButton)b(c).on("click","."+A,d.close);!0!==a.modal&&(b("body").on("click",h+", "+c,d.close),b("body").on("click",c+" .pop-block",function(a){a.stopPropagation()}));!1!==a.escClose&&B();k.on("resize",s)}function C(c){var d="."+f+"."+c;b("."+m+"."+
c+", "+d).off("click");b(d+"."+w).off("click");a.closeClass&&b(d+"."+a.closeClass.replace(".","")).off("click");x.off("keydown."+c)}function B(){x.on("keydown."+e,function(a){if(27==a.which)return a.stopImmediatePropagation(),d.close(l),!1})}function t(c){var h="."+f+"."+e+" ."+u;d.setContent(c);b(h).append(c);c="."+f+" ."+u;!0===a.focus&&b(c).find("input,textarea").first().focus();s()}function D(){if("ajax"==a.contentType&&a.loadUrl)b.get(a.loadUrl,function(a){a=b('<div class="pop-ajax-wrapper"></div>').append(a);
t(a);return!1});else if("iframe"==a.contentType&&a.loadUrl){var c=b('<iframe class="pop-iframe"></iframe>');c.attr("src",a.loadUrl);c.css({border:0,width:a.iframeWidth,height:a.iframeHeight});t(c)}else 0==a.contentType.indexOf("#")&&(c=b(a.contentType).html(),t(c))}function s(){if(""!==a.offsetTop&&0<=a.offsetTop||!1===a.valign)return!1;var c="."+f+"."+e+" .pop-block";b(c).outerWidth();c=b(c).outerHeight();_new_top=(E-c)/2-20;_new_top=0<_new_top?_new_top:0;b("."+f+"."+e+" .pop-container").css("margin-top",
_new_top)}var d=this,x=b(document),v=window,k=b(v),E=v.innerHeight||k.height();v.innerWidth||k.width();var A="pop-btn-close",w="pop-close",m="pop-screen",f="pop-wrap",u="pop-content",e,q=9E3,a=b.extend({modal:!1,title:!1,content:"",offsetTop:-1,closeButton:!0,closeBtnTooltip:"Close",width:600,closeClass:"",escClose:!0,focus:null,contentType:!1,loadUrl:!1,buttons:[],fadeSpeed:200,iframeHeight:"300px",iframeWidth:"100%",maxHeight:!1,valign:!0,responsive:!1,overlayColor:!1,overlayOpacity:!1},y);d.init=
function(){g=(g||0)+1;e="__pop"+g+"__";q+=g};d.setContent=function(b){a.content=b;return d};d.showPopup=function(){if(0>=b("."+f+"."+e).length){var c,h,p,g;p=b("<div>").addClass(m).addClass(e).css("z-index",q);a.overlayColor&&p.css("background",a.overlayColor);a.overlayOpacity&&p.css("opacity",a.overlayOpacity).css("filter","alpha("+10*a.overlayOpacity+")");h=b("<div>").addClass(u);a.title&&(c=b("<div>").addClass("pop-title").text(a.title));a.content&&h.append(a.content);a.buttons.length&&(g=b("<div>").addClass("pop-action-block"),
b.each(a.buttons,function(a,c){b.isFunction(c.classname);var d=b("<button>").addClass("pop-btn").addClass(c.classname).text(c.label);if(c.clickEvent)d.on("click",c.clickEvent);g.append(d)}));a.maxHeight&&h.css("max-height",a.maxHeight);popBlock=b("<div>").addClass("pop-block");if(!1!==a.closeButton){var k=b("<span>").addClass("pop-btn-close").html("&times;");a.closeBtnTooltip&&k.attr("title",a.closeBtnTooltip);popBlock.append(k)}popBlock.append(c).append(h).append(g);popContainer=b("<div>").addClass("pop-container").width(a.width).append(popBlock);
popContainer.css("margin","0 auto");0<=a.offsetTop&&popContainer.css("margin-top",a.offsetTop);!0===a.responsive&&popContainer.css("max-width","100%");c=b("<div>").addClass(f).addClass(e).css("z-index",q+1).append(popContainer);b("body").append(p);b("body").append(c)}(a.contentType||a.loadUrl)&&D();b("."+m+"."+e).show();b("."+f+"."+e).show();z();s();r++;n.push(e);l=e;b("body").not(".noscroll")&&b("body").addClass("noscroll");return d};d.addButton=function(c,e,f){c={label:c};b.isFunction(e)&&(f=e,
e="");c.classname=e;b.isFunction(f)?c.clickEvent=f:c.clickEvent=d.close;a.buttons.push(c);return c};d.addOKButton=function(a){d.addButton("OK",a)};d.addCancelButton=function(){d.addButton("Cancel",d.close)};d.addCloseButton=function(){d.addButton("Close",d.close)};d.closePopup=function(c){popupId=l?l:e;C(popupId);c=b("."+f+"."+popupId);var d=b("."+m+"."+popupId);c.fadeTo(a.fadeSpeed,0,function(){b(this).remove()});d.fadeTo(a.fadeSpeed,0,function(){b(this).remove()});r--;n.pop();l=n[n.length-1];0==
r&&b("body").removeClass("noscroll");return!1};d.show=d.showPopup;d.close=d.closePopup;d.init();return this}})(jQuery);