radically reduce code duplication in updateConvItems(); it's a bit easier to understand now although the different modes aren't as cleanly separated as they were.
This commit is contained in:
parent
cff5e360fd
commit
0098dce597
166
view/js/main.js
166
view/js/main.js
@ -533,133 +533,76 @@ function updatePageItems(mode, data) {
|
|||||||
|
|
||||||
function updateConvItems(mode,data) {
|
function updateConvItems(mode,data) {
|
||||||
|
|
||||||
if(mode === 'update') {
|
if(mode === 'update' || mode === 'replace') {
|
||||||
prev = 'threads-begin';
|
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') {
|
if(mode === 'append') {
|
||||||
|
|
||||||
next = 'threads-end';
|
next = 'threads-end';
|
||||||
|
|
||||||
$('.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;
|
|
||||||
|
|
||||||
if(typeof commentWrap !== 'undefined')
|
|
||||||
itmId = commentWrap.replace('collapsed-comments-', '');
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(loadingPage) {
|
|
||||||
loadingPage = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mode === 'replace') {
|
if(mode === 'replace') {
|
||||||
// clear existing content
|
$('.thread-wrapper').remove(); // clear existing content
|
||||||
$('.thread-wrapper').remove();
|
}
|
||||||
|
|
||||||
prev = 'threads-begin';
|
$('.thread-wrapper.toplevel_item',data).each(function() {
|
||||||
|
|
||||||
$('.thread-wrapper.toplevel_item',data).each(function() {
|
var ident = $(this).attr('id');
|
||||||
|
|
||||||
var ident = $(this).attr('id');
|
var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
|
||||||
var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
|
var itmId = 0;
|
||||||
var itmId = 0;
|
var isVisible = false;
|
||||||
var isVisible = false;
|
|
||||||
|
|
||||||
if(typeof commentWrap !== 'undefined')
|
// figure out the comment state
|
||||||
itmId = commentWrap.replace('collapsed-comments-','');
|
if(typeof commentWrap !== 'undefined')
|
||||||
|
itmId = commentWrap.replace('collapsed-comments-','');
|
||||||
|
|
||||||
if($('#' + ident).length == 0 && profile_page == 1) {
|
if($('#collapsed-comments-'+itmId).is(':visible'))
|
||||||
$('img',this).each(function() {
|
isVisible = true;
|
||||||
$(this).attr('src',$(this).attr('dst'));
|
|
||||||
});
|
// insert the content according to the mode and first_page
|
||||||
if($('#collapsed-comments-'+itmId).is(':visible'))
|
// and whether or not the content exists already (overwrite it)
|
||||||
isVisible = true;
|
|
||||||
$('#' + prev).after($(this));
|
if($('#' + ident).length == 0) {
|
||||||
if(isVisible)
|
if((mode === 'update' || mode === 'replace') && profile_page == 1) {
|
||||||
showHideComments(itmId);
|
$('#' + prev).after($(this));
|
||||||
$("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
|
prev = ident;
|
||||||
$("> .shared_header .autotime",this).timeago();
|
|
||||||
}
|
}
|
||||||
prev = ident;
|
if(mode === 'append') {
|
||||||
});
|
$('#' + next).before($(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('#' + ident).replaceWith($(this));
|
||||||
|
}
|
||||||
|
|
||||||
if(loadingPage) {
|
// set the comment state to the state we discovered earlier
|
||||||
|
|
||||||
|
if(isVisible)
|
||||||
|
showHideComments(itmId);
|
||||||
|
|
||||||
|
// trigger the autotime function on all newly created content
|
||||||
|
|
||||||
|
$("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
|
||||||
|
$("> .shared_header .autotime",this).timeago();
|
||||||
|
|
||||||
|
if((mode === 'append' || mode === 'replace') && (loadingPage)) {
|
||||||
loadingPage = false;
|
loadingPage = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.location.search.indexOf("mid=") != -1 || window.location.pathname.indexOf("display") != -1) {
|
// if single thread view and the item has a title, display it in the title bar
|
||||||
var title = $(".wall-item-title").text();
|
|
||||||
title.replace(/^\s+/, '');
|
if(mode === 'replace') {
|
||||||
title.replace(/\s+$/, '');
|
if (window.location.search.indexOf("mid=") != -1 || window.location.pathname.indexOf("display") != -1) {
|
||||||
if (title)
|
var title = $(".wall-item-title").text();
|
||||||
document.title = title + " - " + document.title;
|
title.replace(/^\s+/, '');
|
||||||
|
title.replace(/\s+$/, '');
|
||||||
|
if (title)
|
||||||
|
document.title = title + " - " + document.title;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// reset rotators and cursors we may have set before reaching this place
|
||||||
|
|
||||||
$('.like-rotator').spin(false);
|
$('.like-rotator').spin(false);
|
||||||
|
|
||||||
@ -668,6 +611,9 @@ function updateConvItems(mode,data) {
|
|||||||
$('body').css('cursor', 'auto');
|
$('body').css('cursor', 'auto');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup to determine if the media player is playing. This affects
|
||||||
|
// some content loading decisions.
|
||||||
|
|
||||||
$('video').off('playing');
|
$('video').off('playing');
|
||||||
$('video').off('pause');
|
$('video').off('pause');
|
||||||
$('audio').off('playing');
|
$('audio').off('playing');
|
||||||
|
Reference in New Issue
Block a user