##// END OF EJS Templates
Refactored thread update code. Use indexOf() instead of contains() for strings...
neko259 -
r1085:f30638e5 default
parent child Browse files
Show More
@@ -58,7 +58,7 b' function addQuickReply(postId) {'
58
58
59 // If this is not OP, add reflink to the post. If there already is
59 // If this is not OP, add reflink to the post. If there already is
60 // the same reflink, don't add it again.
60 // the same reflink, don't add it again.
61 if (!post.is(':first-child') && !textAreaJq.val().contains(postLinkRaw)) {
61 if (!post.is(':first-child') && textAreaJq.val().indexOf(postLinkRaw) < 0) {
62 textToAdd += postLinkRaw + '\n';
62 textToAdd += postLinkRaw + '\n';
63 }
63 }
64
64
@@ -23,13 +23,15 b''
23 for the JavaScript code in this page.
23 for the JavaScript code in this page.
24 */
24 */
25
25
26 var CLASS_POST = '.post'
27
26 var wsUser = '';
28 var wsUser = '';
27
29
28 var unreadPosts = 0;
30 var unreadPosts = 0;
29 var documentOriginalTitle = '';
31 var documentOriginalTitle = '';
30
32
31 // Thread ID does not change, can be stored one time
33 // Thread ID does not change, can be stored one time
32 var threadId = $('div.thread').children('.post').first().attr('id');
34 var threadId = $('div.thread').children(CLASS_POST).first().attr('id');
33
35
34 /**
36 /**
35 * Connect to websocket server and subscribe to thread updates. On any update we
37 * Connect to websocket server and subscribe to thread updates. On any update we
@@ -97,6 +99,10 b' function getThreadDiff() {'
97 hasMetaUpdates = true;
99 hasMetaUpdates = true;
98 }
100 }
99
101
102 var addedPostsCount = addedPosts.length;
103 updateBumplimitProgress(addedPostsCount);
104 showNewPostsTitle(addedPostsCount);
105
100 var updatedPosts = data.updated;
106 var updatedPosts = data.updated;
101
107
102 for (var i = 0; i < updatedPosts.length; i++) {
108 for (var i = 0; i < updatedPosts.length; i++) {
@@ -136,13 +142,7 b' function updatePost(postHtml) {'
136 if (existingPosts.size() > 0) {
142 if (existingPosts.size() > 0) {
137 existingPosts.replaceWith(post);
143 existingPosts.replaceWith(post);
138 } else {
144 } else {
139 var threadPosts = threadBlock.children('.post');
145 post.appendTo(threadBlock);
140 var lastPost = threadPosts.last();
141
142 post.appendTo(lastPost.parent());
143
144 updateBumplimitProgress(1);
145 showNewPostsTitle(1);
146
146
147 if (bottom) {
147 if (bottom) {
148 scrollToBottom();
148 scrollToBottom();
@@ -176,7 +176,7 b' function initAutoupdate() {'
176 }
176 }
177
177
178 function getReplyCount() {
178 function getReplyCount() {
179 return $('.thread').children('.post').length
179 return $('.thread').children(CLASS_POST).length
180 }
180 }
181
181
182 function getImageCount() {
182 function getImageCount() {
General Comments 0
You need to be logged in to leave comments. Login now