From 02d1697b2bad40cffc0f6f8d9f88e9d2513ac7bb Mon Sep 17 00:00:00 2001 From: Niko Bews Date: Thu, 12 May 2016 02:52:15 +0300 Subject: [PATCH] Fix: Auto-expand content in old messages too. --- client/js/shout.js | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/client/js/shout.js b/client/js/shout.js index 0e8e427a..32ae9cae 100644 --- a/client/js/shout.js +++ b/client/js/shout.js @@ -274,6 +274,11 @@ $(function() { function renderChannelMessages(data) { var documentFragment = buildChannelMessages(data.id, data.messages); chat.find("#chan-" + data.id + " .messages").append(documentFragment); + data.messages.forEach(function(e) { + if (e.type === "toggle" && e.toggle !== undefined) { + showToggle(e.toggle, false); + } + }); } socket.on("msg", function(data) { @@ -297,6 +302,11 @@ $(function() { if (data.messages.length !== 100) { chan.find(".show-more").removeClass("show"); } + data.messages.forEach(function(e) { + if (e.type === "toggle" && e.toggle !== undefined) { + showToggle(e.toggle, false); + } + }); }); socket.on("network", function(data) { @@ -371,21 +381,7 @@ $(function() { }); socket.on("toggle", function(data) { - var toggle = $("#toggle-" + data.id); - toggle.parent().after(render("toggle", {toggle: data})); - switch (data.type) { - case "link": - if (options.links) { - toggle.click(); - } - break; - - case "image": - if (options.thumbnails) { - toggle.click(); - } - break; - } + showToggle(data, true); }); socket.on("topic", function(data) { @@ -953,6 +949,26 @@ $(function() { return array; } + function showToggle(data, renderNeeded) { + var toggle = $("#toggle-" + data.id); + if (renderNeeded) { + toggle.parent().after(render("toggle", {toggle: data})); + } + switch (data.type) { + case "link": + if (options.links) { + toggle.click(); + } + break; + + case "image": + if (options.thumbnails) { + toggle.click(); + } + break; + } + } + document.addEventListener( "visibilitychange", function() {