Fix JS to replace liveblog plugin

This commit is contained in:
Iacopo Spalletti 2016-09-16 01:05:32 +02:00
parent 51c99f6f79
commit 67536d5ca5
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6

View file

@ -9,11 +9,11 @@ document.addEventListener("DOMContentLoaded", function() {
var data = JSON.parse(message.data);
// See if there's a div to replace it in, or if we should add a new one
var existing = document.querySelectorAll("div[data-post-id*='" + data.id + "']");
if (existing.length) {
existing.parentNode.replaceChild(data.content, existing);
var item = document.createElement('div');
item.innerHTML = data.content;
if (existing.length > 0) {
existing[0].parentNode.replaceChild(item.children[0], existing[0]);
} else {
var item = document.createElement('div');
item.innerHTML = data.content;
document.getElementById("liveblog-posts").insertBefore(
item.children[0], document.getElementById("liveblog-posts").children[0]
);