Fix mobile browser hang issue when auto-reload by reducing DOM modification in forloop

This commit is contained in:
ben2613 2022-07-28 00:45:31 +01:00 committed by -
parent 57ee34ad55
commit f9cde257c0

View File

@ -196,6 +196,8 @@ $(document).ready(function(){
url: document.location,
success: function(data) {
var loaded_posts = 0; // the number of new posts loaded in this update
var elementsToAppend = [];
var elementsToTriggerNewpostEvent = [];
$(data).find('div.post.reply').each(function() {
var id = $(this).attr('id');
if($('#' + id).length == 0) {
@ -203,14 +205,18 @@ $(document).ready(function(){
var body = $(this).children('.body').html().replace(/<br\s*[\/]?>/gi, "\n");
var n = new Notification("New reply to "+ title, {body: $('<div/>').html(body).text()});
}
$(this).insertAfter($('div.post:not(.post-hover,.inline)').last().next()).after('<br class="clear">');
new_posts++;
loaded_posts++;
$(document).trigger('new_post', this);
recheck_activated();
elementsToAppend.push($(this));
elementsToAppend.push($('<br class="clear">'));
elementsToTriggerNewpostEvent.push(this);
}
});
$('div.post:last').next().after(elementsToAppend);
recheck_activated();
elementsToTriggerNewpostEvent.forEach(function(ele){
$(document).trigger('new_post', ele);
});
time_loaded = Date.now(); // interop with watch.js