Browse code

fix paging

devnewton authored on 27/12/2017 14:30:10
Showing 1 changed files
... ...
@@ -296,20 +296,30 @@ jb3 = {
296 296
             var dates = container.getElementsByClassName("jb3-posts-date");
297 297
             var day = moment(message.time);
298 298
             var date = null;
299
+            var dateAfter = null;
299 300
             for (var d = 0; d < dates.length; ++d) {
300
-                if (moment(dates[d].dataset.date).isSame(day, 'day')) {
301
+                var dateDay = moment(dates[d].dataset.date);
302
+                if (dateDay.isSame(day, 'day')) {
301 303
                     date = dates[d];
302 304
                     break;
303 305
                 }
306
+                if (dateDay.isAfter(day, 'day')) {
307
+                    dateAfter = dates[d];
308
+                    break;
309
+                }
304 310
             }
305
-            if(!date) {
311
+            if (!date) {
306 312
                 date = document.createElement('div');
307 313
                 date.classList.add("jb3-posts-date");
308 314
                 date.dataset.date = day.format("YYYY-MM-DD");
309 315
                 var dateTitle = document.createElement('time');
310 316
                 dateTitle.appendChild(document.createTextNode(day.format("dddd D MMMM YYYY")));
311 317
                 date.appendChild(dateTitle);
312
-                container.insertAdjacentElement('beforeend', date);
318
+                if (dateAfter) {
319
+                    dateAfter.insertAdjacentElement('beforebegin', date);
320
+                } else {
321
+                    container.insertAdjacentElement('beforeend', date);
322
+                }
313 323
             }
314 324
             var t = message.time;
315 325
             var posts = date.getElementsByClassName('jb3-post');