diff options
Diffstat (limited to 'view/js/main.js')
-rw-r--r-- | view/js/main.js | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/view/js/main.js b/view/js/main.js index 82de0d06f..4d3b2d770 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -627,89 +627,84 @@ function updateConvItems(mode,data) { $('.thread-wrapper').remove(); // clear existing content } - $('.thread-wrapper.toplevel_item',data).each(function() { - - var ident = $(this).attr('id'); - var convId = ident.replace('thread-wrapper-',''); - var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); - - - var itmId = 0; - var isVisible = false; + $('.thread-wrapper', data).each(function() { + if(this.classList.contains('toplevel_item')) { - // figure out the comment state - if(typeof commentWrap !== 'undefined') - itmId = commentWrap.replace('collapsed-comments-',''); - - if($('#collapsed-comments-'+itmId).is(':visible')) - isVisible = true; + var ident = this.id; + var convId = ident.replace('thread-wrapper-',''); + var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); + var itmId = 0; + var isVisible = false; + // figure out the comment state + if(typeof commentWrap !== 'undefined') + itmId = commentWrap.replace('collapsed-comments-',''); + if($('#collapsed-comments-'+itmId).is(':visible')) + isVisible = true; - // insert the content according to the mode and first_page - // and whether or not the content exists already (overwrite it) + // 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; + if($('#' + ident).length == 0) { + if((mode === 'update' || mode === 'replace') && profile_page == 1) { + $('#' + prev).after($(this)); + prev = ident; + } + if(mode === 'append') { + $('#' + next).before($(this)); + } } - if(mode === 'append') { - $('#' + next).before($(this)); + else { + $('#' + ident).replaceWith($(this)); } - } - else { - $('#' + ident).replaceWith($(this)); - } - // set the comment state to the state we discovered earlier + // set the comment state to the state we discovered earlier - if(isVisible) - showHideComments(itmId); + if(isVisible) + showHideComments(itmId); - var commentBody = localStorage.getItem("comment_body-" + convId); + var commentBody = localStorage.getItem("comment_body-" + convId); - if(commentBody) { - var commentElm = $('#comment-edit-text-' + convId); - if(auto_save_draft) { - if($(commentElm).val() === '') { - $('#comment-edit-form-' + convId).show(); - $(commentElm).addClass("expanded"); - openMenu("comment-tools-" + convId); - $(commentElm).val(commentBody); + if(commentBody) { + var commentElm = $('#comment-edit-text-' + convId); + if(auto_save_draft) { + if($(commentElm).val() === '') { + $('#comment-edit-form-' + convId).show(); + $(commentElm).addClass("expanded"); + openMenu("comment-tools-" + convId); + $(commentElm).val(commentBody); + } + } else { + localStorage.removeItem("comment_body-" + convId); } - } else { - localStorage.removeItem("comment_body-" + convId); } - } - // trigger the autotime function on all newly created content - $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); - $("> .shared_header .autotime",this).timeago(); + // 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; - } + 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 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; - document.title = title; + 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; + document.title = title; + } } } } - }); - - // take care of the notifications count updates - $('.thread-wrapper', data).each(function() { + // take care of the notifications count updates var nmids = $(this).data('b64mids'); nmids.forEach(function(nmid, index) { @@ -976,7 +971,7 @@ function liveUpdate(notify_id) { var orgHeight = $("#region_2").height(); } - if(page_cache.data && bParam_page == page_cache.page && page_cache.time > (Date.now() - 60000)) { + if(page_cache.data && bParam_page == page_cache.page && page_cache.time > (Date.now() - 180000)) { page_load = false; scroll_next = false; updateConvItems(update_mode,page_cache.data); @@ -1080,6 +1075,7 @@ function cache_next_page() { if((data.indexOf("<html>") != (-1)) && (data.indexOf("</html>") == (-1))) { console.log('Incomplete data. Reloading'); in_progress = false; + bParam_page = bParam_page - 1; liveRecurse ++; if(liveRecurse < 10) { liveUpdate(); @@ -1554,7 +1550,7 @@ String.prototype.format = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\{'+i+'\\}', 'gi'); - formatted = formatted.replace(regexp, arguments[i]); + formatted = formatted.replace(regexp, ((typeof arguments[i] !== 'undefined') ? arguments[i] : '')); } return formatted; }; @@ -1880,7 +1876,7 @@ function sse_handleNotificationsItems(notifyType, data, replace, followup) { } $(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, encodeURIComponent(this.mids)); + 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); }); |