backlinks sorta work
This commit is contained in:
parent
4a79b1c998
commit
57afa2ce4b
@ -68,6 +68,7 @@ function nntpchan_buildpost(parent, j) {
|
|||||||
if (j) {
|
if (j) {
|
||||||
// huehuehue
|
// huehuehue
|
||||||
post.innerHTML = j.PostMarkup;
|
post.innerHTML = j.PostMarkup;
|
||||||
|
inject_hover_for_element(post);
|
||||||
} else {
|
} else {
|
||||||
post.setAttribute("class", "notfound post");
|
post.setAttribute("class", "notfound post");
|
||||||
post.appendChild(document.createTextNode("post not found"));
|
post.appendChild(document.createTextNode("post not found"));
|
||||||
@ -78,21 +79,21 @@ function nntpchan_buildpost(parent, j) {
|
|||||||
// inject post hover behavior
|
// inject post hover behavior
|
||||||
function inject_hover(prefix, el, parent) {
|
function inject_hover(prefix, el, parent) {
|
||||||
if (!prefix) { throw "prefix is not defined"; }
|
if (!prefix) { throw "prefix is not defined"; }
|
||||||
console.log(el, parent);
|
var linkhash = el.getAttribute("backlinkhash");
|
||||||
var timeout;
|
if (!linkhash) { throw "linkhash undefined"; }
|
||||||
var idx = -2;
|
console.log("rewrite linkhash "+linkhash);
|
||||||
|
|
||||||
var linkhash = el.backlinkhash;
|
|
||||||
|
|
||||||
var elem = document.createElement("span");
|
var elem = document.createElement("span");
|
||||||
elem.setAttribute("class", "backlink_rewritten");
|
elem.setAttribute("class", "backlink_rewritten");
|
||||||
elem.appendChild(document.createTextNode(">>"+linkhash.substr(0,10)));
|
elem.appendChild(document.createTextNode(">>"+linkhash.substr(0,10)));
|
||||||
|
if (!parent) {
|
||||||
parent.appendChild(elem);
|
parent = el.parentNode;
|
||||||
|
}
|
||||||
parent.removeChild(el);
|
parent.removeChild(el);
|
||||||
|
parent.appendChild(elem);
|
||||||
|
|
||||||
elem.onclick = function(ev) {
|
elem.onclick = function(ev) {
|
||||||
if(elem.backlink) {
|
if(parent.backlink) {
|
||||||
nntpchan_apicall(prefix+"api/find?hash="+linkhash, function(j) {
|
nntpchan_apicall(prefix+"api/find?hash="+linkhash, function(j) {
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
wrapper.setAttribute("class", "hover "+linkhash);
|
wrapper.setAttribute("class", "hover "+linkhash);
|
||||||
@ -103,14 +104,14 @@ function inject_hover(prefix, el, parent) {
|
|||||||
// wrap backlink
|
// wrap backlink
|
||||||
nntpchan_buildpost(wrapper, j);
|
nntpchan_buildpost(wrapper, j);
|
||||||
}
|
}
|
||||||
elem.appendChild(wrapper);
|
parent.appendChild(wrapper);
|
||||||
elem.backlink = false;
|
parent.backlink = false;
|
||||||
}, function(msg) {
|
}, function(msg) {
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
wrapper.setAttribute("class", "hover "+linkhash);
|
wrapper.setAttribute("class", "hover "+linkhash);
|
||||||
wrapper.appendChild(document.createTextNode(msg));
|
wrapper.appendChild(document.createTextNode(msg));
|
||||||
elem.appendChild(wrapper);
|
parent.appendChild(wrapper);
|
||||||
elem.backlink = false;
|
parent.backlink = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var elems = document.getElementsByClassName(linkhash);
|
var elems = document.getElementsByClassName(linkhash);
|
||||||
@ -118,10 +119,10 @@ function inject_hover(prefix, el, parent) {
|
|||||||
for (var idx = 0 ; idx < elems.length; idx ++ ) {
|
for (var idx = 0 ; idx < elems.length; idx ++ ) {
|
||||||
elems[idx].parentNode.removeChild(elems[idx]);
|
elems[idx].parentNode.removeChild(elems[idx]);
|
||||||
}
|
}
|
||||||
elem.backlink = true;
|
parent.backlink = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
elem.backlink = true;
|
parent.backlink = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function livechan_got_post(widget, j) {
|
function livechan_got_post(widget, j) {
|
||||||
@ -202,14 +203,23 @@ function nntpchan_inject_banners(elem, prefix) {
|
|||||||
elem.appendChild(e);
|
elem.appendChild(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inject post hover for all backlinks in an element
|
||||||
|
function inject_hover_for_element(elem) {
|
||||||
|
var elems = elem.getElementsByClassName("backlink");
|
||||||
|
var ls = [];
|
||||||
|
var l = elems.length;
|
||||||
|
for ( var idx = 0 ; idx < l ; idx ++ ) {
|
||||||
|
var e = elems[idx];
|
||||||
|
ls.push(e);
|
||||||
|
}
|
||||||
|
for( var elem in ls ) {
|
||||||
|
inject_hover(prefix, ls[elem]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function init(prefix) {
|
function init(prefix) {
|
||||||
// inject posthover ...
|
// inject posthover ...
|
||||||
var elems = document.getElementsByClassName("backlink");
|
inject_hover_for_element(document);
|
||||||
// ... for backlinks
|
|
||||||
for ( var idx = 0 ; idx < elems.length ; idx ++ ) {
|
|
||||||
// uncomment to do reply hover
|
|
||||||
//inject_hover(prefix, elems[idx], elems[idx].parentNode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply themes
|
// apply themes
|
||||||
|
@ -17,6 +17,13 @@ section {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hover {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hover > div > .post {
|
||||||
|
box-shadow: 0 0 10px rgba(0,0,0,0.55);
|
||||||
|
}
|
||||||
|
|
||||||
.frontend , .subject, .catalog_subject {
|
.frontend , .subject, .catalog_subject {
|
||||||
color: #0F0C5D;
|
color: #0F0C5D;
|
||||||
@ -279,6 +286,10 @@ input, textarea {
|
|||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post:focus {
|
||||||
|
background-color: #A99AFF;
|
||||||
|
}
|
||||||
|
|
||||||
.post {
|
.post {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
min-width: 500px;
|
min-width: 500px;
|
||||||
|
Reference in New Issue
Block a user