praiadeseselle/wire/modules/System/SystemNotifications/Notifications.min.js

1 line
13 KiB
JavaScript
Raw Permalink Normal View History

2022-03-08 15:55:41 +01:00
var Notifications={options:{ajaxURL:"./",version:1,reverse:0,updateLast:0,updateDelay:5000,updateDelayFast:1550,iconMessage:"smile-o",iconWarning:"meh-o",iconError:"frown-o",iconRemove:"times-circle",classCommon:"NoticeItem",classMessage:"NoticeMessage",classWarning:"NoticeWarning",classError:"NoticeError",classDebug:"NoticeDebug",classContainer:"container",ghostDelay:2000,ghostDelayError:4000,ghostFadeSpeed:"fast",ghostOpacity:0.9,ghostLimit:20,processKey:"",i18n:{sec:"sec",secs:"secs",min:"min",mins:"mins",hour:"hour",hours:"hours",day:"day",days:"days",expires:"expires",now:"now",fromNow:"from now",ago:"ago"}},updateTimeout:null,renderTimeout:null,timerTimeout:null,updating:false,runtime:[],numRender:0,numEmptyRequests:0,ghostsActive:0,currentDelay:0,turbo:false,timeNow:0,useSession:false,$menu:null,$bug:null,$list:null,relativeTime:function(a){var d="";if(a==0){return d}var c=Notifications.options.i18n;var b=a>0;a=Math.abs(a);if(a>1&&a<60){d=a+" "+(a==1?c.sec:c.secs)}else{if(a>=60&&a<3600){d=Math.floor(a/60);d+=" "+(d==1?c.min:c.mins)}else{if(a>=3600&&a<86400){d=Math.floor(a/3600);d+=" "+(d==1?c.hour:c.hours)}else{if(a>=86400){d=Math.floor(a/86400);d+=" "+(d==1?c.day:c.days)}}}}d+=" ";if(b){if(a<3){d=c.now}}else{if(a<3){d=c.now}}return d},setTurboMode:function(a){if(a){if(Notifications.currentDelay!=Notifications.options.updateDelayFast){Notifications.currentDelay=Notifications.options.updateDelayFast;Notifications.update()}}else{Notifications.currentDelay=Notifications.options.updateDelay}},_updateItemTime:function(h,c){var f=h.find("small.created");var e="";if(f.length>0){var g=parseInt(f.attr("data-created"));var d=c-g;e=Notifications.relativeTime(d,true)}var a=h.attr("data-expires");if(a){a=parseInt(a);if(a>0&&a<=c){h.slideUp("fast",function(){Notifications._remove(h)})}else{if(e.length>0){e+=" / "}var b=Notifications.options.i18n.expires+" "+Notifications.relativeTime(c-a);if(Math.abs(c-a)<10){b="<strong>"+b+"</strong>"}e+=b}}f.html(e)},_updateTime:function(){if(Notifications.timeNow==0){return}Notifications.$list.children("li").each(function(){Notifications._updateItemTime($(this),Notifications.timeNow)})},update:function(){if(Notifications.updating){clearTimeout(Notifications.updateTimeout);Notifications.updateTimeout=setTimeout("Notifications.update()",Notifications.currentDelay);return false}Notifications.updating=true;var c="";var b=Notifications.$list.find("li.removed");b.each(function(){c+=$(this).attr("id")+",";$(this).remove()});var a="./?Notifications=update&time="+Notifications.options.updateLast;if(c.length){a+="&rm="+c}if(Notifications.useSession&&Notifications.options.processKey.length){a+="&processKey="+Notifications.options.processKey+"."+sessionStorage.pwWindowName}$.getJSON(a,function(d){Notifications._update(d);clearTimeout(Notifications.updateTimeout);Notifications.updateTimeout=setTimeout("Notifications.update()",Notifications.currentDelay);Notifications.updating=false})},_update:function(c){var b=parseInt(c.time);var a=false;var g=c.notifications.length;var e=[];if(g>0){Notifications.numEmptyRequests=0}else{Notifications.numEmptyRequests++;if(Notifications.numEmptyRequests>2){Notifications.setTurboMode(false)}}if(b>0){Notifications.timeNow=b}Notifications.options.updateLast=Notifications.timeNow;for(var f=0;f<g;f++){var d=c.notifications[f];if(d.flagNames.indexOf("alert")>-1){e[e.length]=d}else{Notifications._add(d,!c.runtime);if(d.flagNames.indexOf("annoy")>-1){a=true}}if(d.flagNames.indexOf("no-ghost")<0){Notifications._ghost(d,f)}}if(a&&!Notifications.$menu.hasClass("open")){Notifications.$bug.click()}if(a){window.scrollTo(0,0)}if(!Notifications.$menu.hasClass("open")){Notifications._updateTime()}Notifications._updateBug();if(e.length){for(var f=0;f<e.length;f++){ProcessWire.alert(e[f].title)}}},_updateBug:function(){var d=Notifications.$bug;var c=0;var a=0;var b=0;Notifications.$list.children("li").each(function(){var e=$(this);c++;if(e.hasClass("NoticeError")){a++}else{if(e.hasClass("NoticeWarning")){b++}}});if(parseInt(d.attr("data-qty"))==c){}else{Notifications._updateBugQty(c);d.ef