mirror of
https://github.com/zyx0814/dzzoffice.git
synced 2025-04-04 22:33:37 +08:00
1 line
7.8 KiB
JavaScript
1 line
7.8 KiB
JavaScript
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?t(require("jquery")):t(jQuery)}(function(t){var i={element:"body",position:null,type:"info",allow_dismiss:!0,allow_duplicates:!1,newest_on_top:!0,placement:{from:"top",align:"right"},offset:20,spacing:10,z_index:10800,delay:5e3,timer:1e3,url_target:"_blank",mouse_over:"pause",animate:{enter:"animate__animated animate__fadeInDown",exit:"animate__animated animate__fadeOutUp"},onShow:null,onShown:null,onClose:null,onClosed:null,onClick:null,icon_type:"class",template:'<div data-notify="container" class="notify notify-{0}" role="alert"><div class="d-flex align-items-center p-2"><span class="me-2 lead text-{0}" data-notify="icon"></span><span class="notify-body" data-notify="message">{1}</span><a href="{2}" target="{3}" data-notify="url"></a><button type="button" class="btn-close me-2 m-auto" data-notify="dismiss"></button></div></div>'};function e(e,s,n){var a,o,l={content:{message:"object"==typeof s?s.message:s,icon:s.icon?s.icon:"",url:s.url?s.url:"#",target:s.target?s.target:"-"}};n=t.extend(!0,{},l,n),this.settings=t.extend(!0,{},i,n),this._defaults=i,"-"===this.settings.content.target&&(this.settings.content.target=this.settings.url_target),this.animations={start:"webkitAnimationStart oanimationstart MSAnimationStart animationstart",end:"webkitAnimationEnd oanimationend MSAnimationEnd animationend"},"number"==typeof this.settings.offset&&(this.settings.offset={x:this.settings.offset,y:this.settings.offset}),(this.settings.allow_duplicates||!this.settings.allow_duplicates&&(a=this,o=!1,t('[data-notify="container"]').each(function(i,e){var s=t(e),n=s.find('[data-notify="message"]').html().trim()===t("<div>"+a.settings.content.message+"</div>").html().trim(),l=s.hasClass("notify-"+a.settings.type);return n&&l&&(o=!0),!o}),!o))&&this.init()}String.format=function(){var t=arguments;return arguments[0].replace(/(\{\{\d\}\}|\{\d\})/g,function(i){if("{{"===i.substring(0,2))return i;var e=parseInt(i.match(/\d/)[0]);return t[e+1]})},t.extend(e.prototype,{init:function(){var t=this;this.buildNotify(),this.settings.content.icon&&this.setIcon(),"#"!=this.settings.content.url&&this.styleURL(),this.placement(),this.bind(),this.notify={$ele:this.$ele,update:function(i,e){var s={};for(var n in"string"==typeof i?s[i]=e:s=i,s)switch(n){case"type":this.$ele.removeClass("notify-"+t.settings.type),t.settings.type=s[n];break;case"icon":var a=this.$ele.find('[data-notify="icon"]');"class"===t.settings.icon_type.toLowerCase()?a.removeClass(t.settings.content.icon).addClass(s[n]):(a.is("img")||a.find("img"),a.attr("src",s[n])),t.settings.content.icon=s[i];break;case"url":this.$ele.find('[data-notify="url"]').attr("href",s[n]);break;case"target":this.$ele.find('[data-notify="url"]').attr("target",s[n]);break;default:this.$ele.find('[data-notify="'+n+'"]').html(s[n])}var o=this.$ele.outerHeight()+parseInt(t.settings.spacing)+parseInt(t.settings.offset.y);t.reposition(o)},close:function(){t.close()}}},buildNotify:function(){var i=this.settings.content;this.$ele=t(String.format(this.settings.template,this.settings.type,i.message,i.url,i.target)),this.$ele.attr("data-notify-position",this.settings.placement.from+"-"+this.settings.placement.align),this.settings.allow_dismiss||this.$ele.find('[data-notify="dismiss"]').css("display","none")},setIcon:function(){"class"===this.settings.icon_type.toLowerCase()?this.$ele.find('[data-notify="icon"]').addClass(this.settings.content.icon):this.$ele.find('[data-notify="icon"]').is("img")?this.$ele.find('[data-notify="icon"]').attr("src",this.settings.content.icon):this.$ele.find('[data-notify="icon"]').append('<img src="'+this.settings.content.icon+'" alt="Notify Icon" />')},styleURL:function(){this.$ele.find('[data-notify="url"]').css({backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)",height:"100%",left:0,position:"absolute",top:0,width:"100%",zIndex:this.settings.z_index+1})},placement:function(){var i=this,e=this.settings.offset.y,s={display:"inline-block",margin:"0px auto",position:this.settings.position?this.settings.position:"body"===this.settings.element?"fixed":"absolute",transition:"all .5s ease-in-out",zIndex:this.settings.z_index},n=!1,a=this.settings;switch(t('[data-notify-position="'+this.settings.placement.from+"-"+this.settings.placement.align+'"]:not([data-closing="true"])').each(function(){e=Math.max(e,parseInt(t(this).css(a.placement.from))+parseInt(t(this).outerHeight())+parseInt(a.spacing))}),!0===this.settings.newest_on_top&&(e=this.settings.offset.y),s[this.settings.placement.from]=e+"px",this.settings.placement.align){case"left":case"right":s[this.settings.placement.align]=this.settings.offset.x+"px";break;case"center":s.left=0,s.right=0}this.$ele.css(s).addClass(this.settings.animate.enter),t.each(Array("webkit-","moz-","o-","ms-",""),function(t,e){i.$ele[0].style[e+"AnimationIterationCount"]=1}),t(this.settings.element).append(this.$ele),!0===this.settings.newest_on_top&&(e=parseInt(e)+parseInt(this.settings.spacing)+this.$ele.outerHeight(),this.reposition(e)),t.isFunction(i.settings.onShow)&&i.settings.onShow.call(this.$ele),this.$ele.one(this.animations.start,function(){n=!0}).one(this.animations.end,function(){i.$ele.removeClass(i.settings.animate.enter),t.isFunction(i.settings.onShown)&&i.settings.onShown.call(this)}),setTimeout(function(){n||t.isFunction(i.settings.onShown)&&i.settings.onShown.call(this)},600)},bind:function(){var i=this;if(this.$ele.find('[data-notify="dismiss"]').on("click",function(){i.close()}),t.isFunction(i.settings.onClick)&&this.$ele.on("click",function(t){t.target!=i.$ele.find('[data-notify="dismiss"]')[0]&&i.settings.onClick.call(this,t)}),this.$ele.mouseover(function(){t(this).data("data-hover","true")}).mouseout(function(){t(this).data("data-hover","false")}),this.$ele.data("data-hover","false"),this.settings.delay>0){i.$ele.data("notify-delay",i.settings.delay);var e=setInterval(function(){var t=parseInt(i.$ele.data("notify-delay"))-i.settings.timer;("false"===i.$ele.data("data-hover")&&"pause"===i.settings.mouse_over||"pause"!=i.settings.mouse_over)&&(i.settings.delay,i.settings.delay,i.$ele.data("notify-delay",t)),t<=-i.settings.timer&&(clearInterval(e),i.close())},i.settings.timer)}},close:function(){var i=this,e=parseInt(this.$ele.css(this.settings.placement.from)),s=!1;this.$ele.attr("data-closing","true").addClass(this.settings.animate.exit),i.reposition(e),t.isFunction(i.settings.onClose)&&i.settings.onClose.call(this.$ele),this.$ele.one(this.animations.start,function(){s=!0}).one(this.animations.end,function(){t(this).remove(),t.isFunction(i.settings.onClosed)&&i.settings.onClosed.call(this)}),setTimeout(function(){s||(i.$ele.remove(),t.isFunction(i.settings.onClosed)&&i.settings.onClosed.call(this))},600)},reposition:function(i){var e=this,s='[data-notify-position="'+this.settings.placement.from+"-"+this.settings.placement.align+'"]:not([data-closing="true"])',n=this.$ele.nextAll(s);!0===this.settings.newest_on_top&&(n=this.$ele.prevAll(s)),n.each(function(){t(this).css(e.settings.placement.from,i),i=parseInt(i)+parseInt(e.settings.spacing)+t(this).outerHeight()})}}),t.notify=function(t,i){return new e(this,t,i).notify},t.notifyDefaults=function(e){return i=t.extend(!0,{},i,e)},t.notifyClose=function(i){void 0===i||"all"===i?t("[data-notify]").find('[data-notify="dismiss"]').trigger("click"):"success"===i||"info"===i||"warning"===i||"danger"===i?t(".notify-"+i+"[data-notify]").find('[data-notify="dismiss"]').trigger("click"):i?t(i+"[data-notify]").find('[data-notify="dismiss"]').trigger("click"):t('[data-notify-position="'+i+'"]').find('[data-notify="dismiss"]').trigger("click")},t.notifyCloseExcept=function(i){"success"===i||"info"===i||"warning"===i||"danger"===i?t("[data-notify]").not(".notify-"+i).find('[data-notify="dismiss"]').trigger("click"):t("[data-notify]").not(i).find('[data-notify="dismiss"]').trigger("click")}}); |