var src = null; var prev = null; var livetime = null; var msie = false; var stopped = false; var totStopped = false; var timer = null; var pr = 0; var liking = 0; var in_progress = false; var langSelect = false; var commentBusy = false; var last_popup_menu = null; var last_popup_button = null; var scroll_next = false; var next_page = 1; var page_load = true; var loadingPage = true; var pageHasMoreContent = true; var divmore_height = 400; var last_filestorage_id = null; var mediaPlaying = false; var contentHeightDiff = 0; var liveRecurse = 0; var savedTitle = ''; var initialLoad = true; var window_needs_alert = true; var sse_bs_active = false; var sse_offset = 0; var sse_type; var sse_partial_result = false; var sse_mids = []; // take care of tab/window reloads on channel change if(localStorage.getItem('uid') !== localUser.toString()) { localStorage.clear(); sessionStorage.clear(); localStorage.setItem('uid', localUser.toString()); } window.onstorage = function(e) { if(e.key === 'uid' && parseInt(e.newValue) !== localUser) { if(window_needs_alert) { window_needs_alert = false; alert("Your identity has changed. Page reload required!"); window.location.reload(); return; } } } $.ajaxSetup({cache: false}); $(document).ready(function() { $(document).on('click focus', '.comment-edit-form', handle_comment_form); $(document).on('click', '.conversation-settings-link', getConversationSettings); $(document).on('click', '#settings_module_ajax_submit', postConversationSettings); $(document).on('click focus', '.comment-edit-form textarea', function(e) { if(! this.autocomplete_handled) { /* autocomplete @nicknames */ $(this).editor_autocomplete(baseurl+"/acl?f=&n=1"); /* autocomplete bbcode */ $(this).bbco_autocomplete('bbcode'); this.autocomplete_handled = true; } }); var tf = new Function('n', 's', 'var k = s.split("/")['+aStr['plural_func']+']; return (k ? k : s);'); jQuery.timeago.settings.strings = { prefixAgo : aStr['t01'], prefixFromNow : aStr['t02'], suffixAgo : aStr['t03'], suffixFromNow : aStr['t04'], seconds : aStr['t05'], minute : aStr['t06'], minutes : function(value){return tf(value, aStr['t07']);}, hour : aStr['t08'], hours : function(value){return tf(value, aStr['t09']);}, day : aStr['t10'], days : function(value){return tf(value, aStr['t11']);}, month : aStr['t12'], months : function(value){return tf(value, aStr['t13']);}, year : aStr['t14'], years : function(value){return tf(value, aStr['t15']);}, wordSeparator : aStr['t16'], numbers : aStr['t17'], }; if(typeof(window.SharedWorker) === 'undefined') { // notifications with multiple tabs open will not work very well in this scenario var evtSource = new EventSource('/sse'); evtSource.addEventListener('notifications', function(e) { var obj = JSON.parse(e.data); sse_handleNotifications(obj, false, false); }, false); document.addEventListener('visibilitychange', function() { if (!document.hidden) { sse_offset = 0; sse_bs_init(); } }, false); } else { var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser); myWorker.port.onmessage = function(e) { obj = e.data; console.log(obj); sse_handleNotifications(obj, false, false); } myWorker.onerror = function(e) { myWorker.port.close(); } myWorker.port.start(); } sse_bs_init(); $('.notification-link').on('click', { replace: true, followup: false }, sse_bs_notifications); $('.notification-filter').on('keypress', function(e) { if(e.which == 13) { // enter this.blur(); sse_offset = 0; $("#nav-" + sse_type + "-menu").html(''); $("#nav-" + sse_type + "-loading").show(); var cn_val = $('#cn-' + sse_type + '-input').length ? $('#cn-' + sse_type + '-input').val().toString().toLowerCase() : ''; $.get('/sse_bs/' + sse_type + '/' + sse_offset + '?nquery=' + encodeURIComponent(cn_val), function(obj) { console.log('sse: bootstraping ' + sse_type); console.log(obj); sse_handleNotifications(obj, true, false); sse_bs_active = false; sse_partial_result = true; sse_offset = obj[sse_type].offset; if(sse_offset < 0) $("#nav-" + sse_type + "-loading").hide(); }); } }); $('.notifications-textinput-clear').on('click', function(e) { if(! sse_partial_result) return; $("#nav-" + sse_type + "-menu").html(''); $("#nav-" + sse_type + "-loading").show(); $.get('/sse_bs/' + sse_type, function(obj) { console.log('sse: bootstraping ' + sse_type); console.log(obj); sse_handleNotifications(obj, true, false); sse_bs_active = false; sse_partial_result = false; sse_offset = obj[sse_type].offset; if(sse_offset < 0) $("#nav-" + sse_type + "-loading").hide(); }); }); $('.notification-content').on('scroll', function() { if(this.scrollTop > this.scrollHeight - this.clientHeight - (this.scrollHeight/7)) { if(!sse_bs_active) sse_bs_notifications(sse_type, false, true); } }); //mod_mail only $(".mail-conv-detail .autotime").timeago(); savedTitle = document.title; updateInit(); /* $('a.notification-link').click(function(e){ var notifyType = $(this).data('type'); if(! $('#nav-' + notifyType + '-sub').hasClass('show')) { loadNotificationItems(notifyType); sessionStorage.setItem('notification_open', notifyType); } else { sessionStorage.removeItem('notification_open'); } }); if(sessionStorage.getItem('notification_open') !== null) { var notifyType = sessionStorage.getItem('notification_open'); $('#nav-' + notifyType + '-sub').addClass('show'); loadNotificationItems(notifyType); } */ // Allow folks to stop the ajax page updates with the pause/break key $(document).keydown(function(event) { if(event.keyCode == '8') { var target = event.target || event.srcElement; if (!/input|textarea/i.test(target.nodeName)) { return false; } } if(event.keyCode == '19' || (event.ctrlKey && event.which == '32')) { event.preventDefault(); if(stopped === false) { stopped = true; if (event.ctrlKey) { totStopped = true; } $('#pause').html(''); } else { unpause(); } } else { if (!totStopped) { unpause(); } } }); var e = document.getElementById('content-complete'); if(e) pageHasMoreContent = false; initialLoad = false; }); function getConversationSettings() { $.get('settings/conversation/?f=&aj=1',function(data) { $('#conversation_settings_body').html(data); }); } function postConversationSettings() { $.post( 'settings/conversation', $('#settings_module_ajax_form').serialize() + "&auto_update=" + next_page ); if(next_page === 1) { page_load = true; } $('#conversation_settings').modal('hide'); if(timer) clearTimeout(timer); timer = setTimeout(updateInit,100); return false; } function datasrc2src(selector) { $(selector).each(function(i, el) { $(el).attr("src", $(el).data("src")); $(el).removeAttr("data-src"); }); } function confirmDelete() { return confirm(aStr.delitem); } function handle_comment_form(e) { e.stopPropagation(); //handle eventual expanded forms var expanded = $('.comment-edit-text.expanded'); var i = 0; if(expanded.length) { expanded.each(function() { var ex_form = $(expanded[i].form); var ex_fields = ex_form.find(':input[type=text], textarea'); var ex_fields_empty = true; ex_fields.each(function() { if($(this).val() != '') ex_fields_empty = false; }); if(ex_fields_empty) { ex_form.find('.comment-edit-text').removeClass('expanded').attr('placeholder', aStr.comment); ex_form.find(':not(.comment-edit-text)').hide(); } i++; }); } // handle clicked form var form = $(this); var fields = form.find(':input[type=text], textarea'); var fields_empty = true; if(form.find('.comment-edit-text').length) { var commentElm = form.find('.comment-edit-text').attr('id'); var submitElm = commentElm.replace(/text/,'submit'); $('#' + commentElm).addClass('expanded').removeAttr('placeholder'); $('#' + commentElm).attr('tabindex','9'); $('#' + submitElm).attr('tabindex','10'); form.find(':not(:visible)').show(); } // handle click outside of form (close empty forms) $(document).on('click', function(e) { fields.each(function() { if($(this).val() != '') fields_empty = false; }); if(fields_empty) { var emptyCommentElm = form.find('.comment-edit-text').attr('id'); var emptySubmitElm = commentElm.replace(/text/,'submit'); $('#' + emptyCommentElm).removeClass('expanded').attr('placeholder', aStr.comment); $('#' + emptyCommentElm).removeAttr('tabindex'); $('#' + emptySubmitElm).removeAttr('tabindex'); form.find(':not(.comment-edit-text)').hide(); form.find(':input[name=parent]').val(emptyCommentElm.replace(/\D/g,'')); var btn = form.find(':button[type=submit]').html(); form.find(':button[type=submit]').html(btn.replace(/<[^>]*>/g, '').trim()); form.find(':button[type=submit]').prop('title', ''); } }); var commentSaveTimer = null; var emptyCommentElm = form.find('.comment-edit-text').attr('id'); var convId = emptyCommentElm.replace('comment-edit-text-',''); $(document).on('focusout','#' + emptyCommentElm,function(e){ if(commentSaveTimer) clearTimeout(commentSaveTimer); commentSaveChanges(convId,true); commentSaveTimer = null; }); $(document).on('focusin','#' + emptyCommentElm,function(e){ commentSaveTimer = setTimeout(function () { commentSaveChanges(convId,false); },10000); }); function commentSaveChanges(convId, isFinal) { if(typeof isFinal === 'undefined') isFinal = false; if(auto_save_draft) { tmp = $('#' + emptyCommentElm).val(); if(tmp) { localStorage.setItem("comment_body-" + convId, tmp); } else { localStorage.removeItem("comment_body-" + convId); } if( !isFinal) { commentSaveTimer = setTimeout(commentSaveChanges,10000,convId); } } } } function commentClose(obj, id) { if(obj.value === '') { obj.value = aStr.comment; $("#comment-edit-text-" + id).removeClass("expanded"); $("#mod-cmnt-wrap-" + id).hide(); $("#comment-tools-" + id).hide(); $("#comment-edit-anon-" + id).hide(); return true; } return false; } function showHideCommentBox(id) { if( $('#comment-edit-form-' + id).is(':visible')) { $('#comment-edit-form-' + id).hide(); } else { $('#comment-edit-form-' + id).show(); } } function commentInsert(obj, id) { var tmpStr = $("#comment-edit-text-" + id).val(); if(tmpStr == '$comment') { tmpStr = ''; $("#comment-edit-text-" + id).addClass("expanded"); openMenu("comment-tools-" + id); } var ins = $(obj).html(); ins = ins.replace('<','<'); ins = ins.replace('>','>'); ins = ins.replace('&','&'); ins = ins.replace('"','"'); $("#comment-edit-text-" + id).val(tmpStr + ins); } function insertbbcomment(comment, BBcode, id) { // allow themes to override this if(typeof(insertFormatting) != 'undefined') return(insertFormatting(comment, BBcode, id)); var urlprefix = ((BBcode == 'url') ? '#^' : ''); var tmpStr = $("#comment-edit-text-" + id).val(); if(tmpStr == comment) { tmpStr = ""; $("#comment-edit-text-" + id).addClass("expanded"); openMenu("comment-tools-" + id); $("#comment-edit-text-" + id).val(tmpStr); } textarea = document.getElementById("comment-edit-text-" +id); if (document.selection) { textarea.focus(); selected = document.selection.createRange(); selected.text = urlprefix+"["+BBcode+"]" + selected.text + "[/"+BBcode+"]"; } else if (textarea.selectionStart || textarea.selectionStart == "0") { var start = textarea.selectionStart; var end = textarea.selectionEnd; textarea.value = textarea.value.substring(0, start) + urlprefix+"["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length); } return true; } function inserteditortag(BBcode, id) { // allow themes to override this if(typeof(insertEditorFormatting) != 'undefined') return(insertEditorFormatting(BBcode)); textarea = document.getElementById(id); if (document.selection) { textarea.focus(); selected = document.selection.createRange(); selected.text = urlprefix+"["+BBcode+"]" + selected.text + "[/"+BBcode+"]"; } else if (textarea.selectionStart || textarea.selectionStart == "0") { var start = textarea.selectionStart; var end = textarea.selectionEnd; textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length); } return true; } function insertCommentAttach(comment,id) { activeCommentID = id; activeCommentText = comment; $('body').css('cursor', 'wait'); $('#invisible-comment-upload').trigger('click'); return false; } function insertCommentURL(comment, id) { reply = prompt(aStr.linkurl); if(reply && reply.length) { reply = bin2hex(reply); $('body').css('cursor', 'wait'); $.get('linkinfo?f=&binurl=' + reply, function(data) { var tmpStr = $("#comment-edit-text-" + id).val(); if(tmpStr == comment) { tmpStr = ""; $("#comment-edit-text-" + id).addClass("expanded"); openMenu("comment-tools-" + id); $("#comment-edit-text-" + id).val(tmpStr); } textarea = document.getElementById("comment-edit-text-" +id); textarea.value = textarea.value + data; preview_comment(id); $('body').css('cursor', 'auto'); }); } return true; } function doFollowAuthor(url) { $.get(url, function(data) { notificationsUpdate(); }); return true; } function viewsrc(id) { $.colorbox({href: 'viewsrc/' + id, maxWidth: '80%', maxHeight: '80%' }); } function showHideComments(id) { if( $('#collapsed-comments-' + id).is(':visible')) { $('#collapsed-comments-' + id + ' .autotime').timeago('dispose'); $('#collapsed-comments-' + id).hide(); $('#hide-comments-' + id).html(aStr.showmore); $('#hide-comments-total-' + id).show(); } else { $('#collapsed-comments-' + id + ' .autotime').timeago(); $('#collapsed-comments-' + id).show(); $('#hide-comments-' + id).html(aStr.showfewer); $('#hide-comments-total-' + id).hide(); } } function openClose(theID) { if(document.getElementById(theID).style.display == "block") { document.getElementById(theID).style.display = "none"; } else { document.getElementById(theID).style.display = "block"; } } function openCloseTR(theID) { if(document.getElementById(theID).style.display == "table-row") { document.getElementById(theID).style.display = "none"; } else { document.getElementById(theID).style.display = "table-row"; } } function closeOpen(theID) { if(document.getElementById(theID).style.display == "none") { document.getElementById(theID).style.display = "block"; } else { document.getElementById(theID).style.display = "none"; } } function openMenu(theID) { document.getElementById(theID).style.display = "block"; } function closeMenu(theID) { document.getElementById(theID).style.display = "none"; } function markRead(notifType) { $.get('ping?f=&markRead='+notifType); $('.' + notifType + '-button').hide(); $('#nav-' + notifType + '-sub').removeClass('show'); sessionStorage.removeItem(notifType + '_notifications_cache'); sessionStorage.removeItem('notification_open'); if(timer) clearTimeout(timer); timer = setTimeout(updateInit,2000); } function markItemRead(itemId) { $.get('ping?f=&markItemRead='+itemId); $('.unseen-wall-indicator-'+itemId).hide(); } /* function notificationsUpdate(cached_data) { var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : ''); if(cached_data !== undefined) { handleNotifications(cached_data); } else { $.get(pingCmd,function(data) { // Put the object into storage if(! data) return; sessionStorage.setItem('notifications_cache', JSON.stringify(data)); var fnotifs = []; if(data.forums) { $.each(data.forums_sub, function() { fnotifs.push(this); }); handleNotificationsItems('forums', fnotifs); } if(data.invalid == 1) { window.location.href=window.location.href; } handleNotifications(data); $.jGrowl.defaults.closerTemplate = '
(.*?)<\/code>/gi,"[code]$1[/code]");
rep(/<\/(strong|b)>/gi,"[/b]");
rep(/<(strong|b)>/gi,"[b]");
rep(/<\/(em|i)>/gi,"[/i]");
rep(/<(em|i)>/gi,"[i]");
rep(/<\/u>/gi,"[/u]");
rep(/(.*?)<\/span>/gi,"[u]$1[/u]");
rep(//gi,"[u]");
rep(/]*>/gi,"[quote]");
rep(/<\/blockquote>/gi,"[/quote]");
rep(/
/gi,"[hr]");
rep(/
/gi,"\n");
rep(/
/gi,"\n");
rep(/
/gi,"\n");
rep(//gi,"");
rep(/<\/p>/gi,"\n");
rep(/ /gi," ");
rep(/"/gi,"\"");
rep(/</gi,"<");
rep(/>/gi,">");
rep(/&/gi,"&");
return y;
}
function b2h(s) {
var y = s;
function rep(re, str) {
y = y.replace(re,str);
}
rep(/\&/gi,"&");
rep(/\/gi,">");
rep(/\"/gi,""");
rep(/\n/gi,"
");
rep(/\[b\]/gi,"");
rep(/\[\/b\]/gi,"");
rep(/\[i\]/gi,"");
rep(/\[\/i\]/gi,"");
rep(/\[u\]/gi,"");
rep(/\[\/u\]/gi,"");
rep(/\[hr\]/gi,"
");
rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2");
rep(/\[url\](.*?)\[\/url\]/gi,"$1");
rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"");
rep(/\[img\](.*?)\[\/img\]/gi,"");
rep(/\[zrl=([^\]]+)\](.*?)\[\/zrl\]/gi,"$2");
rep(/\[zrl\](.*?)\[\/zrl\]/gi,"$1");
rep(/\[zmg=(.*?)x(.*?)\](.*?)\[\/zmg\]/gi,"");
rep(/\[zmg\](.*?)\[\/zmg\]/gi,"");
rep(/\[list\](.*?)\[\/list\]/gi, '$1
');
rep(/\[list=\](.*?)\[\/list\]/gi, '$1
');
rep(/\[list=1\](.*?)\[\/list\]/gi, '$1
');
rep(/\[list=i\](.*?)\[\/list\]/gi,'$1
');
rep(/\[list=I\](.*?)\[\/list\]/gi, '$1
');
rep(/\[list=a\](.*?)\[\/list\]/gi, '$1
');
rep(/\[list=A\](.*?)\[\/list\]/gi, '$1
');
rep(/\[li\](.*?)\[\/li\]/gi, '- $1
');
rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2");
rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2");
rep(/\[code\](.*?)\[\/code\]/gi,"$1
");
rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"$1
");
rep(/\[video\](.*?)\[\/video\]/gi,"$1");
rep(/\[audio\](.*?)\[\/audio\]/gi,"$1");
rep(/\[\&\;([#a-z0-9]+)\;\]/gi,'&$1;');
rep(/\<(.*?)(src|href)=\"[^hfm](.*?)\>/gi,'<$1$2="">');
return y;
}
function zid(s) {
if((! s.length) || (s.indexOf('zid=') != (-1)))
return s;
if(! zid.length)
return s;
var has_params = ((s.indexOf('?') == (-1)) ? false : true);
var achar = ((has_params) ? '&' : '?');
s = s + achar + 'f=&zid=' + zid;
return s;
}
function sse_bs_init() {
if(sessionStorage.getItem('notification_open') !== null || typeof sse_type !== 'undefined' ) {
if(typeof sse_type === 'undefined')
sse_type = sessionStorage.getItem('notification_open');
$("#nav-" + sse_type + "-sub").addClass('show');
sse_bs_notifications(sse_type, true, false);
}
else {
$.get('/sse_bs',function(obj) {
console.log(obj);
sse_handleNotifications(obj, true, false);
});
}
}
function sse_bs_notifications(e, replace, followup) {
sse_bs_active = true;
var manual = false;
if(typeof replace === 'undefined')
replace = e.data.replace;
if(typeof followup === 'undefined')
followup = e.data.followup;
if(typeof e === 'string') {
sse_type = e;
}
else {
manual = true;
sse_offset = 0;
sse_type = e.target.dataset.sse_type;
}
if(typeof sse_type === 'undefined')
return;
if(followup || !manual || !($('#nav-' + sse_type + '-sub').hasClass('collapse') && $('#nav-' + sse_type + '-sub').hasClass('show'))) {
if(sse_offset >= 0) {
$("#nav-" + sse_type + "-loading").show();
}
sessionStorage.setItem('notification_open', sse_type);
if(sse_offset !== -1 || replace) {
var cn_val = (($('#cn-' + sse_type + '-input').length && sse_partial_result) ? $('#cn-' + sse_type + '-input').val().toString().toLowerCase() : '');
$.get('/sse_bs/' + sse_type + '/' + sse_offset + '?nquery=' + encodeURIComponent(cn_val), function(obj) {
console.log('sse: bootstraping ' + sse_type);
console.log(obj);
sse_handleNotifications(obj, replace, followup);
sse_bs_active = false;
sse_offset = obj[sse_type].offset;
if(sse_offset < 0)
$("#nav-" + sse_type + "-loading").hide();
});
}
else
$("#nav-" + sse_type + "-loading").hide();
}
else {
sessionStorage.removeItem('notification_open');
}
}
function sse_handleNotifications(obj, replace, followup) {
if(
(obj.network && obj.network.count) ||
(obj.home && obj.home.count) ||
(obj.intros && obj.intros.count) ||
(obj.register && obj.register.count) ||
(obj.mail && obj.mail.count) ||
(obj.all_events && obj.all_events.count) ||
(obj.notify && obj.notify.count) ||
(obj.files && obj.files.count) ||
(obj.pubs && obj.pubs.count) ||
(obj.forums && obj.forums.count)
) {
$('.notifications-btn').css('opacity', 1);
$('#no_notifications').hide();
}
else {
$('.notifications-btn').css('opacity', 0.5);
$('#navbar-collapse-1').removeClass('show');
$('#no_notifications').show();
}
if(
(obj.home && obj.home.count) ||
(obj.intros && obj.intros.count) ||
(obj.register && obj.register.count) ||
(obj.mail && obj.mail.count) ||
(obj.notify && obj.notify.count) ||
(obj.files && obj.files.count)
) {
$('.notifications-btn-icon').removeClass('fa-exclamation-circle');
$('.notifications-btn-icon').addClass('fa-exclamation-triangle');
}
if(
!(obj.home && obj.home.count) &&
!(obj.intros && obj.intros.count) &&
!(obj.register && obj.register.count) &&
!(obj.mail && obj.mail.count) &&
!(obj.notify && obj.notify.count) &&
!(obj.files && obj.files.count)
) {
$('.notifications-btn-icon').removeClass('fa-exclamation-triangle');
$('.notifications-btn-icon').addClass('fa-exclamation-circle');
}
if(obj.all_events_today && obj.all_events_today.count) {
$('.all_events-update').removeClass('badge-secondary');
$('.all_events-update').addClass('badge-danger');
}
else {
$('.all_events-update').removeClass('badge-danger');
$('.all_events-update').addClass('badge-secondary');
}
// network
if(obj.network && obj.network.count) {
$('.network-button').fadeIn();
if(replace || followup)
$('.network-update').html(Number(obj.network.count));
else
$('.network-update').html(Number(obj.network.count) + Number($('.network-update').html()));
}
if(obj.network && obj.network.notifications.length)
sse_handleNotificationsItems('network', obj.network.notifications, replace, followup);
// home
if(obj.home && obj.home.count) {
$('.home-button').fadeIn();
if(replace || followup)
$('.home-update').html(Number(obj.home.count));
else
$('.home-update').html(Number(obj.home.count) + Number($('.home-update').html()));
}
if(obj.home && obj.home.notifications.length)
sse_handleNotificationsItems('home', obj.home.notifications, replace, followup);
// notify
if(obj.notify && obj.notify.count) {
$('.notify-button').fadeIn();
if(replace || followup)
$('.notify-update').html(Number(obj.notify.count));
else
$('.notify-update').html(Number(obj.notify.count) + Number($('.notify-update').html()));
}
if(obj.notify && obj.notify.notifications.length)
sse_handleNotificationsItems('notify', obj.notify.notifications, replace, false);
// intros
if(obj.intros && obj.intros.count) {
$('.intros-button').fadeIn();
if(replace || followup)
$('.intros-update').html(Number(obj.intros.count));
else
$('.intros-update').html(Number(obj.intros.count) + Number($('.intros-update').html()));
}
if(obj.intros && obj.intros.notifications.length)
sse_handleNotificationsItems('intros', obj.intros.notifications, replace, false);
// forums
if(obj.forums && obj.forums.count) {
$('.forums-button').fadeIn();
if(replace || followup)
$('.forums-update').html(Number(obj.forums.count));
else
$('.forums-update').html(Number(obj.forums.count) + Number($('.forums-update').html()));
}
if(obj.forums && obj.forums.notifications.length)
sse_handleNotificationsItems('forums', obj.forums.notifications, replace, false);
// pubs
if(obj.pubs && obj.pubs.count) {
$('.pubs-button').fadeIn();
if(replace || followup)
$('.pubs-update').html(Number(obj.pubs.count));
else
$('.pubs-update').html(Number(obj.pubs.count) + Number($('.pubs-update').html()));
}
if(obj.pubs && obj.pubs.notifications.length)
sse_handleNotificationsItems('pubs', obj.pubs.notifications, replace, followup);
// files
if(obj.files && obj.files.count) {
$('.files-button').fadeIn();
if(replace || followup)
$('.files-update').html(Number(obj.files.count));
else
$('.files-update').html(Number(obj.files.count) + Number($('.files-update').html()));
}
if(obj.files && obj.files.notifications.length)
sse_handleNotificationsItems('files', obj.files.notifications, replace, false);
// mail
if(obj.mail && obj.mail.count) {
$('.mail-button').fadeIn();
if(replace || followup)
$('.mail-update').html(Number(obj.mail.count));
else
$('.mail-update').html(Number(obj.mail.count) + Number($('.mail-update').html()));
}
if(obj.mail && obj.mail.notifications.length)
sse_handleNotificationsItems('mail', obj.mail.notifications, replace, false);
// all_events
if(obj.all_events && obj.all_events.count) {
$('.all_events-button').fadeIn();
if(replace || followup)
$('.all_events-update').html(Number(obj.all_events.count));
else
$('.all_events-update').html(Number(obj.all_events.count) + Number($('.all_events-update').html()));
}
if(obj.all_events && obj.all_events.notifications.length)
sse_handleNotificationsItems('all_events', obj.all_events.notifications, replace, false);
// register
if(obj.register && obj.register.count) {
$('.register-button').fadeIn();
if(replace || followup)
$('.register-update').html(Number(obj.register.count));
else
$('.register-update').html(Number(obj.register.count) + Number($('.register-update').html()));
}
if(obj.register && obj.register.notifications.length)
sse_handleNotificationsItems('register', obj.register.notifications, replace, false);
// notice and info
$.jGrowl.defaults.closerTemplate = '[ ' + aStr.closeAll + ']';
if(obj.notice) {
$(obj.notice.notifications).each(function() {
$.jGrowl(this, { sticky: true, theme: 'notice' });
});
}
if(obj.info) {
$(obj.info.notifications).each(function(){
$.jGrowl(this, { sticky: false, theme: 'info', life: 10000 });
});
}
}
function sse_handleNotificationsItems(notifyType, data, replace, followup) {
console.log('replace: ' + replace);
console.log('followup: ' + followup);
var notifications_tpl = ((notifyType == 'forums') ? unescape($("#nav-notifications-forums-template[rel=template]").html()) : unescape($("#nav-notifications-template[rel=template]").html()));
var notify_menu = $("#nav-" + notifyType + "-menu");
var notify_loading = $("#nav-" + notifyType + "-loading");
var notify_count = $("." + notifyType + "-update");
if(replace && !followup) {
notify_menu.html('');
notify_loading.hide();
}
$(data).each(function() {
if(sse_mids.indexOf(this.b64mid) >= 0) {
return sse_updateNotifications(notifyType, this.b64mid, false);
}
html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.addr,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top,this.unseen,this.private_forum);
notify_menu.append(html);
});
sse_mids = [];
if(!replace && !followup) {
console.log('sorting');
$("#nav-" + notifyType + "-menu .notification").sort(function(a,b) {
a = new Date(a.dataset.when);
b = new Date(b.dataset.when);
return a > b ? -1 : a < b ? 1 : 0;
}).appendTo('#nav-' + notifyType + '-menu');
}
$(document.body).trigger("sticky_kit:recalc");
$("#nav-" + notifyType + "-menu .notifications-autotime").timeago();
if($('#tt-' + notifyType + '-only').hasClass('active'))
$('#nav-' + notifyType + '-menu [data-thread_top=false]').addClass('d-none');
if($('#cn-' + notifyType + '-input').length) {
var filter = $('#cn-' + notifyType + '-input').val().toString().toLowerCase();
if(filter) {
filter = filter.indexOf('%') == 0 ? filter.substring(1) : filter;
$('#nav-' + notifyType + '-menu .notification').each(function(i, el) {
var cn = $(el).data('contact_name').toString().toLowerCase();
var ca = $(el).data('contact_addr').toString().toLowerCase();
if(cn.indexOf(filter) === -1 && ca.indexOf(filter) === -1)
$(el).addClass('d-none');
else
$(el).removeClass('d-none');
});
}
}
}
function sse_updateNotifications(type, mid, interactive) {
console.log('interactive: ' + interactive);
if(type === 'pubs')
return true;
if(type === 'notify' && (mid !== bParam_mid || sse_type !== 'notify'))
return true;
var count = Number($('.' + type + '-update').html());
if(count > 0)
count--;
if(count < 1) {
$('.' + type + '-button').fadeOut();
$('.' + type + '-update').html(count);
}
else
$('.' + type + '-update').html(count);
if(! interactive)
return true;
$('#nav-' + type + '-menu .notification[data-b64mid=\'' + mid + '\']').fadeOut();
return false;
}