diff options
author | zotlabs <mike@macgirvin.com> | 2017-08-25 00:00:51 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-08-25 00:00:51 -0700 |
commit | 0098dce5976bffb23dbb31d151d2d871c7cab8f9 (patch) | |
tree | a077d81f050441b7b9f1fac3255e3ae3ea5f72a5 /view/js | |
parent | cff5e360fd70832825ae7d6420602e573622d008 (diff) | |
download | volse-hubzilla-0098dce5976bffb23dbb31d151d2d871c7cab8f9.tar.gz volse-hubzilla-0098dce5976bffb23dbb31d151d2d871c7cab8f9.tar.bz2 volse-hubzilla-0098dce5976bffb23dbb31d151d2d871c7cab8f9.zip |
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.
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/main.js | 164 |
1 files changed, 55 insertions, 109 deletions
diff --git a/view/js/main.js b/view/js/main.js index fd3c8b08f..ece4c2015 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -533,133 +533,76 @@ 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) + document.title = title + " - " + document.title; + } } - } + }); + + // reset rotators and cursors we may have set before reaching this place $('.like-rotator').spin(false); @@ -668,6 +611,9 @@ function updateConvItems(mode,data) { $('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'); |