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=""+b+""}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-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;f0){d.addClass(Notifications.options.classError,"slow").removeClass(Notifications.options.classWarning,"slow")}else{if(b>0){d.addClass(Notifications.options.classWarning,"slow").removeClass(Notifications.options.classError,"slow")}else{d.removeClass(Notifications.options.classWarning+" "+Notifications.options.classError,"slow")}}},_updateBugQty:function(b){var c=Notifications.$bug;var d=c.children(".qty");var a=b>99?"99+":b;c.attr("class",c.attr("class").replace(/qty\d+\s*/g,""));c.addClass("qty"+b);d.text(a);if(b==0){c.fadeOut()}else{if(!c.is(":visible")){c.fadeIn()}}c.attr("data-qty",b)},add:function(a){var b=Notifications.runtime.length;a.addClass="runtime";a.runtime=true;Notifications.runtime[b]=a},render:function(){Notifications.renderTimeout=setTimeout(function(){var a=0;var b=0;var c=0;$(Notifications.runtime).each(function(f,e){if(e.flagNames.indexOf("error")!=-1){a++}else{if(e.flagNames.indexOf("warning")!=-1){b++}else{c++}}});var d={qty:Notifications.runtime.length,qtyNew:0,qtyMessage:c,qtyWarning:b,qtyError:a,notifications:Notifications.runtime,runtime:true};Notifications._update(d,true);if(Notifications.$list.find(".NotificationProgress").length>0){Notifications.setTurboMode(true)}},250);Notifications.numRender++},_add:function(a,b){var o=false;var d=false;var j=Notifications.$list.children("#"+a.id);var q=parseInt(a.progress);var m=0;var n=null;if(j.length>0){o=true;b=false;d=j.hasClass("open");var i=j.find(".NotificationProgress");if(i.length>0){m=parseInt(i.text())}n=j.find("small.created");j.empty()}else{j=$("
  • ")}j.attr("id",a.id).addClass(Notifications.options.classCommon);if(a.expires>0){j.attr("data-expires",a.expires)}var g=$("").addClass("fa fa-fw fa-"+a.icon);var k=$("").addClass("NotificationTitle").html(a.title);var f=$("

    ").append(k).prepend(" ").prepend(g);var h=$("
    ").addClass(Notifications.options.classContainer).append(f);var l=$("
    ").addClass("NotificationText");var c=$("");var e="";if(q>0){j.prepend(Notifications._progress(k,q,m));if(q<100){j.addClass("NotificationHasProgress","normal")}}if("addClass" in a&&a.addClass.length>0){e=a.addClass;j.addClass(e)}if(n!==null&&n.length){k.append(" ").append(n)}else{if("when" in a&&a.created>0){k.append(" "+a.when+"")}}if(a.flagNames.indexOf("debug")!=-1){j.addClass(Notifications.options.classDebug)}if(a.flagNames.indexOf("error")!=-1){j.addClass(Notifications.options.classError)}else{if(a.flagNames.indexOf("warning")!=-1){j.addClass(Notifications.options.classWarning)}else{if(a.flagNames.indexOf("message")!=-1){j.addClass(Notifications.options.classMessage)}}}if(a.html.length>0){l.html(a.html);var p=$("");k.append(" ").append(p);k.click(function(){if(j.hasClass("open")){j.removeClass("open");l.slideUp("fast").removeClass("open");p.removeClass("fa-chevron-circle-down").addClass("fa-chevron-circle-right")}else{l.slideDown("fast").addClass("open");j.addClass("open");p.removeClass("fa-chevron-circle-right").addClass("fa-chevron-circle-down")}});h.append(l);if(d||a.flagNames.indexOf("open")!=-1){if(!d){k.click()}else{j.addClass("open");l.show().addClass("open")}}}c.on("click",function(){Notifications._remove(j)});f.prepend(c);j.append(h);if(b){j.hide();if(Notifications.options.reverse){Notifications.$list.append(j)}else{Notifications.$list.prepend(j)}j.slideDown().effect("highlight",500)}else{if(o){j.show()}else{Notifications.$list.append(j)}}},_remove:function(b){b.addClass("removed").hide();var a=b.siblings(":visible").length;Notifications._updateBugQty(a);clearTimeout(Notifications.updateTimeout);Notifications.updateTimeout=setTimeout("Notifications.update()",1000)},_progress:function(d,a,c){var b=$("
    ").addClass("NotificationProgress").html(""+a+"%").css("width",c+"%").hide();if(a>c){var e=c==0?Notifications.currentDelay/1.4:1750;var f="linear";if(a==100){e=750;f="swing"}else{if(c==0){f="swing"}}if(a>0&&a<=100){b.show().animate({width:a+"%"},{duration:e,easing:f,complete:function(){if(a>=100){b.fadeOut("slow",function(){d.parents(".NotificationHasProgress").removeClass("NotificationHasProgress","slow")})}}})}else{if(a>=100){if(Notifications.$list.find(".NotificationHasProgress").length==0){Notifications.setTurboMode(false)}}else{b.css("width",a+"%").show()}}b.height("100%")}d.append(" "+a+"%");return b},_ghost:function(d,c){if(d.progress>0&&d.progress<100){return}if(Notifications.$menu.hasClass("open")){return}var g=$('');var i=$("
    ").append(g).append(" "+$(""+d.title+"").text());var h=$("
  • ").append(i);var e=Notifications.options.ghostDelay;if(d.flagNames.indexOf("error")>-1){i.addClass(Notifications.options.classError);e=Notifications.options.ghostDelayError}else{if(d.flagNames.indexOf("warning")>-1){i.addClass(Notifications.options.classWarning);e=Notifications.options.ghostDelayError}else{i.addClass(Notifications.options.classMessage)}}Notifications.$ghosts.append(h.hide());Notifications.ghostsActive++;var j=Notifications.options.ghostFadeSpeed;var f=Notifications.options.ghostOpacity;var b=100*c;var a=$(window).height();if(j.length==0){b=200*c}setTimeout(function(){if(j.length>0){h.fadeTo(j,f)}else{h.show().css("opacity",f)}var l=h.offset().top;var k=h.height();if(l+k>(a/2)){Notifications.$ghosts.animate({top:"-="+(k+3)},"fast")}setTimeout(function(){var m=function(){h.addClass("removed");Notifications.ghostsActive--;if(Notifications.ghostsActive==0){Notifications.$ghosts.children("li").remove()}};if(j.length>0){h.fadeTo(j,0.01,m)}else{h.css("opacity",0.01);m()}},e)},b);d.ghostShown=true},clickBug:function(){var a=Notifications.$menu;if(a.hasClass("open")){a.slideUp("fast",function(){a.removeClass("open");Notifications.$bug.removeClass("open");clearTimeout(Notifications.timerTimeout)})}else{if(!a.hasClass("init")){a.prependTo($("body"));a.addClass("init")}a.slideDown("fast",function(){a.addClass("open");Notifications.$bug.addClass("open");Notifications._startTimeUpdater()});Notifications.$ghosts.find("li").hide()}return false},_startTimeUpdater:function(){if(Notifications.timeNow>0){Notifications.timeNow+=1}Notifications._updateTime();Notifications.timerTimeout=setTimeout("Notifications._startTimeUpdater()",1000)},_show:function(d,f,b,c,a){var e={id:0,title:f,from:"",created:0,modified:0,when:"now",href:a,icon:c,flags:0,flagNames:d+" notice",progress:0,html:b,qty:1};Notifications.add(e);if(Notifications.numRender>0){Notifications.render()}},message:function(d,b,c,a){if(typeof b=="undefined"){b=""}if(typeof c=="undefined"){c=Notifications.options.iconMessage}if(typeof a=="undefined"){a=""}Notifications._show("message",d,b,c,a)},warning:function(d,b,c,a){if(typeof b=="undefined"){b=""}if(typeof c=="undefined"){c=Notifications.options.iconWarning}if(typeof a=="undefined"){a=""}Notifications._show("warning",d,b,c,a)},error:function(d,b,c,a){if(typeof b=="undefined"){b=""}if(typeof c=="undefined"){c=Notifications.options.iconError}if(typeof a=="undefined"){a=""}Notifications._show("error",d,b,c,a)},init:function(a){$.extend(Notifications.options,a);Notifications.currentDelay=Notifications.options.updateDelay;Notifications.$menu=$("#NotificationMenu");Notifications.$bug=$("#NotificationBug");Notifications.$list=$("#NotificationList");Notifications.$ghosts=$("#NotificationGhosts");if(!Notifications.$bug.length){return}Notifications.$menu.hide();Notifications.$bug.click(Notifications.clickBug);Notifications.useSession=typeof sessionStorage!="undefined";Notifications.updateTimeout=setTimeout(Notifications.update,Notifications.currentDelay);$("#ProcessPageSearchForm input").dblclick(function(b){Notifications.message("ProcessWire Notifications v"+Notifications.options.version,"Grab a coffee and come and visit us at the ProcessWire support forums.

    ","coffee fa-spin");return false});$(document).on("pw-modal-opened",function(){if(Notifications.$bug.is(":visible")){Notifications.$bug.fadeOut().addClass("hidden-for-modal")}if(Notifications.$menu.is(":visible")){Notifications.$menu.hide().addClass("hidden-for-modal")}}).on("pw-modal-closed",function(){if(Notifications.$bug.hasClass("hidden-for-modal")){Notifications.$bug.fadeIn().removeClass("hidden-for-modal")}if(Notifications.$menu.hasClass("hidden-for-modal")){Notifications.$menu.slideDown().removeClass("hidden-for-modal")}});if(Notifications.useSession&&Notifications.options.processKey.length){if(typeof sessionStorage.pwWindowName=="undefined"||sessionStorage.pwWindowName.indexOf("PW")!==0){sessionStorage.pwWindowName="PW"+Math.floor(Math.random()*65536).toString()+Math.floor(Math.random()*65536).toString()}}}};