dashboard-ui/modules/toast/toast.js
2023-08-31 15:30:17 +02:00

1 line
2.7 KiB
JavaScript

define(["exports","./../layoutmanager.js","./../dom.js","./../dialoghelper/dialoghelper.js"],function(_exports,_layoutmanager,_dom,_dialoghelper){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!modules/toast/toast.css"]);var fillFromTop=_layoutmanager.default.tv,sectionElement=function(){var section=document.createElement("section");section.classList.add("toast-group"),fillFromTop&&section.classList.add("toast-group-top");return document.body.appendChild(section),section}();var nativeAnimationSupported=document.documentElement.animate;function appendToastElement(element,position){nativeAnimationSupported&&sectionElement.children.length&&window.matchMedia("(prefers-reduced-motion: no-preference)").matches?function(element,position){var t;"center"===position?sectionElement.appendChild(element):(t=sectionElement.offsetHeight,sectionElement.appendChild(element),element=sectionElement.offsetHeight-t,"top"===position&&(element*=-1),t=sectionElement.animate([{transform:"translateY(".concat(element,"px)")},{transform:"translateY(0)"}],{duration:150,easing:"ease-out"}),(position=document.timeline)&&(t.startTime=position.currentTime))}(element,position):sectionElement.appendChild(element)}function getAnimationPromise(elem){return elem.getAnimations?Promise.allSettled(elem.getAnimations().map(function(o){return o.finished})):(delay=3300,new Promise(function(resolve,reject){setTimeout(resolve,delay)}));var delay}_exports.default=function(options){return"string"==typeof options&&(options={text:options}),require(["css!modules/toast/toast.css"]).then(function(){var position=fillFromTop?"top":options.icon?"center":null,toast=function(options,position){var iconClass,toast=document.createElement("output"),html="";return options.icon&&(iconClass="toast-icon","center"===position&&(iconClass+=" toast-icon-center"),html=(html+='<i class="md-icon autortl '+iconClass+'">')+options.icon+"</i>"),html+='<div class="flex flex-direction-column">',html="center"===position?(html+='<h3 class="toast-primarytext">')+options.text+"</h3>":(html+='<div class="toast-primarytext">')+options.text+"</div>",options.secondaryText&&(html=(html+='<div class="secondaryText toast-secondaryText">')+options.secondaryText+"</div>"),html+="</div>",toast.classList.add("toast"),toast.classList.add("dialog"),_dom.default.allowBackdropFilter()&&toast.classList.add("dialog-blur"),position&&toast.classList.add("toast-"+position),"center"===position&&toast.classList.add("toast-large"),toast.setAttribute("role","status"),toast.innerHTML=html,toast}(options,position);return appendToastElement(toast,position),getAnimationPromise(toast).then(function(){sectionElement.removeChild(toast)})})}});