From 9ebc76e4e81179825e9fa9487aac362b3b7b40c1 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 16 May 2018 19:39:14 -0400 Subject: [PATCH] cite hover --- contrib/backends/srndv2/src/srnd/markup.go | 2 +- contrib/static/overchan.js | 84 ++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/contrib/backends/srndv2/src/srnd/markup.go b/contrib/backends/srndv2/src/srnd/markup.go index 92bb1f1..f475866 100644 --- a/contrib/backends/srndv2/src/srnd/markup.go +++ b/contrib/backends/srndv2/src/srnd/markup.go @@ -47,7 +47,7 @@ func backlink(word, prefix string) (markup string) { if len(parts) > 1 { longhash = parts[1] } - return `>>` + link + "" + return `>>` + link + "" } else { return escapeline(word) } diff --git a/contrib/static/overchan.js b/contrib/static/overchan.js index 6981f3d..efa1d54 100644 --- a/contrib/static/overchan.js +++ b/contrib/static/overchan.js @@ -184,6 +184,90 @@ onready(function(){ } }); +// inline reply expand +onready(function() { + + var fetchpost = function(url, cb) + { + var parts = url.split("#"); + var base = parts[0]; + var h = parts[1]; + var ajax = new XMLHttpRequest(); + ajax.onreadystatechange = function() + { + if(ajax.readyState == 4) + { + if(ajax.status == 200) + { + var j = JSON.parse(ajax.responseText); + for(var idx =0 ; idx < j.length; idx ++) + { + if (j[idx].HashLong == h) { + cb(j[idx]); + return; + } + } + cb(null); + } + else + { + cb(null); + } + } + }; + ajax.open("GET", base +"json"); + ajax.send(); + }; + + var showhover = function(parent, url, id) + { + fetchpost(url, function(post) { + var wrapper = document.createElement("div"); + var e = document.createElement("div"); + e.innerHTML = post.PostMarkup || "post not found" + wrapper.setAttribute('id', id); + wrapper.setAttribute("class", "hover"); + wrapper.appendChild(e); + var cl = document.createElement("div"); + cl.innerHTML = "[X]"; + cl.onclick = function() { + wrapper.remove(); + }; + wrapper.appendChild(cl); + parent.appendChild(wrapper); + }); + }; + + var hidehover = function(parent, id) + { + var hover = document.getElementById(id); + if(hover) hover.remove(); + }; + + var elems = document.getElementsByClassName("backlink"); + for(var idx = 0; idx < elems.length; idx ++) + { + var elem = elems[idx]; + var wrapper = document.createElement("div"); + elem.parentNode.insertBefore(wrapper, elem); + var el = elem.cloneNode(true); + elem.remove(); + elem = el; + var h = elem.href.split("#")[1]; + wrapper.appendChild(el); + var id = "hover_"+h; + + elem.onpointerenter = function() { + showhover(wrapper, elem.href, id); + }; + + elem.onpointerleave = function() + { + hidehover(wrapper, id); + }; + } +}); + // rewrite all images to add inline expand onready(function() {