This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
divbox.min.js
1 lines (1 loc) · 2.09 KB
/
divbox.min.js
1
(function(e){e.fn.divBox=function(t){return this.each(function(){var n=e.extend({},e.fn.divBox.defaults,t),r=this,i=n.closeButton,s=e(n.content,r);e.fn.divBox.content=s;e.fn.divBox.customClass=n.customClass;e.fn.divBox.callback=n.callback;e.fn.divBox.onload=n.onload;e.fn.divBox.onclose=n.onclose;createDivbox=function(t,n){t=t||"body";$target=e(t);e.fn.divBox.target=$target;var r=e(">.divboxContainer>.divboxContent",$target);if(r.length>0)return r;var o="divboxContainer";e.fn.divBox.customClass&&(o+=" "+e.fn.divBox.customClass);$target.css("position","relative");var u=e("<div>").addClass(o).css({position:"absolute",display:"none",top:"0",bottom:"0",left:"0",right:"0","z-index":"1001"}),a=e("<div>").attr("class","divbox").css({position:"absolute",background:n,top:"0",bottom:"0",left:"0",right:"0","z-index":"1002"}).fadeTo(0,.8);r=e("<div>").attr("class","divboxContent").css({position:"absolute",top:"30px",bottom:"30px",left:"30px",right:"30px","z-index":"1003"});e.fn.divBox.closeOnClickOut&&a.on("click",function(){e.fn.divBox.deleteDivbox()});if(s){s.show();r.append(s)}u.append(a,r);$target.append(u);u.fadeIn(500);typeof e.fn.divBox.onload=="function"&&e.fn.divBox.onload.call(u);setTimeout(function(e,t){typeof e=="function"&&e.call(t)},50,e.fn.divBox.callback,u);e(i,t).each(function(){if(e(this).data("isCerrar")!=1){e(this).data("isCerrar",!0);e(this).on("click",function(t){t.preventDefault();$dc=e(this).parents("div.divboxContainer");e.fn.divBox.deleteDivbox($dc.parent(),s)})}});return r};toggleDivbox=function(t,n){$target=e(t);var r=e(">.divboxContainer>.divboxContent",$target);r.length>0?e.fn.divBox.deleteDivbox():createDivbox(t,n)};toggleDivbox(r,n.bgColor)})};e.fn.divBox.defaults={content:".content-divbox",closeButton:".close-divbox",bgColor:"#fff",closeOnClickOut:!0,onload:null,onclose:null,callback:null};e.fn.divBox.deleteDivbox=function(){$target=e.fn.divBox.target;$content=e.fn.divBox.content;e(".divboxContainer",$target).fadeOut(500,function(){if($content){$content.hide();$target.append($content)}e(this).remove();typeof e.fn.divBox.onclose=="function"&&e.fn.divBox.onclose.call($target)})}})(jQuery);