streams/view/js/main.js

1752 lines
48 KiB
JavaScript
Raw Normal View History

let src = null;
let prev = null;
let livetime = null;
let msie = false;
let stopped = false;
let totStopped = false;
let timer = null;
let pr = 0;
let liking = 0;
let in_progress = false;
let langSelect = false;
let commentBusy = false;
let last_popup_menu = null;
let last_popup_button = null;
let scroll_next = false;
let next_page = 1;
let page_load = true;
let loadingPage = true;
let pageHasMoreContent = true;
let divmore_height = 400;
let last_filestorage_id = null;
let mediaPlaying = false;
let contentHeightDiff = 0;
let liveRecurse = 0;
let savedTitle = '';
let initialLoad = true;
let cached_data = [];
$.ajaxPrefilter(function( options, original_Options, jqXHR ) {
options.async = true;
});
// Clear the session and local storage if we switch channel or log out
let cache_uid = '';
if(sessionStorage.getItem('uid') !== null) {
cache_uid = sessionStorage.getItem('uid');
}
if(cache_uid !== localUser.toString()) {
sessionStorage.clear();
localStorage.clear();
sessionStorage.setItem('uid', localUser.toString());
}
$.ajaxSetup({cache: false});
let region = 0;
$(document).ready(function() {
$(document).on('click focus', '.comment-edit-form', handle_comment_form);
jQuery.timeago.settings.strings = {
prefixAgo : aStr['t01'],
prefixFromNow : aStr['t02'],
suffixAgo : aStr['t03'],
suffixFromNow : aStr['t04'],
seconds : aStr['t05'],
minute : aStr['t06'],
minutes : aStr['t07'],
hour : aStr['t08'],
hours : aStr['t09'],
day : aStr['t10'],
days : aStr['t11'],
month : aStr['t12'],
months : aStr['t13'],
year : aStr['t14'],
years : aStr['t15'],
wordSeparator : aStr['t16'],
numbers : aStr['t17'],
};
jQuery.timeago.settings.allowFuture = true;
savedTitle = document.title;
updateInit();
$('a.notification-link').click(function(e){
let notifyType = $(this).data('type');
if(! $('#nav-' + notifyType + '-sub').hasClass('show')) {
loadNotificationItems(notifyType);
2018-01-26 10:44:24 +00:00
sessionStorage.setItem('notification_open', notifyType);
}
else {
sessionStorage.removeItem('notification_open');
}
});
2018-01-26 10:44:24 +00:00
if(sessionStorage.getItem('notification_open') !== null) {
let notifyType = sessionStorage.getItem('notification_open');
2018-01-26 10:44:24 +00:00
$('#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') {
let 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;
}
2019-08-26 00:35:14 +00:00
$('#pause').html('<i class="fa fa-pause fa-fw"></i>');
} else {
unpause();
}
} else {
if (!totStopped) {
unpause();
}
}
});
let e = document.getElementById('content-complete');
if(e)
pageHasMoreContent = false;
initialLoad = 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);
}
2019-12-06 03:07:55 +00:00
function getSelectedText() {
let selectedText = '';
2019-12-06 03:07:55 +00:00
// window.getSelection
if (window.getSelection) {
selectedText = window.getSelection();
}
// document.getSelection
else if (document.getSelection) {
selectedText = document.getSelection();
}
// document.selection
else if (document.selection) {
selectedText = document.selection.createRange().text;
} else return;
return selectedText;
}
2019-12-09 00:13:52 +00:00
function commentCancel(commentId) {
$("#comment-edit-text-" + commentId).val('');
localStorage.removeItem("comment_body-" + commentId);
2019-12-09 00:13:52 +00:00
}
2019-12-06 03:07:55 +00:00
2017-08-28 21:42:17 +00:00
function handle_comment_form(e) {
e.stopPropagation();
//handle eventual expanded forms
let expanded = $('.comment-edit-text.expanded');
let i = 0;
2017-08-28 21:42:17 +00:00
if(expanded.length) {
expanded.each(function() {
let ex_form = $(expanded[i].form);
let ex_fields = ex_form.find(':input[type=text], textarea');
let ex_fields_empty = true;
2017-08-28 21:42:17 +00:00
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
let form = $(this);
let fields = form.find(':input[type=text], textarea');
let fields_empty = true;
2017-08-28 21:42:17 +00:00
if(form.find('.comment-edit-text').length) {
let commentElm = form.find('.comment-edit-text').attr('id');
let commentId = commentElm.replace('comment-edit-text-','');
let submitElm = commentElm.replace(/text/,'submit');
2017-11-07 01:08:48 +00:00
$('#' + commentElm).addClass('expanded').removeAttr('placeholder');
$('#' + commentElm).attr('tabindex','9');
$('#' + submitElm).attr('tabindex','10');
2017-08-28 21:42:17 +00:00
form.find(':not(:visible)').show();
2020-05-15 00:45:56 +00:00
commentAuthors(commentId);
let quoted = getSelectedText();
let tmpStr = $("#comment-edit-text-" + commentId).val();
2019-12-09 00:13:52 +00:00
if(quoted != '') {
$("#comment-edit-text-" + commentId).val(tmpStr + '[quote]' + quoted + '[/quote]');
}
2017-08-28 21:42:17 +00:00
}
2019-12-09 00:13:52 +00:00
2017-08-28 21:42:17 +00:00
// 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) {
let emptyCommentElm = form.find('.comment-edit-text').attr('id');
let emptySubmitElm = commentElm.replace(/text/,'submit');
2017-11-07 01:08:48 +00:00
$('#' + emptyCommentElm).removeClass('expanded').attr('placeholder', aStr.comment);
$('#' + emptyCommentElm).removeAttr('tabindex');
$('#' + emptySubmitElm).removeAttr('tabindex');
2017-08-28 21:42:17 +00:00
form.find(':not(.comment-edit-text)').hide();
}
});
let commentSaveTimer = null;
let emptyCommentElm = form.find('.comment-edit-text').attr('id');
let convId = emptyCommentElm.replace('comment-edit-text-','');
$(document).on('focusout','#' + emptyCommentElm,function(e){
if(commentSaveTimer)
clearTimeout(commentSaveTimer);
2018-04-13 04:44:06 +00:00
commentSaveChanges(convId,true);
commentSaveTimer = null;
});
$(document).on('focusin','#' + emptyCommentElm,function(e){
commentSaveTimer = setTimeout(function () {
2018-04-13 04:44:06 +00:00
commentSaveChanges(convId,false);
},10000);
});
2018-04-13 04:44:06 +00:00
function commentSaveChanges(convId,isFinal = false) {
if(auto_save_draft) {
2018-04-13 05:24:25 +00:00
tmp = $('#' + emptyCommentElm).val();
if(tmp) {
localStorage.setItem("comment_body-" + convId, tmp);
}
else {
localStorage.removeItem("comment_body-" + convId);
}
if( !isFinal) {
2018-04-13 04:44:06 +00:00
commentSaveTimer = setTimeout(commentSaveChanges,10000,convId);
}
}
}
2017-08-28 21:42:17 +00:00
}
function doreply(parent, ident) {
showHideCommentBox(parent);
openClose('wall-item-comment-wrapper-' + ident.toString());
}
function commentClose(obj, id) {
if(obj.value === '') {
obj.value = aStr.comment;
2017-08-28 21:42:17 +00:00
$("#comment-edit-text-" + id).removeClass("expanded");
$("#mod-cmnt-wrap-" + id).hide();
2017-08-12 20:29:57 +00:00
$("#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) {
let tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == '$comment') {
tmpStr = '';
2017-08-28 21:42:17 +00:00
$("#comment-edit-text-" + id).addClass("expanded");
openMenu("comment-tools-" + id);
}
let ins = $(obj).html();
ins = ins.replace('&lt;','<');
ins = ins.replace('&gt;','>');
ins = ins.replace('&amp;','&');
ins = ins.replace('&quot;','"');
$("#comment-edit-text-" + id).val(tmpStr + ins);
}
function commentAuthors(id) {
2020-05-14 00:39:48 +00:00
$("#hidden-mentions-" + id).val($("#thread-authors-" + id).html());
}
function insertbbcomment(comment, BBcode, id) {
// allow themes to override this
if(typeof(insertFormatting) != 'undefined')
return(insertFormatting(comment, BBcode, id));
let tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == comment) {
tmpStr = "";
2017-08-28 21:42:17 +00:00
$("#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 = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
} else if (textarea.selectionStart || textarea.selectionStart == "0") {
let start = textarea.selectionStart;
let 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;
}
2015-10-05 10:26:04 +00:00
function inserteditortag(BBcode, id) {
// allow themes to override this
if(typeof(insertEditorFormatting) != 'undefined')
return(insertEditorFormatting(BBcode));
2015-10-05 10:26:04 +00:00
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") {
let start = textarea.selectionStart;
let 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;
}
2019-06-03 01:57:43 +00:00
// used by link modal to pass data to callbacks and still allow handler removal
let currentComment = null;
let currentID = null;
2019-06-03 01:57:43 +00:00
function insertCommentURL(comment, id) {
2019-05-23 23:37:56 +00:00
textarea = document.getElementById("comment-edit-text-" +id);
if (textarea.selectionStart || textarea.selectionStart == "0") {
let start = textarea.selectionStart;
let end = textarea.selectionEnd;
2019-05-23 23:37:56 +00:00
if (end > start) {
reply = prompt(aStr['linkurl']);
if(reply && reply.length) {
textarea.value = textarea.value.substring(0, start) + "[url=" + reply + "]" + textarea.value.substring(start, end) + "[/url]" + textarea.value.substring(end, textarea.value.length);
}
return true;
}
}
2019-06-03 01:57:43 +00:00
if ($('#jot-popup').length != 0) $('#jot-popup').show();
2019-05-23 23:37:56 +00:00
2019-06-03 01:57:43 +00:00
currentComment = comment;
currentID = id;
2019-04-30 04:07:57 +00:00
$('#linkModal').modal();
$('#id_link_url').focus();
2019-05-30 02:55:29 +00:00
$('#link-modal-CancelButton').on('click', commentclearlinkmodal);
2019-06-03 01:57:43 +00:00
$('#link-modal-OKButton').on('click', commentgetlinkmodal);
2019-05-30 02:55:29 +00:00
return true;
}
function commentclearlinkmodal() {
$('#link-modal-OKButton').off('click', commentgetlinkmodal);
$('#link-modal-CancelButton').off('click', commentclearlinkmodal);
}
function commentgetlinkmodal() {
let reply=$('#id_link_url').val();
2019-05-30 02:55:29 +00:00
if(reply && reply.length) {
let radioValue = $("input[name='link_style']:checked"). val();
2019-05-30 02:55:29 +00:00
if(radioValue == '0') {
reply = '!' + reply;
2019-04-30 04:07:57 +00:00
}
let optstr = '';
let opts = $("input[name='oembed']:checked"). val();
2019-05-30 02:55:29 +00:00
if(opts) {
optstr = optstr + '&oembed=1';
}
opts = $("input[name='zotobj']:checked"). val();
2019-05-30 02:55:29 +00:00
if(opts) {
optstr = optstr + '&zotobj=1';
}
reply = bin2hex(reply);
$('body').css('cursor', 'wait');
$.get('linkinfo?f=&binurl=' + reply + optstr, function(data) {
$('#linkModal').modal('hide');
2019-06-03 01:57:43 +00:00
$("#comment-edit-text-" + currentID).focus();
$("#comment-edit-text-" + currentID).addClass("expanded");
openMenu("comment-tools-" + currentID);
let tmpStr = $("#comment-edit-text-" + currentID).val();
2019-05-23 23:37:56 +00:00
2019-06-03 01:57:43 +00:00
textarea = document.getElementById("comment-edit-text-" + currentID);
2019-05-30 02:55:29 +00:00
textarea.value = textarea.value + data;
2019-06-03 01:57:43 +00:00
preview_comment(currentID);
2019-05-30 02:55:29 +00:00
$('#link-modal-OKButton').off('click', commentgetlinkmodal);
$('#link-modal-CancelButton').off('click', commentclearlinkmodal);
$('#id_link_url').val('');
$('body').css('cursor', 'auto');
});
}
}
function doFollowAuthor(url) {
$.get(url, function(data) { notificationsUpdate(); });
return true;
}
function doPoke(xchan) {
$.get('poke?xchan=' + xchan, function(data) { notificationsUpdate(); });
return true;
}
2020-11-16 00:58:31 +00:00
function update_role_text() {
let new_role = $("#id_permissions_role").val();
2020-11-16 00:58:31 +00:00
if (typeof(new_role) !== 'undefined') {
$("#channel_role_text").html(aStr[new_role]);
}
}
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).slideUp();
$('#hide-comments-' + id).html(aStr.showmore);
$('#hide-comments-total-' + id).show();
} else {
$('#collapsed-comments-' + id + ' .autotime').timeago();
$('#collapsed-comments-' + id).slideDown();
$('#hide-comments-' + id).html(aStr.showfewer);
$('#hide-comments-total-' + id).hide();
2014-06-19 03:33:28 +00:00
}
}
2020-09-21 04:11:42 +00:00
function collapseComments(id) {
if( $('.collapsed-comments-' + id).is(':visible')) {
$('.collapsed-comments-' + id + ' .autotime').timeago('dispose');
$('.collapsed-comments-' + id).slideUp();
$('#hide-comments-' + id).html(aStr.showmore);
$('#hide-comments-total-' + id).show();
} else {
$('.collapsed-comments-' + id + ' .autotime').timeago();
$('.collapsed-comments-' + id).slideDown();
$('#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";
}
}
2017-09-15 20:17:18 +00:00
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) {
let pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
if(cached_data !== undefined) {
handleNotifications(cached_data);
}
else {
$.get(pingCmd,function(data) {
2019-01-17 23:12:58 +00:00
if(! data)
return;
// Put the object into storage
sessionStorage.setItem('notifications_cache', JSON.stringify(data));
let fnotifs = [];
2018-06-02 13:39:38 +00:00
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 = '<div>[ ' + aStr.closeAll + ']</div>';
$(data.notice).each(function() {
$.jGrowl(this.message, { sticky: false, theme: 'notice', life: 10000 });
});
$(data.info).each(function(){
$.jGrowl(this.message, { sticky: false, theme: 'info' });
});
});
}
let notifyType = null;
2018-01-25 11:56:52 +00:00
if($('.notification-content.show').length) {
notifyType = $('.notification-content.show').data('type');
2018-01-25 11:56:52 +00:00
}
if(notifyType !== null) {
loadNotificationItems(notifyType);
}
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,updateInterval);
}
function handleNotifications(data) {
2020-02-13 05:36:21 +00:00
if(data.stream || data.home || data.intros || data.register || data.mail || data.all_events || data.notify || data.files || data.pubs || data.forums) {
$('.notifications-btn').css('opacity', 1);
$('#no_notifications').hide();
}
else {
$('.notifications-btn').css('opacity', 0.5);
$('#navbar-collapse-1').removeClass('show');
$('#no_notifications').show();
}
if(data.home || data.intros || data.register || data.mail || data.notify || data.files) {
$('.notifications-btn-icon').removeClass('fa-exclamation-circle');
$('.notifications-btn-icon').addClass('fa-exclamation-triangle');
}
if(!data.home && !data.intros && !data.register && !data.mail && !data.notify && !data.files) {
$('.notifications-btn-icon').removeClass('fa-exclamation-triangle');
$('.notifications-btn-icon').addClass('fa-exclamation-circle');
}
if(data.all_events_today) {
$('.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');
}
$.each(data, function(index, item) {
//do not process those
let arr = ['notice', 'info', 'invalid'];
if(arr.indexOf(index) !== -1)
return;
2012-07-26 05:55:43 +00:00
if(item == 0) {
$('.' + index + '-button').fadeOut();
sessionStorage.removeItem(index + '_notifications_cache');
} else {
$('.' + index + '-button').fadeIn();
$('.' + index + '-update').html(item);
}
});
}
function handleNotificationsItems(notifyType, data) {
let notifications_tpl = ((notifyType == 'forums') ? unescape($("#nav-notifications-forums-template[rel=template]").html()) : unescape($("#nav-notifications-template[rel=template]").html()));
let notify_menu = $("#nav-" + notifyType + "-menu");
notify_menu.html('');
$(data).each(function() {
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);
});
datasrc2src('#notifications .notification img[data-src]');
if($('#tt-' + notifyType + '-only').hasClass('active'))
$('#nav-' + notifyType + '-menu [data-thread_top=false]').hide();
if($('#cn-' + notifyType + '-input').length) {
let filter = $('#cn-' + notifyType + '-input').val().toString().toLowerCase();
if(filter) {
$('#nav-' + notifyType + '-menu .notification').each(function(i, el){
let cn = $(el).data('contact_name').toString().toLowerCase();
if(cn.indexOf(filter) === -1)
$(el).addClass('d-none');
else
$(el).removeClass('d-none');
});
}
}
}
function contextualHelp() {
let container = $("#contextual-help-content");
if(container.hasClass('contextual-help-content-open')) {
container.removeClass('contextual-help-content-open');
2016-12-30 19:50:12 +00:00
$('main').css('margin-top', '')
}
else {
container.addClass('contextual-help-content-open');
let mainTop = container.outerHeight(true);
2016-12-30 19:50:12 +00:00
$('main').css('margin-top', mainTop + 'px');
}
}
function contextualHelpFocus(target, openSidePanel) {
if($(target).length) {
if (openSidePanel) {
$("main").addClass('region_1-on'); // Open the side panel to highlight element
}
else {
$("main").removeClass('region_1-on');
}
let css_position = $(target).parent().css('position');
if (css_position === 'fixed') {
$(target).parent().css('position', 'static');
}
$('html,body').animate({ scrollTop: $(target).offset().top - $('nav').outerHeight(true) - $('#contextual-help-content').outerHeight(true)}, 'slow');
for (i = 0; i < 3; i++) {
$(target).fadeTo('slow', 0.1).fadeTo('slow', 1.0);
}
$(target).parent().css('position', css_position);
}
}
2012-07-24 03:49:56 +00:00
function updatePageItems(mode, data) {
if(mode === 'append') {
$(data).each(function() {
$('#page-end').before($(this));
});
if(loadingPage) {
loadingPage = false;
}
}
2014-08-06 05:01:47 +00:00
let e = document.getElementById('content-complete');
2014-08-06 05:01:47 +00:00
if(e) {
pageHasMoreContent = false;
2014-08-06 05:01:47 +00:00
}
2014-12-17 01:43:36 +00:00
collapseHeight();
}
2012-07-24 03:49:56 +00:00
function updateConvItems(mode,data) {
if(mode === 'update' || mode === 'replace') {
2012-07-24 03:49:56 +00:00
prev = 'threads-begin';
}
if(mode === 'append') {
next = 'threads-end';
}
if(mode === 'replace') {
$('.thread-wrapper').remove(); // clear existing content
}
2012-07-24 03:49:56 +00:00
$('.thread-wrapper.toplevel_item',data).each(function() {
let ident = $(this).attr('id');
let convId = ident.replace('thread-wrapper-','');
let commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
2018-04-13 04:44:06 +00:00
let itmId = 0;
let isVisible = false;
// figure out the comment state
if(typeof commentWrap !== 'undefined')
itmId = commentWrap.replace('collapsed-comments-','');
2013-07-04 22:46:20 +00:00
if($('#collapsed-comments-'+itmId).is(':visible'))
isVisible = true;
2018-04-13 04:44:06 +00:00
// insert the content according to the mode and first_page
// and whether or not the content exists already (overwrite it)
if($('#' + ident).length == 0) {
if((mode === 'update' || mode === 'replace') && profile_page == 1) {
$('#' + prev).after($(this));
prev = ident;
2012-07-24 03:49:56 +00:00
}
if(mode === 'append') {
$('#' + next).before($(this));
2012-07-24 03:49:56 +00:00
}
}
else {
$('#' + ident).replaceWith($(this));
}
2012-07-25 04:03:15 +00:00
// set the comment state to the state we discovered earlier
2012-07-25 04:03:15 +00:00
if(isVisible)
showHideComments(itmId);
let commentBody = localStorage.getItem("comment_body-" + convId);
2018-04-13 04:44:06 +00:00
if(commentBody) {
let commentElm = $('#comment-edit-text-' + convId);
2018-04-13 04:44:06 +00:00
if(auto_save_draft) {
2018-04-13 05:24:25 +00:00
if($(commentElm).val() === '') {
2018-04-13 04:44:06 +00:00
$('#comment-edit-form-' + convId).show();
2018-04-13 05:24:25 +00:00
$(commentElm).addClass("expanded");
openMenu("comment-tools-" + convId);
$(commentElm).val(commentBody);
2018-04-13 04:44:06 +00:00
}
} else {
2018-04-13 05:24:25 +00:00
localStorage.removeItem("comment_body-" + convId);
2018-04-13 04:44:06 +00:00
}
}
// trigger the autotime function on all newly created content
2020-03-18 04:30:25 +00:00
$(".pinned .autotime").timeago();
$("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
$("> .shared_header .autotime",this).timeago();
if((mode === 'append' || mode === 'replace') && (loadingPage)) {
loadingPage = false;
}
// if single thread view and the item has a title, display it in the title bar
if(mode === 'replace') {
if (window.location.search.indexOf("mid=") != -1 || window.location.pathname.indexOf("display") != -1) {
let title = $(".wall-item-title").text();
title.replace(/^\s+/, '');
title.replace(/\s+$/, '');
if (title) {
savedTitle = title + " " + savedTitle;
2019-01-30 05:26:52 +00:00
document.title = title;
}
}
}
});
// reset rotators and cursors we may have set before reaching this place
2012-07-24 03:49:56 +00:00
$('.like-rotator').hide();
2012-07-24 03:49:56 +00:00
if(commentBusy) {
commentBusy = false;
$('body').css('cursor', 'auto');
}
// Setup to determine if the media player is playing. This affects
// some content loading decisions.
$('video').off('playing');
$('video').off('pause');
$('audio').off('playing');
$('audio').off('pause');
$('video').on('playing', function() {
mediaPlaying = true;
});
$('video').on('pause', function() {
mediaPlaying = false;
});
$('audio').on('playing', function() {
mediaPlaying = true;
});
$('audio').on('pause', function() {
mediaPlaying = false;
});
2012-07-24 03:49:56 +00:00
/* autocomplete @nicknames */
$(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1");
/* autocomplete bbcode */
$(".comment-edit-form textarea").bbco_autocomplete('bbcode');
let bimgs = ((preloadImages) ? false : $(".wall-item-body img, .wall-photo-item img").not(function() { return this.complete; }));
let bimgcount = bimgs.length;
2012-07-24 03:49:56 +00:00
if (bimgcount) {
bimgs.on('load',function() {
bimgcount--;
if (! bimgcount) {
collapseHeight();
}
});
} else {
collapseHeight();
}
// auto-scroll to a particular comment in a thread (designated by mid) when in single-thread mode
// use the same method to generate the submid as we use in ThreadItem,
// base64_encode + replace(['+','='],['','']);
let submid = ((bParam_mid.length) ? bParam_mid : 'abcdefg');
let encoded = ((submid.substr(0,4) == 'b64.') ? true : false);
let submid_encoded = ((encoded) ? submid.substr(4) : window.btoa(submid));
submid_encoded = submid_encoded.replace(/[\+\=]/g,'');
if($('.item_' + submid_encoded).length && !$('.item_' + submid_encoded).hasClass('toplevel_item') && mode == 'replace') {
if($('.collapsed-comments').length) {
let scrolltoid = $('.collapsed-comments').attr('id').substring(19);
$('#collapsed-comments-' + scrolltoid + ' .autotime').timeago();
$('#collapsed-comments-' + scrolltoid).show();
$('#hide-comments-' + scrolltoid).html(aStr.showfewer);
$('#hide-comments-total-' + scrolltoid).hide();
}
$('html, body').animate({ scrollTop: $('.item_' + submid_encoded).offset().top - $('nav').outerHeight() }, 'slow');
$('.item_' + submid_encoded).addClass('item-highlight');
}
2019-07-31 00:56:35 +00:00
2019-07-29 02:34:42 +00:00
$(document.body).trigger("sticky_kit:recalc");
}
2012-07-24 03:49:56 +00:00
function collapseHeight() {
let origContentHeight = Math.ceil($("#region_2").height());
let cDiff = 0;
let i = 0;
let position = $(window).scrollTop();
$(".wall-item-content, .directory-collapse").each(function() {
let orgHeight = $(this).outerHeight(true);
if(orgHeight > divmore_height) {
2017-03-06 10:52:07 +00:00
if(! $(this).hasClass('divmore') && $(this).has('div.no-collapse').length == 0) {
// check if we will collapse some content above the visible content and compensate the diff later
2016-02-17 10:07:47 +00:00
if($(this).offset().top + divmore_height - $(window).scrollTop() + cDiff - ($(".divgrow-showmore").outerHeight() * i) < 65) {
diff = orgHeight - divmore_height;
cDiff = cDiff + diff;
i++;
}
$(this).readmore({
speed: 0,
heightMargin: 50,
collapsedHeight: divmore_height,
2016-07-15 11:20:00 +00:00
moreLink: '<a href="#" class="divgrow-showmore fakelink">' + aStr.divgrowmore + '</a>',
lessLink: '<a href="#" class="divgrow-showmore fakelink">' + aStr.divgrowless + '</a>',
beforeToggle: function(trigger, element, expanded) {
if(expanded) {
if((($(element).offset().top + divmore_height) - $(window).scrollTop()) < 65 ) {
$(window).scrollTop($(window).scrollTop() - ($(element).outerHeight(true) - divmore_height));
}
}
}
});
$(this).addClass('divmore');
}
}
});
let collapsedContentHeight = Math.ceil($("#region_2").height());
contentHeightDiff = liking ? 0 : origContentHeight - collapsedContentHeight;
console.log('collapseHeight() - contentHeightDiff: ' + contentHeightDiff + 'px');
if(i && ! liking){
let sval = position - cDiff + ($(".divgrow-showmore").outerHeight() * i);
2016-02-16 20:02:28 +00:00
console.log('collapsed above viewport count: ' + i);
$(window).scrollTop(sval);
}
2019-07-31 00:56:35 +00:00
}
function updateInit() {
2020-02-13 05:48:10 +00:00
if($('#live-stream').length) { src = 'stream'; }
if($('#live-channel').length) { src = 'channel'; }
if($('#live-pubstream').length) { src = 'pubstream'; }
if($('#live-display').length) { src = 'display'; }
if($('#live-hq').length) { src = 'hq'; }
if($('#live-search').length) { src = 'search'; }
2012-07-25 05:06:21 +00:00
if (initialLoad && (sessionStorage.getItem('notifications_cache') !== null)) {
cached_data = JSON.parse(sessionStorage.getItem('notifications_cache'));
notificationsUpdate(cached_data);
2018-06-02 13:39:38 +00:00
let fnotifs = [];
2018-06-02 13:39:38 +00:00
if(cached_data.forums) {
$.each(cached_data.forums_sub, function() {
fnotifs.push(this);
});
handleNotificationsItems('forums', fnotifs);
}
}
if(! src) {
notificationsUpdate();
}
else {
liveUpdate();
}
if($('#live-photos').length || $('#live-cards').length || $('#live-articles').length ) {
if(liking) {
liking = 0;
window.location.href=window.location.href;
}
}
}
function liveUpdate(notify_id) {
if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */
if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
if(in_progress || mediaPlaying) {
if(livetime) {
clearTimeout(livetime);
}
livetime = setTimeout(liveUpdate, 10000);
return;
}
if(timer)
clearTimeout(timer);
if(livetime !== null)
livetime = null;
prev = 'live-' + src;
in_progress = true;
let update_url;
let update_mode;
if(scroll_next) {
bParam_page = next_page;
page_load = true;
}
else {
bParam_page = 1;
}
update_url = buildCmd();
if(page_load) {
$("#page-spinner").show();
if(bParam_page == 1)
update_mode = 'replace';
else
update_mode = 'append';
}
else {
update_mode = 'update';
let orgHeight = $("#region_2").height();
}
let dstart = new Date();
console.log('LOADING data...' + update_url);
$.get(update_url, function(data) {
// on shared hosts occasionally the live update process will be killed
// leaving an incomplete HTML structure, which leads to conversations getting
// truncated and the page messed up if all the divs aren't closed. We will try
// again and give up if we can't get a valid HTML response after 10 tries.
if((data.indexOf("<html>") != (-1)) && (data.indexOf("</html>") == (-1))) {
console.log('Incomplete data. Reloading');
in_progress = false;
liveRecurse ++;
if(liveRecurse < 10) {
liveUpdate();
}
else {
console.log('Incomplete data. Too many attempts. Giving up.');
}
}
// else data was valid - reset the recursion counter
liveRecurse = 0;
if(typeof notify_id !== 'undefined' && notify_id !== 'undefined') {
$.post(
"hq",
{
"notify_id" : notify_id
}
);
}
let dready = new Date();
console.log('DATA ready in: ' + (dready - dstart)/1000 + ' seconds.');
if(update_mode === 'update' || preloadImages) {
console.log('LOADING images...');
$('.wall-item-body, .wall-photo-item',data).imagesLoaded( function() {
let iready = new Date();
console.log('IMAGES ready in: ' + (iready - dready)/1000 + ' seconds.');
page_load = false;
scroll_next = false;
updateConvItems(update_mode,data);
$("#page-spinner").hide();
$("#profile-jot-text-loading").hide();
2016-02-17 10:07:47 +00:00
// adjust scroll position if new content was added above viewport
2019-01-25 03:03:14 +00:00
if(update_mode === 'update' && !justifiedGalleryActive) {
$(window).scrollTop($(window).scrollTop() + $("#region_2").height() - orgHeight + contentHeightDiff);
}
in_progress = false;
});
}
else {
page_load = false;
scroll_next = false;
updateConvItems(update_mode,data);
$("#page-spinner").hide();
$("#profile-jot-text-loading").hide();
in_progress = false;
}
})
.done(function() {
notificationsUpdate();
});
}
function pageUpdate() {
in_progress = true;
let update_url;
let update_mode;
if(scroll_next) {
bParam_page = next_page;
page_load = true;
}
else {
bParam_page = 1;
}
update_url = baseurl + '/' + decodeURIComponent(page_query) + '/?f=&aj=1&page=' + bParam_page + extra_args ;
$("#page-spinner").show();
update_mode = 'append';
2012-12-19 00:17:08 +00:00
$.get(update_url,function(data) {
page_load = false;
scroll_next = false;
updatePageItems(update_mode,data);
$("#page-spinner").hide();
$(".autotime").timeago();
in_progress = false;
});
}
function justifyPhotos(id) {
justifiedGalleryActive = true;
2017-09-27 13:48:13 +00:00
$('#' + id).show();
$('#' + id).justifiedGallery({
2019-06-11 06:21:57 +00:00
selector: 'a, div:not(#page-end)',
margins: 3,
2019-06-11 06:21:57 +00:00
border: 0
}).on('jg.complete', function(e){ justifiedGalleryActive = false; });
}
function justifyPhotosAjax(id) {
justifiedGalleryActive = true;
$('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
}
function loadNotificationItems(notifyType) {
let pingExCmd = 'ping/' + notifyType + ((localUser != 0) ? '?f=&uid=' + localUser : '');
let clicked = $('[data-type=\'' + notifyType + '\']').data('clicked');
if((clicked === undefined) && (sessionStorage.getItem(notifyType + '_notifications_cache') !== null)) {
cached_data = JSON.parse(sessionStorage.getItem(notifyType + '_notifications_cache'));
handleNotificationsItems(notifyType, cached_data);
$('[data-type=\'' + notifyType + '\']').data('clicked',true);
console.log('updating ' + notifyType + ' notifications from cache...');
}
else {
cached_data = [];
}
console.log('updating ' + notifyType + ' notifications...');
2018-06-02 13:39:38 +00:00
$.get(pingExCmd, function(data) {
if(data.invalid == 1) {
window.location.href=window.location.href;
}
2017-10-12 18:36:25 +00:00
if(JSON.stringify(cached_data[0]) === JSON.stringify(data.notify[0])) {
console.log(notifyType + ' notifications cache up to date - update deferred');
}
else {
handleNotificationsItems(notifyType, data.notify);
sessionStorage.setItem(notifyType + '_notifications_cache', JSON.stringify(data.notify));
}
});
}
2010-09-17 10:10:19 +00:00
// Since our ajax calls are asynchronous, we will give a few
// seconds for the first ajax call (setting like/dislike), then
// run the updater to pick up any changes and display on the page.
// The updater will turn any rotators off when it's done.
// This function will have returned long before any of these
// events have completed and therefore there won't be any
// visible feedback that anything changed without all this
// trickery. This still could cause confusion if the "like" ajax call
// is delayed and updateInit runs before it completes.
function dolike(ident, verb) {
unpause();
$('#like-rotator-' + ident.toString()).show();
$.get('like/' + ident.toString() + '?verb=' + verb, updateInit );
liking = 1;
}
2014-06-23 05:16:26 +00:00
function doprofilelike(ident, verb) {
2021-07-17 11:28:12 +00:00
$.get('plike/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; });
}
2014-06-23 05:16:26 +00:00
2018-05-03 03:08:59 +00:00
function dopin(id) {
id = id.toString();
$('#like-rotator-' + id).show();
$.post('pin', { 'id' : id })
.done(function() {
window.location.href=window.location.href;
})
.fail(function() {
window.location.href=window.location.href;
})
}
function dropItem(url, object) {
let confirm = confirmDelete();
if(confirm) {
let id = url.split('/')[2];
$('body').css('cursor', 'wait');
$(object + ', #pinned-wrapper-' + id).fadeTo('fast', 0.33, function () {
$.post('pin', { 'id' : id });
$.get(url).done(function() {
$(object + ', #pinned-wrapper-' + id).remove();
$('body').css('cursor', 'auto');
});
});
return true;
}
else {
return false;
}
}
function dropItem(url, object) {
2018-05-03 03:08:59 +00:00
let confirm = confirmDelete();
if(confirm) {
$('body').css('cursor', 'wait');
$(object).fadeTo('fast', 0.33, function () {
$.get(url).done(function() {
$(object).remove();
$('body').css('cursor', 'auto');
});
});
return true;
}
else {
return false;
}
}
function dosubthread(ident) {
unpause();
$('#like-rotator-' + ident.toString()).show();
$.get('subthread/sub/' + ident.toString(), updateInit );
liking = 1;
}
2015-11-03 22:59:14 +00:00
function dounsubthread(ident) {
unpause();
$('#like-rotator-' + ident.toString()).show();
$.get('subthread/unsub/' + ident.toString(), updateInit );
2015-11-03 22:59:14 +00:00
liking = 1;
}
function dostar(ident) {
ident = ident.toString();
$('#like-rotator-' + ident).show();
$.get('starred/' + ident, function(data) {
if(data.result == 1) {
$('#starred-' + ident).addClass('starred');
$('#starred-' + ident).removeClass('unstarred');
$('#starred-' + ident).addClass('fa-star');
2016-04-30 18:51:01 +00:00
$('#starred-' + ident).removeClass('fa-star-o');
$('#star-' + ident).addClass('hidden');
$('#unstar-' + ident).removeClass('hidden');
let btn_tpl = '<div class="btn-group" id="star-button-' + ident + '"><button type="button" class="btn btn-outline-secondary btn-sm wall-item-like" onclick="dostar(' + ident + ');"><i class="fa fa-star"></i></button></div>'
$('#wall-item-tools-left-' + ident).prepend(btn_tpl);
}
else {
$('#starred-' + ident).addClass('unstarred');
$('#starred-' + ident).removeClass('starred');
2016-04-30 18:51:01 +00:00
$('#starred-' + ident).addClass('fa-star-o');
$('#starred-' + ident).removeClass('fa-star');
$('#star-' + ident).removeClass('hidden');
$('#unstar-' + ident).addClass('hidden');
$('#star-button-' + ident).remove();
}
$('#like-rotator-' + ident).hide();
});
}
function getPosition(e) {
let cursor = {x:0, y:0};
if ( e.pageX || e.pageY ) {
cursor.x = e.pageX;
cursor.y = e.pageY;
2011-07-04 02:41:04 +00:00
}
else {
if( e.clientX || e.clientY ) {
cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
2010-09-30 05:11:26 +00:00
}
else {
if( e.x || e.y ) {
cursor.x = e.x;
cursor.y = e.y;
2010-09-30 05:11:26 +00:00
}
}
}
return cursor;
}
2010-09-30 05:11:26 +00:00
function lockview(type, id) {
$.get('lockview/' + type + '/' + id, function(data) {
$('#panel-' + id).html(data);
});
}
2010-09-30 05:11:26 +00:00
function filestorage(event, nick, id) {
$('#cloud-index-' + last_filestorage_id).removeClass('cloud-index-active');
$('#perms-panel-' + last_filestorage_id).hide().html('');
$('#file-edit-' + id).show();
$.get('filestorage/' + nick + '/' + id + '/edit', function(data) {
$('#cloud-index-' + id).addClass('cloud-index-active');
$('#perms-panel-' + id).html(data).show();
$('#file-edit-' + id).hide();
last_filestorage_id = id;
});
}
2020-01-27 23:54:43 +00:00
function submitPoll(id) {
$.post('vote/' + id,
2020-01-29 02:17:47 +00:00
$('#question-form-' + id).serialize(),
function(data) {
$.jGrowl(data.message, { sticky: false, theme: ((data.success) ? 'info' : 'notice'), life: 10000 });
2020-01-28 04:46:14 +00:00
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,1500);
2020-01-29 02:17:47 +00:00
}
2020-01-28 04:46:14 +00:00
);
2020-01-27 23:54:43 +00:00
}
function post_comment(id) {
unpause();
commentBusy = true;
$('body').css('cursor', 'wait');
$("#comment-preview-inp-" + id).val("0");
$.post(
"item",
$("#comment-edit-form-" + id).serialize(),
function(data) {
if(data.success) {
2018-04-13 10:50:37 +00:00
localStorage.removeItem("comment_body-" + id);
$("#comment-edit-preview-" + id).hide();
$("#comment-edit-wrapper-" + id).hide();
$("#comment-edit-text-" + id).val('');
let tarea = document.getElementById("comment-edit-text-" + id);
if(tarea) {
commentClose(tarea, id);
$(document).unbind( "click.commentOpen");
}
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,1500);
}
if(data.reload) {
window.location.href=data.reload;
}
},
"json"
);
return false;
}
2011-02-14 12:43:19 +00:00
function preview_comment(id) {
$("#comment-preview-inp-" + id).val("1");
$("#comment-edit-preview-" + id).show();
$.post(
"item",
$("#comment-edit-form-" + id).serialize(),
function(data) {
if(data.preview) {
$("#comment-edit-preview-" + id).html(data.preview);
$("#comment-edit-preview-" + id + " .autotime").timeago();
$("#comment-edit-preview-" + id + " a").click(function() { return false; });
}
},
"json"
);
return true;
}
2012-01-06 00:38:24 +00:00
function importElement(elem) {
$.post(
"impel",
{ "element" : elem },
function(data) {
if(timer) clearTimeout(timer);
timer = setTimeout(updateInit,10);
}
);
return false;
}
2012-01-06 00:38:24 +00:00
function preview_post() {
$("#jot-preview").val("1");
$("#jot-preview-content").show();
$.post(
"item",
$("#profile-jot-form").serialize(),
function(data) {
if(data.preview) {
$("#jot-preview-content").html(data.preview);
$("#jot-preview-content .autotime").timeago();
$("#jot-preview-content" + " a").click(function() { return false; });
}
},
"json"
);
$("#jot-preview").val("0");
return true;
}
2014-10-07 00:47:17 +00:00
2020-11-30 00:38:45 +00:00
function save_draft() {
$("#jot-draft").val("1");
$.post(
"item",
$("#profile-jot-form").serialize(),
function() {
itemCancel();
document.location.href=document.location.href;
},
);
return true;
}
2021-03-07 23:11:03 +00:00
function save_draft_comment(id) {
$("#comment-draft-" + id).val("1");
$.post(
"item",
$("#comment-edit-form-" + id).serialize(),
function() {
commentCancel(id);
document.location.href=document.location.href;
},
);
return true;
}
2020-11-30 00:38:45 +00:00
2016-12-14 01:30:02 +00:00
function preview_mail() {
$("#mail-preview").val("1");
$("#mail-preview-content").show();
$.post(
"mail",
$("#prvmail-form").serialize(),
function(data) {
if(data.preview) {
$("#mail-preview-content").html(data.preview);
$("#mail-preview-content" + " a").click(function() { return false; });
}
},
"json"
);
$("#mail-preview").val("0");
return true;
}
function unpause() {
// unpause auto reloads if they are currently stopped
totStopped = false;
stopped = false;
$('#pause').html('');
}
2012-01-06 00:38:24 +00:00
function bin2hex(s) {
// Converts the binary representation of data to hex
//
// version: 812.316
// discuss at: http://phpjs.org/functions/bin2hex
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Linuxworld
// * example 1: bin2hex('Kev');
// * returns 1: '4b6576'
// * example 2: bin2hex(String.fromCharCode(0x00));
// * returns 2: '00'
let v,i, f = 0, a = [];
s += '';
f = s.length;
for (i = 0; i<f; i++) {
a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
2012-01-10 02:52:49 +00:00
}
return a.join('');
}
2012-01-06 00:38:24 +00:00
function hex2bin(hex) {
let bytes = [], str;
for(let i=0; i< hex.length-1; i+=2)
bytes.push(parseInt(hex.substr(i, 2), 16));
2011-04-13 04:21:33 +00:00
return String.fromCharCode.apply(String, bytes);
}
2011-04-13 04:21:33 +00:00
function groupChangeMember(gid, cid, sec_token) {
$('body .fakelink').css('cursor', 'wait');
2019-10-02 02:03:48 +00:00
$.get('lists/' + gid + '/' + cid + "?t=" + sec_token, function(data) {
$('#group-update-wrapper').html(data);
$('body .fakelink').css('cursor', 'auto');
});
}
function profChangeMember(gid, cid) {
$('body .fakelink').css('cursor', 'wait');
$.get('profperm/' + gid + '/' + cid, function(data) {
$('#prof-update-wrapper').html(data);
$('body .fakelink').css('cursor', 'auto');
});
}
function contactgroupChangeMember(gid, cid) {
$('body').css('cursor', 'wait');
$.get('contactgroup/' + gid + '/' + cid, function(data) {
$('body').css('cursor', 'auto');
2016-04-30 18:51:01 +00:00
$('#group-' + gid).toggleClass('fa-check-square-o fa-square-o');
});
}
function checkboxhighlight(box) {
if($(box).is(':checked')) {
$(box).addClass('checkeditem');
} else {
$(box).removeClass('checkeditem');
}
}
/**
* sprintf in javascript
* "{0} and {1}".format('zero','uno');
*/
String.prototype.format = function() {
let formatted = this;
for (let i = 0; i < arguments.length; i++) {
let regexp = new RegExp('\\{'+i+'\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
2011-07-19 14:17:58 +00:00
// Array Remove
Array.prototype.remove = function(item) {
to = undefined;
from = this.indexOf(item);
let rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
2011-07-19 14:17:58 +00:00
};
function zFormError(elm,x) {
if(x) {
$(elm).addClass("zform-error");
$(elm).removeClass("zform-ok");
} else {
$(elm).addClass("zform-ok");
$(elm).removeClass("zform-error");
}
}
$(window).scroll(function () {
if(typeof buildCmd == 'function') {
// This is a content page with items and/or conversations
if($(window).scrollTop() + $(window).height() > $(document).height() - 300) {
if((pageHasMoreContent) && (! loadingPage)) {
next_page++;
scroll_next = true;
loadingPage = true;
liveUpdate();
}
}
}
else {
// This is some other kind of page - perhaps a directory
if($(window).scrollTop() + $(window).height() > $(document).height() - 300) {
if((pageHasMoreContent) && (! loadingPage) && (! justifiedGalleryActive)) {
next_page++;
scroll_next = true;
loadingPage = true;
pageUpdate();
}
}
}
});
let chanviewFullSize = false;
function chanviewFull() {
if(chanviewFullSize) {
chanviewFullSize = false;
$('#chanview-iframe-border').css({ 'position' : 'relative', 'z-index' : '10' });
$('#remote-channel').css({ 'position' : 'relative' , 'z-index' : '10' });
}
else {
chanviewFullSize = true;
$('#chanview-iframe-border').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150001' });
$('#remote-channel').css({ 'position' : 'fixed', 'top' : '0', 'left' : '0', 'z-index' : '150000' });
resize_iframe();
}
}
function addhtmltext(data) {
data = h2b(data);
addeditortext(data);
}
function loadText(textRegion,data) {
let currentText = $(textRegion).val();
$(textRegion).val(currentText + data);
}
function addeditortext(data) {
if(plaintext == 'none') {
let currentText = $("#profile-jot-text").val();
$("#profile-jot-text").val(currentText + data);
}
}
function h2b(s) {
let y = s;
function rep(re, str) {
y = y.replace(re,str);
}
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
rep(/<span style=\"color:(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
rep(/<font>(.*?)<\/font>/gi,"$1");
rep(/<img.*?width=\"(.*?)\".*?height=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$1x$2]$3[/img]");
rep(/<img.*?height=\"(.*?)\".*?width=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$2x$1]$3[/img]");
rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");
rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");
rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
rep(/<ul class=\"listbullet\" style=\"list-style-type\: circle\;\">(.*?)<\/ul>/gi,"[list]$1[/list]");
rep(/<ul class=\"listnone\" style=\"list-style-type\: none\;\">(.*?)<\/ul>/gi,"[list=]$1[/list]");
rep(/<ul class=\"listdecimal\" style=\"list-style-type\: decimal\;\">(.*?)<\/ul>/gi,"[list=1]$1[/list]");
rep(/<ul class=\"listlowerroman\" style=\"list-style-type\: lower-roman\;\">(.*?)<\/ul>/gi,"[list=i]$1[/list]");
rep(/<ul class=\"listupperroman\" style=\"list-style-type\: upper-roman\;\">(.*?)<\/ul>/gi,"[list=I]$1[/list]");
rep(/<ul class=\"listloweralpha\" style=\"list-style-type\: lower-alpha\;\">(.*?)<\/ul>/gi,"[list=a]$1[/list]");
rep(/<ul class=\"listupperalpha\" style=\"list-style-type\: upper-alpha\;\">(.*?)<\/ul>/gi,"[list=A]$1[/list]");
rep(/<li>(.*?)<\/li>/gi,"[li]$1[/li]");
rep(/<code>(.*?)<\/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 style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
rep(/<u>/gi,"[u]");
rep(/<blockquote[^>]*>/gi,"[quote]");
rep(/<\/blockquote>/gi,"[/quote]");
rep(/<hr \/>/gi,"[hr]");
rep(/<br (.*?)\/>/gi,"\n");
rep(/<br\/>/gi,"\n");
rep(/<br>/gi,"\n");
rep(/<p>/gi,"");
rep(/<\/p>/gi,"\n");
rep(/&nbsp;/gi," ");
rep(/&quot;/gi,"\"");
rep(/&lt;/gi,"<");
rep(/&gt;/gi,">");
rep(/&amp;/gi,"&");
return y;
}
function b2h(s) {
let y = s;
function rep(re, str) {
y = y.replace(re,str);
}
rep(/\&/gi,"&amp;");
rep(/\</gi,"&lt;");
rep(/\>/gi,"&gt;");
rep(/\"/gi,"&quot;");
2019-11-22 04:00:57 +00:00
rep(/\n/gi,"<br>");
rep(/\[b\]/gi,"<strong>");
rep(/\[\/b\]/gi,"</strong>");
rep(/\[i\]/gi,"<em>");
rep(/\[\/i\]/gi,"</em>");
rep(/\[u\]/gi,"<u>");
rep(/\[\/u\]/gi,"</u>");
rep(/\[hr\]/gi,"<hr />");
rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3\" />");
rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
rep(/\[zrl=([^\]]+)\](.*?)\[\/zrl\]/gi,"<a href=\"$1" + '?f=&zid=' + zid + "\">$2</a>");
rep(/\[zrl\](.*?)\[\/zrl\]/gi,"<a href=\"$1" + '?f=&zid=' + zid + "\">$1</a>");
rep(/\[zmg=(.*?)x(.*?)\](.*?)\[\/zmg\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3" + '?f=&zid=' + zid + "\" />");
rep(/\[zmg\](.*?)\[\/zmg\]/gi,"<img src=\"$1" + '?f=&zid=' + zid + "\" />");
rep(/\[list\](.*?)\[\/list\]/gi, '<ul class="listbullet" style="list-style-type: circle;">$1</ul>');
rep(/\[list=\](.*?)\[\/list\]/gi, '<ul class="listnone" style="list-style-type: none;">$1</ul>');
rep(/\[list=1\](.*?)\[\/list\]/gi, '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');
rep(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');
rep(/\[list=I\](.*?)\[\/list\]/gi, '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');
rep(/\[list=a\](.*?)\[\/list\]/gi, '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');
rep(/\[list=A\](.*?)\[\/list\]/gi, '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');
rep(/\[li\](.*?)\[\/li\]/gi, '<li>$1</li>');
rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");
rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");
rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");
rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");
rep(/\[video\](.*?)\[\/video\]/gi,"<a href=\"$1\">$1</a>");
rep(/\[audio\](.*?)\[\/audio\]/gi,"<a href=\"$1\">$1</a>");
rep(/\[\&amp\;([#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;
let has_params = ((s.indexOf('?') == (-1)) ? false : true);
let achar = ((has_params) ? '&' : '?');
s = s + achar + 'f=&zid=' + zid;
return s;
2015-03-26 08:45:30 +00:00
}