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 liveRecurse = 0; var savedTitle = ''; var followUpPageLoad = false; var window_needs_alert = true; var expanded_items = []; var sse_bs_active = false; var sse_offset = 0; var sse_type; var sse_partial_result = false; var sse_rmids = []; var sse_fallback_interval; var page_cache = {}; // 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; } }); $(document).on('keydown', '.comment-edit-form textarea.expanded', function (e) { if (e.ctrlKey && e.keyCode === 13) { post_comment(this.id.replace('comment-edit-text-','')); } }); // @hilmar |-> if ( typeof(window.tao) == 'undefined' ) { window.tao = {}; } if ( typeof(window.tao.zin) == 'undefined' ) { tao.zin = { syslc: '', syslcs: {}, htm: '', me: '', debug: '' }; tao.zin.axim = '
(.*?)<\/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 {
sse_bs_counts();
}
}
function sse_bs_counts() {
if(sse_bs_active)
return;
sse_bs_active = true;
$.ajax({
type: 'post',
url: '/sse_bs',
data: { sse_rmids }
}).done( function(obj) {
console.log(obj);
sse_bs_active = false;
sse_rmids = [];
sse_handleNotifications(obj, true, false);
});
}
function sse_bs_notifications(e, replace, followup) {
if(sse_bs_active)
return;
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() : '');
$("#nav-" + sse_type + "-loading").show();
sse_bs_active = true;
$.ajax({
type: 'post',
url: '/sse_bs/' + sse_type + '/' + sse_offset,
nquery: encodeURIComponent(cn_val),
data: { sse_rmids }
}).done(function(obj) {
console.log('sse: bootstraping ' + sse_type);
console.log(obj);
sse_bs_active = false;
sse_rmids = [];
$("#nav-" + sse_type + "-loading").hide();
sse_offset = obj[sse_type].offset;
sse_handleNotifications(obj, replace, followup);
});
}
else
$("#nav-" + sse_type + "-loading").hide();
}
else {
sessionStorage.removeItem('notification_open');
}
}
function sse_handleNotifications(obj, replace, followup) {
var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files'];
var secondary_notifications = ['network', 'forums', 'all_events', 'pubs'];
var all_notifications = primary_notifications.concat(secondary_notifications);
all_notifications.forEach(function(type, index) {
if(typeof obj[type] === typeof undefined)
return true;
if(obj[type].count) {
$('.' + type + '-button').fadeIn();
if(replace || followup)
$('.' + type + '-update').html(Number(obj[type].count));
else
$('.' + type + '-update').html(Number(obj[type].count) + Number($('.' + type + '-update').html()));
}
else {
$('.' + type + '-update').html('0');
$('.' + type + '-button').fadeOut(function() {
sse_setNotificationsStatus();
});
}
if(obj[type].notifications.length)
sse_handleNotificationsItems(type, obj[type].notifications, replace, followup);
});
sse_setNotificationsStatus();
// 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 });
});
}
// load more notifications if visible notifications count becomes low
if(sse_type && sse_offset != -1 && $('#nav-' + sse_type + '-menu').children().length <= 20) {
sse_offset = 0;
sse_bs_notifications(sse_type, false, true);
}
}
function sse_handleNotificationsItems(notifyType, data, replace, followup) {
var notifications_tpl = ((notifyType == 'forums') ? decodeURIComponent($("#nav-notifications-forums-template[rel=template]").html().replace('data-src', 'src')) : decodeURIComponent($("#nav-notifications-template[rel=template]").html().replace('data-src', 'src')));
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() {
// do not add a notification if it is already present
if($('#nav-' + notifyType + '-menu .notification[data-b64mid=\'' + this.b64mid + '\']').length)
return true;
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, encodeURIComponent(this.mids), this.body);
notify_menu.append(html);
});
if(!replace && !followup) {
$("#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('tt-filter-active');
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('cn-filter-active');
else
$(el).removeClass('cn-filter-active');
});
}
}
}
function sse_updateNotifications(type, mid) {
if(type === 'pubs')
return true;
if(type === 'notify' && (mid !== bParam_mid || sse_type !== 'notify'))
return true;
/*
var count = Number($('.' + type + '-update').html());
count--;
if(count < 1) {
$('.' + type + '-update').html(count);
$('.' + type + '-button').fadeOut(function() {
sse_setNotificationsStatus();
});
}
else {
$('.' + type + '-update').html(count);
}
*/
$('#nav-' + type + '-menu .notification[data-b64mid=\'' + mid + '\']').fadeOut(function() {
this.remove();
});
}
function sse_setNotificationsStatus() {
var primary_notifications = ['dm', 'home', 'intros', 'register', 'mail', 'notify', 'files'];
var secondary_notifications = ['network', 'forums', 'all_events', 'pubs'];
var all_notifications = primary_notifications.concat(secondary_notifications);
var primary_available = false;
var any_available = false;
all_notifications.forEach(function(type, index) {
if($('.' + type + '-button').css('display') == 'block') {
any_available = true;
if(primary_notifications.indexOf(type) > -1)
primary_available = true;
}
});
if(primary_available) {
$('.notifications-btn-icon').removeClass('fa-exclamation-circle');
$('.notifications-btn-icon').addClass('fa-exclamation-triangle');
}
else {
$('.notifications-btn-icon').removeClass('fa-exclamation-triangle');
$('.notifications-btn-icon').addClass('fa-exclamation-circle');
}
if(any_available) {
$('.notifications-btn').css('opacity', 1);
$('#no_notifications').hide();
$('#notifications').show();
}
else {
$('.notifications-btn').css('opacity', 0.5);
$('#navbar-collapse-1').removeClass('show');
$('#no_notifications').show();
$('#notifications').hide();
}
}
function sse_fallback() {
$.get('/sse', function(obj) {
if(! obj)
return;
console.log('sse fallback');
console.log(obj);
sse_handleNotifications(obj, false, false);
});
}
function makeid(length) {
var result = '';
var characters = 'abcdef0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}