Вход Регистрация
Файл: touchSpace/js/notifications.js
Строк: 501
<?php
var Notifications=function(){this.lock=!1,this.blinker={interval:null,old_title:null},this.ncounter=0,this.beacon_interval=null,this.window_active="true"!=cookie.get("spacesactive"),this.top_notif_queue=[],this.top_notif_queue_lock=!1,this.page_load_time=(new Date).getTime(),this.oncounterchange=null,this.__construct()};extend(Notifications,{COUNTER:{JOURNAL:1,LENTA:2,MAIL:3},counters:{1:{title:"Журнал",id:"jour_notif_cnt"},2:{title:"Лента",id:"lent_notif_cnt"},3:{title:"Почта",id:"mail_notif_cnt"}},_instance:null,instance:function(){return Notifications._instance||(Notifications._instance=new Notifications),Notifications._instance}}),extend(Notifications.prototype,{__construct:function(){var t,i=this;void 0!==document.onfocusin?(document.onfocusin=class_func(this,this.onFocusWindow),document.onfocusout=class_func(this,this.onBlurWindow)):(window.onfocus=class_func(this,this.onFocusWindow),window.onblur=class_func(this,this.onBlurWindow)),cookie.set("spacesactive","true",{expires:7}),page_loader&&(page_loader.onRequestStart("notifications",function(){i.lock=!0}),page_loader.onRequestEnd("notifications",function(){$("#top_notif_place").find(".notification_hide").click(),$(".lp_notif_message").click(),i.lock=!1})),play_sound&&init_sound_manager(function(){soundManager.createSound({id:"notifSound",url:ICONS_BASEURL+"sounds/newMessage.mp3"})}),i.beacon(!0),pushstream.addMessageHandler("notifications",class_func(this,this.onLongPolling)),$(window).on("scroll.notif",function(){var t=$(window).scrollTop();$(".lp_notif_wrapper").each(function(){50>=t?($(this).remove(),i.top_notif_queue=[]):$(this).css({top:t+"px"})})}),t="touchmove.activity_detect touchstart.activity_detect keydown.activity_detect click.activity_detect MozMousePixelScroll.activity_detect mousewheel.activity_detect wheel.activity_detect scroll.activity_detect mousemove.activity_detect",$(window).on(t,function(t){t.originalEvent&&(i.window_active=!0,$(window).off(".activity_detect"))})},onLongPolling:function(t){var i,n=this;t.act==Spaces.LongPollingTypes.NOTIFICATION_SEND?$.inArray(cookie.get("sid"),t.sids)>=0&&n.pushNotification(t)&&n.showNewEvent("Новое событие"):t.act==Spaces.LongPollingTypes.TOP_COUNTER_UPDATE?n.updateCounter(t.type,t.cnt,{important:!!t.important}):t.act==Spaces.LongPollingTypes.COMM_COUNTER_UPDATE&&(i=$("#cc"+t.com_id),i.length&&(i.find(".acnt").text(t.cnt),t.cnt>0?i.show():i.hide()))},beacon:function(t){var i=this;return t?i.beacon_interval=setInterval(function(){Spaces.api("common.beacon")},24e4):clearInterval(i.beacon_interval),this},onBlurWindow:function(){this.window_active=!1,cookie.set("spacesactive","false",{expires:7}),$(".lp_notif_wrapper").remove()},onFocusWindow:function(){this.titleBlink(!1),this.window_active=!0,cookie.set("spacesactive","true",{expires:7}),this.showBackgroundNotifications()},updateCounter:function(t,i,n){var e,o,s;return n=extend({blink:!0,important:!1},n||{}),(e=Notifications.counters[t])?(o=$("#"+e.id),parseInt(o.text())==i?this:(s=jQuery.Event("counterchange"),s.counterType=t,$(this).trigger(s),s.isDefaultPrevented()?this:(void 0!==s.counterValue&&(i=s.counterValue),i>0?o.text(i):o.stop(!0,!0).fadeOut(function(){o.text("")}),i>0&&(this.showNewEvent(e.title+" +"+i),n.blink&&$(window).scrollTop()<10?o.not(":animated").length>0&&o.fadeTo(500,.2).fadeTo(499,1).fadeTo(500,.2).fadeTo(499,1).fadeTo(500,.2).fadeTo(499,1):o.fadeTo(0,1)),this))):(console.error("Unknown counter type: ",t),this)},showNewEvent:function(t){var i=this,n=cookie.get("spacesactive");return cookie.set("pageLoadTime",i.page_load_time,{expires:7}),"true"==n?i.window_active&&i.pushTopNotification({text:t}):setTimeout(function(){i.titleBlink(t),i.playSoundInBg()},300),this},showNotification:function(t,i,n){n=extend({silent:!0},n||{}),i=i||"info";var e={error:3,warning:2,info:1};return this.renderNotification({id:"user_"+(new Date).getTime(),generic:!0,text:t,severity:e[i]}),n.silent||this.showNewEvent("Новое событие"),this},pushNotifications:function(t){for(var i=0;i<t.length;++i)this.pushNotification(t[i]);return this},pushNotification:function(t){var i=parseInt(cookie.get("qnotid"))||0;return this.lock||i>=t.id?(console.error(i>=t.id?"Старая":"Залоченная","нотификация",t,new Date),!1):(this.window_active&&cookie.set("qnotid",t.id,{expires:7}),this.renderNotification(t),!0)},closeNotification:function(t){var i,n=$("#notif_"+t);return n.length&&(n.remove(),--this.ncounter),i=$("#top_notif_place .notification_item").first(),i&&(i.find(".notification_counter").text(this.ncounter).toggle(1!=this.ncounter),i.show()),this},renderNotification:function(t){var i,n=this,e={1:"info",2:"busi",3:"error"},o=$("#top_notif_place");return this.ncounter>0&&o.find(".notification_item").first().find(".notification_counter").text(this.ncounter+1).removeClass("hide"),i=$('<div id="notif_'+t.id+'" class="oh notification_item '+(this.ncounter||!t.generic&&!this.window_active?"hide ":"")+(t.generic|this.window_active?"shown ":"to_show ")+e[t.severity]+'"><img src="'+ICONS_BASEURL+'cross_r.gif" alt="" class="pointer right notification_hide notif_close" /><span class="notification_counter '+(this.ncounter?"":"hide ")+'">'+(this.ncounter+1)+"</span> "+Spaces.prepareLink(t.text)+"</div>"),i.prop("nid",t.id).prop("generic",!!t.generic),i.find(".notif_close").on("click",{id:t.id},function(t){t.preventDefault(),n.closeNotification(t.data.id)}),++this.ncounter,o.append(i),this},showBackgroundNotifications:function(){var t,i=$("#top_notif_place"),n=parseInt(cookie.get("qnotid")||0),e=i.find(".to_show");for(t=0;t<e.length;++t)e[t].nid<=n?this.closeNotification(e[t].nid):(n=parseInt(cookie.get("qnotid")||0),n<e[t].nid&&cookie.set("qnotid",e[t].nid,{expires:7}),$(e[t]).removeClass("to_show").addClass("show"));return this},pushTopNotification:function(t){return $(window).scrollTop()<=50?this:(t.id=t.id||(new Date).getTime(),this.top_notif_queue.push(t),this.topNotifQueue())},topNotifQueue:function(t){var i,n,e,o,s=this;if(t||!this.top_notif_queue_lock)return this.top_notif_queue.length?(this.top_notif_queue_lock=!0,i=this.top_notif_queue.shift(),n=function(){$(this).remove(),s.topNotifQueue(!0)},e=function(){var t=s.renderTopNotif(i);t.slideDown(400,function(){s.top_notif_queue.length>0?t.delay(2e3).slideUp(400,function(){$(this).remove(),s.topNotifQueue(!0)}):(t.find(".lp_notif_message").delay(5e3).fadeTo(400,.5),s.topNotifQueue(!0))})},o=$(".lp_notif_wrapper"),o.length>0?o.first().slideUp(400,function(){$(this).remove(),e()}):e(),this):void(this.top_notif_queue_lock=!1)},renderTopNotif:function(t){var i=this,n=$('<div id="top_notif_id_'+t.id+'" class="lp_notif_wrapper"><div class="lp_notif_message">'+t.text+"</div></div>");return n.css({top:$(window).scrollTop()}),n.find(".lp_notif_message").on("click",{id:t.id},function(t){t.preventDefault(),i.closeTopNotif(t.data.id)}),$(document.body).append(n),n},closeTopNotif:function(t){return $("html, body").scrollTop(0),$("#top_notif_id_"+t).remove(),this},playSound:function(){return init_sound_manager(function(){soundManager.stop("notifSound"),soundManager.play("notifSound")}),this},playSoundInBg:function(){var t=parseInt(cookie.get("pageLoadTime")||0);return this.page_load_time==t&&play_sound&&this.playSound(),this},titleBlink:function(t){var i,n=this,e=!0;return n.blinker.interval&&(document.title=n.blinker.old_title,clearInterval(n.blinker.interval),n.blinker.interval=null),t&&(i=function(){e?(n.blinker.old_title=document.title,document.title=t,e=!1):(document.title=n.blinker.old_title,e=!0),"true"==cookie.get("spacesactive")&&n.titleBlink(!1)},i(),n.blinker.interval=setInterval(i,1e3)),this}}),Spaces.notifications=new Notifications;
?>
Онлайн: 0
Реклама