Remove jQuery dependency
This commit is contained in:
parent
d9dd192ca8
commit
3c4eebdd02
1 changed files with 11 additions and 14 deletions
|
@ -1,27 +1,24 @@
|
|||
$(function () {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Correctly decide between ws:// and wss://
|
||||
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
|
||||
var ws_path = ws_scheme + '://' + window.location.host + "/liveblog/liveblog/" + liveblog_apphook + "/" + liveblog_language + "/" + liveblog_post + "/";
|
||||
console.log("Connecting to " + ws_path);
|
||||
var socket = new ReconnectingWebSocket(ws_path);
|
||||
// Handle incoming messages
|
||||
socket.onmessage = function (message) {
|
||||
// Decode the JSON
|
||||
console.log("Got message " + message.data);
|
||||
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 = $("div[data-post-id=" + data.id + "]");
|
||||
var existing = document.querySelectorAll("div[data-post-id*='" + data.id + "']");
|
||||
if (existing.length) {
|
||||
existing.replaceWith(data.content);
|
||||
existing.parentNode.replaceChild(data.content, existing);
|
||||
} else {
|
||||
$("#liveblog-posts").prepend(data.content);
|
||||
var item = document.createElement('div');
|
||||
item.innerHTML = data.content;
|
||||
document.getElementById("liveblog-posts").insertBefore(
|
||||
item.children[0], document.getElementById("liveblog-posts").children[0]
|
||||
);
|
||||
}
|
||||
};
|
||||
// Helpful debugging
|
||||
socket.onopen = function () {
|
||||
console.log("Connected to notification socket");
|
||||
}
|
||||
socket.onclose = function () {
|
||||
console.log("Disconnected to notification socket");
|
||||
}
|
||||
});
|
||||
|
||||
}, false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue