vmailadmin/resources/js/lib/flash.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-05-23 15:20:01 +02:00
define("flash",['jquery'],function($){
let my = {
class: function(el, classes, duration)
{
if(undefined == duration)
{
duration = 3000;
}
if(undefined !== el.dataset.timeout_class)
{
clearTimeout(el.dataset.timeout_class);
}
if(!Array.isArray(classes)){
classes = [classes];
}
for(let c of classes) {
el.classList.add(c);
}
el.dataset.timeout = setTimeout(function(){
for(let c of classes) {
el.classList.remove(c);
}
},duration);
},
tooltip: function(el, message, duration, position)
{
let opts = {trigger: "manual", html: true, placement: "right"};
if(undefined !== position && ['auto','top','left','right','bottom'].includes(position)){
opts.placement = position;
}
el.title = message;
$(el).tooltip(opts).tooltip('show');
if(undefined !== el.dataset.timeout_tooltip)
{
clearTimeout(el.dataset.timeout_tooltip);
}
el.dataset.timeout = setTimeout(function(){
$(el).tooltip('hide').tooltip('dispose');
},duration);
}
}
return my;
});