$(function(){window.notification_timers={};window.doNotification=function(type,nid,title,message,timeout,icon,actions,hints,onAction,onClose){console.debug("doNotification",type,nid,title,message,timeout,icon,actions,hints,onAction,onClose);var hints="notification"+nid,a=$(`<div id="${hints}" class="alert ${type}">`+`<img class="notification_icon" id="notification_icon${hints}">`+`<span class="title">${title}</span>`+`<span class="message">${message}</span>`+'<div class="dismiss">&#215;</div></div>'),type=$(".notifications");if(type.prepend(a),actions){var notification_buttons=$('<div class="notification_buttons"></div>');a.append(notification_buttons);for(var index=0;index<actions.length;index+=2){var action_id=actions[index],action_label=actions[index+1],action_id=window._notification_button(nid,action_id,action_label,onAction,onClose);notification_buttons.append(action_id)}}return type.prepend(a),icon&&(title=icon[0],message=icon[3],"png"==title&&(type=`data:image/${title};base64,`+Utilities.ArrayBufferToBase64(message),$("#notification_icon"+hints).attr("src",type))),a.on("click",".dismiss",function(){window.cancelNotificationTimer(nid),a.removeClass("visible").addClass("hidden"),a.on("transitionend webkitTransitionEnd",$.debounce(250,function(){a.trigger("dismissed"),a.remove()})),onClose&&onClose(nid,3,"user clicked dismiss")}),setTimeout(function(){a.addClass("visible")},1),timeout&&(a.data("timeLeft",timeout),window.notification_timers[nid]=setInterval(function(){var tleft=a.data("timeLeft")-1;0===a.data("timeLeft")?(a.find(".dismiss").trigger("click"),onClose&&onClose(nid,1,"timeout")):(a.find("sec").text(tleft),a.data("timeLeft",tleft))},1e3)),a},window._notification_button=function(nid,action_id,action_label,onAction,onClose){action_label=$(`<div class="notification_button" id=notification"${action_id}">${action_label}</div>`);return action_label.on("click",function(){window.closeNotification(nid),onAction&&onAction(nid,action_id),onClose&&onClose(nid,3,"user clicked action")}),action_label},window.cancelNotificationTimer=function(nid){var timer=window.notification_timers[nid];timer&&(window.clearInterval(timer),delete window.notification_timers[nid])},window.cancelNotificationTimers=function(){for(var nid in window.notification_timers)window.cancelNotificationTimer(nid)},window.closeNotification=function(nid){window.cancelNotificationTimer(nid);nid="notification"+nid;$(".notifications").find("#"+nid).find(".dismiss").trigger("click")},window.clearNotifications=function(){window.cancelNotificationTimers(),$(".notifications").find(".dismiss").trigger("click")},window.removeNotifications=function(){window.cancelNotificationTimers(),$(".notifications").empty()}});