aboutsummaryrefslogtreecommitdiffstats
path: root/view/js/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'view/js/main.js')
-rw-r--r--view/js/main.js371
1 files changed, 210 insertions, 161 deletions
diff --git a/view/js/main.js b/view/js/main.js
index 5de4aa9a2..73b2f3616 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -1,6 +1,55 @@
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) {
+ form.find('.comment-edit-text').addClass('expanded').removeAttr('placeholder');
+ 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) {
+ form.find('.comment-edit-text').removeClass('expanded').attr('placeholder', aStr.comment);
+ form.find(':not(.comment-edit-text)').hide();
+ }
+ });
+}
+
+/*
function commentOpenUI(obj, id) {
$(document).unbind( "click.commentOpen", handler );
@@ -13,6 +62,7 @@ function commentOpenUI(obj, id) {
$("#comment-edit-text-" + id).attr('tabindex','9');
$("#comment-edit-submit-" + id).attr('tabindex','10');
$("#comment-tools-" + id).show();
+ $("#comment-edit-anon-" + id).show();
}
};
@@ -20,15 +70,20 @@ function commentOpenUI(obj, id) {
}
function commentCloseUI(obj, id) {
- $(document).unbind( "click.commentClose", handler );
+ var form_id = $(obj)[0].form.id;
+
+ $('#' + form_id).on('click', function(e) {
+ $(document).unbind( "click.commentClose", handler );
+ });
var handler = function() {
- if(obj.value === '') {
- obj.value = aStr.comment;
+ if($('#comment-edit-text-' + id).val() === '') {
+ $('#comment-edit-text-' + id).val(aStr.comment);
$("#comment-edit-text-" + id).removeClass("comment-edit-text-full").addClass("comment-edit-text-empty");
$("#comment-edit-text-" + id).removeAttr('tabindex');
$("#comment-edit-submit-" + id).removeAttr('tabindex');
$("#comment-tools-" + id).hide();
+ $("#comment-edit-anon-" + id).hide();
}
};
@@ -38,27 +93,28 @@ function commentCloseUI(obj, id) {
function commentOpen(obj, id) {
if(obj.value == aStr.comment) {
obj.value = '';
- $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
+ $("#comment-edit-text-" + id).addClass("expanded");
$("#mod-cmnt-wrap-" + id).show();
- openMenu("comment-tools-" + id);
+ $("#comment-tools-" + id).show();
+ $("#comment-edit-anon-" + id).show();
return true;
}
return false;
}
-
+*/
function commentClose(obj, id) {
if(obj.value === '') {
obj.value = aStr.comment;
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).addClass("comment-edit-text-empty");
+ $("#comment-edit-text-" + id).removeClass("expanded");
$("#mod-cmnt-wrap-" + id).hide();
- closeMenu("comment-tools-" + id);
+ $("#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();
@@ -71,8 +127,7 @@ function commentInsert(obj, id) {
var tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == '$comment') {
tmpStr = '';
- $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
+ $("#comment-edit-text-" + id).addClass("expanded");
openMenu("comment-tools-" + id);
}
var ins = $(obj).html();
@@ -93,8 +148,7 @@ function insertbbcomment(comment, BBcode, id) {
var tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == comment) {
tmpStr = "";
- $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
+ $("#comment-edit-text-" + id).addClass("expanded");
openMenu("comment-tools-" + id);
$("#comment-edit-text-" + id).val(tmpStr);
}
@@ -130,6 +184,19 @@ function inserteditortag(BBcode, id) {
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) {
@@ -139,14 +206,14 @@ function insertCommentURL(comment, id) {
var tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == comment) {
tmpStr = "";
- $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
+ $("#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');
});
}
@@ -161,8 +228,7 @@ function qCommentInsert(obj, id) {
var tmpStr = $("#comment-edit-text-" + id).val();
if(tmpStr == aStr.comment) {
tmpStr = '';
- $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
- $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
+ $("#comment-edit-text-" + id).addClass("expanded");
openMenu("comment-edit-submit-wrapper-" + id);
}
var ins = $(obj).val();
@@ -196,6 +262,14 @@ function openClose(theID) {
}
}
+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";
@@ -215,7 +289,7 @@ function closeMenu(theID) {
function markRead(notifType) {
$.get('ping?f=&markRead='+notifType);
if(timer) clearTimeout(timer);
- $('#' + notifType + '-update').html('');
+ $('.' + notifType + '-button').hide();
timer = setTimeout(NavUpdate,2000);
}
@@ -250,6 +324,7 @@ var last_filestorage_id = null;
var mediaPlaying = false;
var contentHeightDiff = 0;
var liveRecurse = 0;
+var savedTitle = '';
$(function() {
$.ajaxSetup({cache: false});
@@ -339,7 +414,7 @@ $(function() {
function NavUpdate() {
if(liking)
- $('.like-rotator').spin(false);
+ $('.like-rotator').hide();
if((! stopped) && (! mediaPlaying)) {
var pingCmd = 'ping' + ((localUser != 0) ? '?f=&uid=' + localUser : '');
@@ -357,8 +432,9 @@ function NavUpdate() {
if($('#live-pubstream').length) { src = 'pubstream'; liveUpdate(); }
if($('#live-display').length) { src = 'display'; liveUpdate(); }
if($('#live-search').length) { src = 'search'; liveUpdate(); }
+ // if($('#live-cards').length) { src = 'cards'; liveUpdate(); }
- if($('#live-photos').length) {
+ if($('#live-photos').length || $('#live-cards').length) {
if(liking) {
liking = 0;
window.location.href=window.location.href;
@@ -368,21 +444,39 @@ function NavUpdate() {
updateCountsOnly = false;
- if(data.network || data.home || data.intros || data.mail || data.all_events || data.notify) {
- $('#notifications-btn').css('color', 'white').prop('disabled', false);
+ if(data.network || data.home || data.intros || data.mail || data.all_events || data.notify || data.files || data.pubs) {
+ $('#notifications-btn').css('opacity', 1);
}
else {
- $('#notifications-btn').css('color', 'grey').prop('disabled', true);
- $('#navbar-collapse-1').removeClass('in');
+ $('#notifications-btn').css('opacity', 0.5);
+ $('#navbar-collapse-1').removeClass('show');
}
if(data.network == 0) {
data.network = '';
- $('.net-update, .net-button').hide();
+ $('.network-update, .network-button').hide();
+ document.title = savedTitle;
} else {
- $('.net-update, .net-button').show();
+ $('.network-update, .network-button').show();
+ document.title = '(' + data.network + ') ' + savedTitle;
}
- $('.net-update').html(data.network);
+ $('.network-update').html(data.network);
+
+ if(data.pubs == 0) {
+ data.pubs = '';
+ $('.pubs-update, .pubs-button').hide();
+ } else {
+ $('.pubs-update, .pubs-button').show();
+ }
+ $('.pubs-update').html(data.pubs);
+
+ if(data.files == 0) {
+ data.files = '';
+ $('.files-update, .files-button').hide();
+ } else {
+ $('.files-update, .files-button').show();
+ }
+ $('.files-update').html(data.files);
if(data.home == 0) { data.home = ''; $('.home-update, .home-button').hide(); } else { $('.home-update, .home-button').show(); }
$('.home-update').html(data.home);
@@ -491,141 +585,88 @@ function updatePageItems(mode, data) {
function updateConvItems(mode,data) {
- if(mode === 'update') {
+ if(mode === 'update' || mode === 'replace') {
prev = 'threads-begin';
-
- $('.thread-wrapper.toplevel_item',data).each(function() {
-
- var ident = $(this).attr('id');
- // This should probably use the context argument instead
- var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
- var itmId = 0;
- var isVisible = false;
-
- if(typeof commentWrap !== 'undefined')
- itmId = commentWrap.replace('collapsed-comments-','');
-
- if($('#' + ident).length == 0 && profile_page == 1) {
- $('img',this).each(function() {
- $(this).attr('src',$(this).attr('dst'));
- });
- if($('#collapsed-comments-'+itmId).is(':visible'))
- isVisible = true;
- $('#' + prev).after($(this));
- if(isVisible)
- showHideComments(itmId);
- $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
- $("> .shared_header .autotime",this).timeago();
- }
- else {
- $('img',this).each(function() {
- $(this).attr('src',$(this).attr('dst'));
- });
- if($('#collapsed-comments-'+itmId).is(':visible'))
- isVisible = true;
- $('#' + ident).replaceWith($(this));
- if(isVisible)
- showHideComments(itmId);
- $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
- $("> .shared_header .autotime",this).timeago();
- }
- prev = ident;
- });
}
if(mode === 'append') {
-
next = 'threads-end';
+ }
+
+ if(mode === 'replace') {
+ $('.thread-wrapper').remove(); // clear existing content
+ }
- $('.thread-wrapper.toplevel_item',data).each(function() {
- var ident = $(this).attr('id');
- var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
- var itmId = 0;
- var isVisible = false;
+ $('.thread-wrapper.toplevel_item',data).each(function() {
- if(typeof commentWrap !== 'undefined')
- itmId = commentWrap.replace('collapsed-comments-', '');
+ var ident = $(this).attr('id');
- if($('#' + ident).length == 0) {
- $('img',this).each(function() {
- $(this).attr('src',$(this).attr('dst'));
- });
- if($('#collapsed-comments-'+itmId).is(':visible'))
- isVisible = true;
- $('#threads-end').before($(this));
- if(isVisible)
- showHideComments(itmId);
- $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
- $("> .shared_header .autotime",this).timeago();
- }
- else {
- $('img',this).each(function() {
- $(this).attr('src', $(this).attr('dst'));
- });
- if($('#collapsed-comments-'+itmId).is(':visible'))
- isVisible = true;
- $('#' + ident).replaceWith($(this));
- if(isVisible)
- showHideComments(itmId);
- $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
- $("> .shared_header .autotime",this).timeago();
- }
- });
+ var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
+ var itmId = 0;
+ var isVisible = false;
- if(loadingPage) {
- loadingPage = false;
- }
- }
- if(mode === 'replace') {
- // clear existing content
- $('.thread-wrapper').remove();
+ // figure out the comment state
+ if(typeof commentWrap !== 'undefined')
+ itmId = commentWrap.replace('collapsed-comments-','');
+
+ if($('#collapsed-comments-'+itmId).is(':visible'))
+ isVisible = true;
- prev = 'threads-begin';
+ // insert the content according to the mode and first_page
+ // and whether or not the content exists already (overwrite it)
- $('.thread-wrapper.toplevel_item',data).each(function() {
+ if($('#' + ident).length == 0) {
+ if((mode === 'update' || mode === 'replace') && profile_page == 1) {
+ $('#' + prev).after($(this));
+ prev = ident;
+ }
+ if(mode === 'append') {
+ $('#' + next).before($(this));
+ }
+ }
+ else {
+ $('#' + ident).replaceWith($(this));
+ }
- var ident = $(this).attr('id');
- var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
- var itmId = 0;
- var isVisible = false;
+ // set the comment state to the state we discovered earlier
- if(typeof commentWrap !== 'undefined')
- itmId = commentWrap.replace('collapsed-comments-','');
+ if(isVisible)
+ showHideComments(itmId);
- if($('#' + ident).length == 0 && profile_page == 1) {
- $('img',this).each(function() {
- $(this).attr('src',$(this).attr('dst'));
- });
- if($('#collapsed-comments-'+itmId).is(':visible'))
- isVisible = true;
- $('#' + prev).after($(this));
- if(isVisible)
- showHideComments(itmId);
- $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
- $("> .shared_header .autotime",this).timeago();
- }
- prev = ident;
- });
+ // trigger the autotime function on all newly created content
- if(loadingPage) {
+ $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
+ $("> .shared_header .autotime",this).timeago();
+
+ if((mode === 'append' || mode === 'replace') && (loadingPage)) {
loadingPage = false;
}
- if (window.location.search.indexOf("mid=") != -1 || window.location.pathname.indexOf("display") != -1) {
- var title = $(".wall-item-title").text();
- title.replace(/^\s+/, '');
- title.replace(/\s+$/, '');
- if (title)
- document.title = title + " - " + document.title;
+ // 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) {
+ var title = $(".wall-item-title").text();
+ title.replace(/^\s+/, '');
+ title.replace(/\s+$/, '');
+ if (title) {
+ savedTitle = title + " " + savedTitle;
+ }
+ }
}
- }
+ });
- $('.like-rotator').spin(false);
+ // reset rotators and cursors we may have set before reaching this place
+
+ $('.like-rotator').hide();
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');
@@ -665,10 +706,12 @@ function updateConvItems(mode,data) {
// 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,
- // substr(0,32) + base64_encode + replace(['+','='],['','']);
- var submid = bParam_mid;
- var submid_encoded = ((submid.length) ? submid.substring(0,32) : 'abcdefg');
- submid_encoded = window.btoa(submid_encoded);
+ // base64_encode + replace(['+','='],['','']);
+
+ var submid = ((bParam_mid.length) ? bParam_mid : 'abcdefg');
+ var encoded = ((submid.substr(0,4) == 'b64.') ? true : false);
+ var 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) {
@@ -695,7 +738,7 @@ function collapseHeight() {
$(".wall-item-content, .directory-collapse").each(function() {
var orgHeight = $(this).outerHeight(true);
if(orgHeight > divmore_height) {
- if(! $(this).hasClass('divmore')) {
+ 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
if($(this).offset().top + divmore_height - $(window).scrollTop() + cDiff - ($(".divgrow-showmore").outerHeight() * i) < 65) {
@@ -738,8 +781,8 @@ function collapseHeight() {
function liveUpdate() {
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').spin(false); return; }
- if(($('.comment-edit-text-full').length) || (in_progress)) {
+ if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; }
+ if(($('.comment-edit-text.expanded').length) || (in_progress)) {
if(livetime) {
clearTimeout(livetime);
}
@@ -767,7 +810,7 @@ function liveUpdate() {
update_url = buildCmd();
if(page_load) {
- $("#page-spinner").spin('small');
+ $("#page-spinner").show();
if(bParam_page == 1)
update_mode = 'replace';
else
@@ -816,8 +859,8 @@ function liveUpdate() {
page_load = false;
scroll_next = false;
updateConvItems(update_mode,data);
- $("#page-spinner").spin(false);
- $("#profile-jot-text-loading").spin(false);
+ $("#page-spinner").hide();
+ $("#profile-jot-text-loading").hide();
// adjust scroll position if new content was added above viewport
if(update_mode === 'update') {
@@ -846,8 +889,8 @@ function liveUpdate() {
page_load = false;
scroll_next = false;
updateConvItems(update_mode,data);
- $("#page-spinner").spin(false);
- $("#profile-jot-text-loading").spin(false);
+ $("#page-spinner").hide();
+ $("#profile-jot-text-loading").hide();
in_progress = false;
@@ -887,14 +930,14 @@ function pageUpdate() {
update_url = baseurl + '/' + page_query + '/?f=&aj=1&page=' + bParam_page + extra_args ;
- $("#page-spinner").spin('small');
+ $("#page-spinner").show();
update_mode = 'append';
$.get(update_url,function(data) {
page_load = false;
scroll_next = false;
updatePageItems(update_mode,data);
- $("#page-spinner").spin(false);
+ $("#page-spinner").hide();
$(".autotime").timeago();
in_progress = false;
});
@@ -902,6 +945,7 @@ function pageUpdate() {
function justifyPhotos(id) {
justifiedGalleryActive = true;
+ $('#' + id).show();
$('#' + id).justifiedGallery({
selector: 'a, div:not(.spinner, #page-end)',
margins: 3,
@@ -971,7 +1015,7 @@ function notify_popup_loader(notifyType) {
function dolike(ident, verb) {
unpause();
- $('#like-rotator-' + ident.toString()).spin('tiny');
+ $('#like-rotator-' + ident.toString()).show();
$.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
liking = 1;
}
@@ -1001,7 +1045,7 @@ function dropItem(url, object) {
function dosubthread(ident) {
unpause();
- $('#like-rotator-' + ident.toString()).spin('tiny');
+ $('#like-rotator-' + ident.toString()).show();
$.get('subthread/sub/' + ident.toString(), NavUpdate );
liking = 1;
}
@@ -1009,7 +1053,7 @@ function dosubthread(ident) {
function dounsubthread(ident) {
unpause();
- $('#like-rotator-' + ident.toString()).spin('tiny');
+ $('#like-rotator-' + ident.toString()).show();
$.get('subthread/unsub/' + ident.toString(), NavUpdate );
liking = 1;
}
@@ -1018,7 +1062,7 @@ function dounsubthread(ident) {
function dostar(ident) {
ident = ident.toString();
- $('#like-rotator-' + ident).spin('tiny');
+ $('#like-rotator-' + ident).show();
$.get('starred/' + ident, function(data) {
if(data.result == 1) {
$('#starred-' + ident).addClass('starred');
@@ -1036,7 +1080,7 @@ function dostar(ident) {
$('#star-' + ident).removeClass('hidden');
$('#unstar-' + ident).addClass('hidden');
}
- $('#like-rotator-' + ident).spin(false);
+ $('#like-rotator-' + ident).hide();
});
}
@@ -1070,11 +1114,11 @@ function lockview(type, id) {
function filestorage(event, nick, id) {
$('#cloud-index-' + last_filestorage_id).removeClass('cloud-index-active');
$('#perms-panel-' + last_filestorage_id).hide().html('');
- $('#file-edit-' + id).spin('tiny');
+ $('#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).spin(false);
+ $('#file-edit-' + id).hide();
last_filestorage_id = id;
});
}
@@ -1093,8 +1137,10 @@ function post_comment(id) {
$("#comment-edit-wrapper-" + id).hide();
$("#comment-edit-text-" + id).val('');
var tarea = document.getElementById("comment-edit-text-" + id);
- if(tarea)
+ if(tarea) {
commentClose(tarea, id);
+ $(document).unbind( "click.commentOpen");
+ }
if(timer) clearTimeout(timer);
timer = setTimeout(NavUpdate,1500);
}
@@ -1321,9 +1367,10 @@ Array.prototype.remove = function(item) {
return this.push.apply(this, rest);
};
-
$(document).ready(function() {
+ $(document).on('click focus', '.comment-edit-form', handle_comment_form);
+
jQuery.timeago.settings.strings = {
prefixAgo : aStr['t01'],
prefixFromNow : aStr['t02'],
@@ -1344,6 +1391,8 @@ $(document).ready(function() {
numbers : aStr['t17'],
};
+ savedTitle = document.title;
+
});
function zFormError(elm,x) {