From 3c4eebdd02fe24e79fcc0d1eb4c2a38efd754af7 Mon Sep 17 00:00:00 2001 From: Iacopo Spalletti Date: Sun, 5 Jun 2016 22:49:54 +0200 Subject: [PATCH] Remove jQuery dependency --- .../liveblog/static/liveblog/js/liveblog.js | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/djangocms_blog/liveblog/static/liveblog/js/liveblog.js b/djangocms_blog/liveblog/static/liveblog/js/liveblog.js index 1a2105f..3f7ff3a 100644 --- a/djangocms_blog/liveblog/static/liveblog/js/liveblog.js +++ b/djangocms_blog/liveblog/static/liveblog/js/liveblog.js @@ -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); +