-
Notifications
You must be signed in to change notification settings - Fork 14
/
mylib-toast-min.js
1 lines (1 loc) · 4.45 KB
/
mylib-toast-min.js
1
var API,global=this;if(API&&API.areFeatures&&API.areFeatures("createElement","attachDocumentReadyListener","getElementDocument")){API.attachDocumentReadyListener(function(){var V,R=API,U=R.getBodyElement,K=R.showControl,N=R.cornerControl,T=R.createElement,P=R.getElementDocument;var A=R.attachListener,Z=R.callInContext,G=R.getWorkspaceRectangle,X=R.getDocumentWindow,S=R.playEventSound;var L,D,Y,W,F,Q,I=["topleft","topright","bottomleft","bottomright"];var O=U();var E={};var C=function(a){for(V=I.length;V--;){a[I[V]]=[]}return a};C(E);var J=function(b){var a;if(!b||b==global){a=global.document}else{a=b.document}return a};var B,H=function(a){API.attachWindowListener("resize",function(){Y(null,a)})};var M=function(a){if(!a||a==global.document){if(!B){H(global.document);B=true}return E}else{if(!a.toaster&&(typeof a.expando=="undefined"||a.expando)){H(a);a.toaster=C({})}return a.toaster}};if(!O||typeof O.offsetWidth!="number"){return }Q=function(g,b,m){var c=0,h=0,n=M(m)[g],a=G(m),f=a[2],e=0;var j=g.indexOf("top")!=-1;var l=g.indexOf("right")!=-1;for(var d=n.length;d--;){var k=n[d];if(k.element){c+=(j?1:-1)*k.element.offsetHeight}else{if(k.arranging){c+=(j?1:-1)*k.arranging}}if(k.element&&k.element.offsetWidth>e){e=k.element.offsetWidth}if(Math.abs(c)+b.offsetHeight>f){h+=(l?-1:1)*e;c=e=0}}return[c,h]};F=function(b,g){var f,h;for(var e=I.length;e--;){f=false;var k=M(g)[I[e]];for(var d=0,c=k.length;d<c;d++){var a=k[d];if(a.element){if(a.element==b){h=k[d]}f=true}else{if(a.arranging){f=true}}}if(!f){E[I[e]]=[]}}return h};L=function(c,b,d){var a=M(d)[b];return(a[a.length]={element:c,position:b})};D=function(h,o,n){var d=0,j=0,p=M(n)[h],b=G(n),g=b[2],f=0;var k=h.indexOf("top")!=-1;var m=h.indexOf("right")!=-1;o=o||{duration:1};for(var e=0,c=p.length;e<c;e++){if(p[e].element){var a=(k?1:-1)*p[e].element.offsetHeight;if(Math.abs(d+a)>g){j+=(m?-1:1)*f;d=f=0;o.offset=[d,j]}else{o.offset=[d,j]}d+=a;p[e].destination=N(p[e].element,h,o);if(p[e].element.offsetWidth>f){f=p[e].element.offsetWidth}}else{if(p[e].arranging){d+=(k?1:-1)*p[e].arranging}}}};Y=function(a,c){for(var b=I.length;b--;){D(I[b],a,c)}};if(O&&A&&API.isHostMethod(O,"appendChild")&&N&&K){R.arrangeToast=D;R.arrangeToasts=Y;R.enhanceToast=W=function(a,k,f){var i,h=f?J(f):P(a),e=U(h);if(!f&&X){f=X(h)}if(!f){return null}if(!k){k={}}var c=k.position;if(c){c=c.toLowerCase().replace(/ /,"")}else{c="bottomleft"}if(e){var l=F(a,h);if(l){global.clearTimeout(l.timer)}a.style.position="absolute";a.style.visibility="hidden";a.className=k.className||"toast panel";if(c.indexOf("top")!=-1){a.className+=" top"}e.appendChild(a);var j={duration:k.duration,effects:k.effects,fps:k.fps,ease:k.ease,removeOnHide:true,useCSSTransitions:false};if(j.effects&&API.effects&&(j.effects==API.effects.slide||j.effects==API.effects.drop)&&!k.effectParams){j.effectParams={side:c.indexOf("top")==-1?"top":"bottom"}}else{if(j.effects&&API.effects&&j.effects==API.effects.fold&&!k.effectParams){j.effectParams={axes:1}}else{j.effectParams=k.effectParams}}var b=Q(c,a,h);var g=a.offsetWidth;N(a,c,{offset:b},null,h);if(a.offsetWidth!=g){N(a,c,{offset:[b[0],b[1]-1]},null,h)}if(k.fixed&&API.fixElement){API.fixElement(a,true,k)}var d=function(m,n){if(i&&l.element){l.element=null;if(m){n.clearTimeout(l.timer)}if(!k.onhide||Z(k.onhide,k.callbackContext||API)!==false){l.arranging=a.offsetHeight;var o=l.destination;if(o){API.positionElement(a,o[0],o[1],{duration:1})}K(a,false,j,function(){l.arranging=false;D(c,k,h);if(k.autoDestroy){API.destroyToast(a,n);a=null}})}}if(!k.autoDestroy){a=null}i=false};A(a,"click",function(){if(!k.onclick||Z(k.onclick,k.callbackContext||API)!==false){d(true,f)}});l=L(a,c,h);if(!k.onshow||Z(k.onshow)!==false){K(a,true,j,function(){l.timer=f.setTimeout(function(){d(false,f)},k.pause||5000)})}if(S&&!k.mute){global.setTimeout(function(){S("toast")},k.effects?k.duration||0:0)}i=true;return a}return null};if(R.createElement&&T("div")){R.createToast=function(b,e){var d=J(e),a=U(d);if(!e){e=global}if(!b){b={}}var c=T("div",d);if(c){if(API.setControlRole){API.setControlRole(c,"alertdialog")}c.style.visibility="hidden";c.style.position="absolute";c.style.left=c.style.top="0";API.setControlContent(c,b);if(b.onopen){Z(b.onopen,b.callbackContext||API)}a.appendChild(c);return W(c,b,e)}return null};R.destroyToast=function(c,e){var d;if(e){d=J(e)}else{d=P(c);if(d==global.document){e=global}else{if(X){e=X(d)}}}if(e){var b=F(c,d),a=U(d);if(b){a.removeChild(b.element);e.clearTimeout(b.timer);b.element=null;b.arranging=false;return true}}return false}}}R=O=null})}