All web code and ignore json files
This commit is contained in:
31
plebnet/assets/js/donate.js
Normal file
31
plebnet/assets/js/donate.js
Normal file
@ -0,0 +1,31 @@
|
||||
function onBTCPayFormSubmit(event) {
|
||||
sats = prompt("Choose an amount between 100 and 500000 sats", "2500");
|
||||
if (sats === null) {
|
||||
return;
|
||||
}
|
||||
if (sats < 100 || sats > 500000){
|
||||
alert("Invalid amount!");
|
||||
return;
|
||||
}
|
||||
amountBTC = sats * 0.00000001;
|
||||
|
||||
desc = prompt("Optionally enter a name", "Anonymous");
|
||||
if (desc === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.target[0].value = "Donation from " + desc;
|
||||
event.target[1].value = amountBTC;
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
if (this.status == 200 && this.responseText) {
|
||||
var response = JSON.parse(this.responseText);
|
||||
window.btcpay.showInvoice(response.invoiceId);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.open("POST", event.target.getAttribute('action'), true);
|
||||
xhttp.send(new FormData(event.target));
|
||||
}
|
102
plebnet/assets/js/find.js
Normal file
102
plebnet/assets/js/find.js
Normal file
@ -0,0 +1,102 @@
|
||||
function selectNode(nmb) {
|
||||
var id = lookup[nmb];
|
||||
$("#" + id).click();
|
||||
}
|
||||
|
||||
function autocomplete(inp, arr) {
|
||||
var currentFocus;
|
||||
var nodeNmb = [];
|
||||
inp.addEventListener("input", function(e) {
|
||||
nodeNmb = [];
|
||||
var a, b, i, val = this.value;
|
||||
closeAllLists();
|
||||
if (!val) { return false;}
|
||||
currentFocus = 0;
|
||||
a = document.createElement("DIV");
|
||||
a.setAttribute("id", this.id + "autocomplete-list");
|
||||
a.setAttribute("class", "autocomplete-items");
|
||||
this.parentNode.appendChild(a);
|
||||
for (i = 0; i < arr.length; i++) {
|
||||
for (j = 0; j <= (arr[i].length - val.length); j++) {
|
||||
if (arr[i].substr(j, val.length).toUpperCase() == val.toUpperCase()) {
|
||||
b = document.createElement("DIV");
|
||||
b.innerHTML = arr[i].substr(0, j);
|
||||
b.innerHTML += "<strong>" + arr[i].substr(j, val.length) + "</strong>";
|
||||
b.innerHTML += arr[i].substr(val.length+j);
|
||||
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
|
||||
b.innerHTML += "<input type='hidden' value='" + i + "'>";
|
||||
b.addEventListener("click", function(e) {
|
||||
inp.value = this.getElementsByTagName("input")[0].value;
|
||||
closeAllLists();
|
||||
selectNode(this.getElementsByTagName("input")[1].value);
|
||||
});
|
||||
if (a.children.length < 5) {
|
||||
a.appendChild(b);
|
||||
nodeNmb.push(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
var x = document.getElementById(this.id + "autocomplete-list");
|
||||
if (x) x = x.getElementsByTagName("div");
|
||||
addActive(x);
|
||||
});
|
||||
inp.addEventListener("keydown", function(e) {
|
||||
var x = document.getElementById(this.id + "autocomplete-list");
|
||||
if (x) x = x.getElementsByTagName("div");
|
||||
if (e.keyCode == 40) {
|
||||
/*If the arrow DOWN key*/
|
||||
currentFocus++;
|
||||
addActive(x);
|
||||
} else if (e.keyCode == 38) { //up
|
||||
/*If the arrow UP key*/
|
||||
currentFocus--;
|
||||
addActive(x);
|
||||
} else if (e.keyCode == 13) {
|
||||
/*If the ENTER key is pressed, prevent the form from being submitted,*/
|
||||
e.preventDefault();
|
||||
if (currentFocus > -1) {
|
||||
if (x) x[currentFocus].click();
|
||||
}
|
||||
this.blur()
|
||||
selectNode(nodeNmb[currentFocus]);
|
||||
}
|
||||
});
|
||||
function addActive(x) {
|
||||
if (!x) return false;
|
||||
removeActive(x);
|
||||
if (currentFocus >= x.length) currentFocus = 0;
|
||||
if (currentFocus < 0) currentFocus = (x.length - 1);
|
||||
x[currentFocus].classList.add("autocomplete-active");
|
||||
}
|
||||
function removeActive(x) {
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
x[i].classList.remove("autocomplete-active");
|
||||
}
|
||||
}
|
||||
function closeAllLists(elmnt) {
|
||||
var x = document.getElementsByClassName("autocomplete-items");
|
||||
for (var i = 0; i < x.length; i++) {
|
||||
if (elmnt != x[i] && elmnt != inp) {
|
||||
x[i].parentNode.removeChild(x[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener("click", function (e) {
|
||||
closeAllLists(e.target);
|
||||
});
|
||||
}
|
||||
|
||||
var nodes = []
|
||||
var lookup = []
|
||||
$.getJSON( "graphs/graph.json", function( graph ) {
|
||||
for(var node in graph["nodes"]) {
|
||||
nodes.push(graph["nodes"][node]["name"]);
|
||||
nodes.push(graph["nodes"][node]["id"]);
|
||||
lookup.push(graph["nodes"][node]["id"]);
|
||||
lookup.push(graph["nodes"][node]["id"]);
|
||||
}
|
||||
});
|
||||
|
||||
autocomplete(document.getElementById("nodeInput"), nodes);
|
95
plebnet/assets/js/graph.js
Normal file
95
plebnet/assets/js/graph.js
Normal file
@ -0,0 +1,95 @@
|
||||
function draw_graph(suffix) {
|
||||
var width = window.innerWidth;
|
||||
var height = window.innerHeight;
|
||||
|
||||
var fill = d3.scale.category20();
|
||||
|
||||
var graph_elem = document.getElementById("graph_svg");
|
||||
if (graph_elem) {
|
||||
graph_elem.remove();
|
||||
}
|
||||
|
||||
var svg = d3.select("#graph_container").append("svg")
|
||||
.attr("id", "graph_svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.attr("version", "1.1")
|
||||
.attr("xmlns", "http://www.w3.org/2000/svg")
|
||||
.attr("xmlns:xlink", "http://www.w3.org/1999/xlink")
|
||||
.call(d3.behavior.zoom().on("zoom", function () {
|
||||
svg.attr("transform", "scale(" + d3.event.scale + ")")
|
||||
}));
|
||||
|
||||
var force = d3.layout.force()
|
||||
.gravity(0.25)
|
||||
.charge(-1200)
|
||||
//.gravity(0)
|
||||
//.charge(0)
|
||||
.linkDistance(150)
|
||||
.size([width, height]);
|
||||
|
||||
var voronoi = d3.geom.voronoi()
|
||||
.x(function(d) { return d.x; })
|
||||
.y(function(d) { return d.y; })
|
||||
.clipExtent([[0, 0], [width, height]]);
|
||||
|
||||
d3.json("graphs/graph" + suffix + ".json", function(error, json) {
|
||||
if (error) throw error;
|
||||
|
||||
force
|
||||
.nodes(json.nodes)
|
||||
.links(json.links)
|
||||
.start();
|
||||
|
||||
var link = svg.selectAll(".link")
|
||||
.data(json.links)
|
||||
.enter().append("line")
|
||||
.attr("class", function(d) { return "link " + d.source.index + " " + d.target.index; });
|
||||
|
||||
var node = svg.selectAll(".node")
|
||||
.data(json.nodes)
|
||||
.enter().append("g")
|
||||
.attr("class", "node")
|
||||
.attr("id", function(d) { return d.id; })
|
||||
.style("text-shadow", function(d) { return "2px 2px 4px" + d.color; })
|
||||
.call(force.drag);
|
||||
|
||||
var circle = node.append("circle")
|
||||
.attr("r", 5)
|
||||
.style("stroke", function(d) { return d.color; })
|
||||
.attr("class", "circle");
|
||||
|
||||
var hov_circle = node.append("circle")
|
||||
.attr("r", 15)
|
||||
.attr("class", "cell")
|
||||
|
||||
var id_link = node.append("a")
|
||||
.attr("xlink:href", function(d) { return "https://amboss.space/node/" + d.id; })
|
||||
.attr("target", "_blank");
|
||||
|
||||
var label = id_link.append("text")
|
||||
.attr("dy", ".35em")
|
||||
.text(function(d) { return d.name; });
|
||||
|
||||
force.on("tick", function() {
|
||||
link
|
||||
.attr("x1", function(d) { return d.source.x; })
|
||||
.attr("y1", function(d) { return d.source.y; })
|
||||
.attr("x2", function(d) { return d.target.x; })
|
||||
.attr("y2", function(d) { return d.target.y; });
|
||||
|
||||
circle
|
||||
.attr("cx", function(d) { return d.x; })
|
||||
.attr("cy", function(d) { return d.y; });
|
||||
|
||||
hov_circle
|
||||
.attr("cx", function(d) { return d.x; })
|
||||
.attr("cy", function(d) { return d.y; });
|
||||
|
||||
label
|
||||
.attr("x", function(d) { return d.x + 8; })
|
||||
.attr("y", function(d) { return d.y; });
|
||||
});
|
||||
});
|
||||
}
|
||||
draw_graph("_full");
|
67
plebnet/assets/js/settings.js
Normal file
67
plebnet/assets/js/settings.js
Normal file
@ -0,0 +1,67 @@
|
||||
function setting1() {
|
||||
if($('#setting1').is(":checked")) {
|
||||
$("#graph_svg").addClass("show");
|
||||
} else {
|
||||
$("#graph_svg").removeClass("show");
|
||||
}
|
||||
}
|
||||
function setting1b() {
|
||||
if($('#setting1b').is(":checked")) {
|
||||
$("#graph_svg").addClass("enable1st");
|
||||
} else {
|
||||
$("#graph_svg").removeClass("enable1st");
|
||||
}
|
||||
}
|
||||
function setting1c() {
|
||||
if($('#setting1c').is(":checked")) {
|
||||
$("#graph_svg").addClass("enable2nd");
|
||||
} else {
|
||||
$("#graph_svg").removeClass("enable2nd");
|
||||
}
|
||||
}
|
||||
function setting2() {
|
||||
if($('#setting2').is(":checked")) {
|
||||
draw_graph("");
|
||||
} else {
|
||||
draw_graph("_full");
|
||||
}
|
||||
//reapply settings
|
||||
reinit();
|
||||
}
|
||||
|
||||
function init() {
|
||||
$( function(){
|
||||
setTimeout(() => {
|
||||
//Show all node names (change classes)
|
||||
$('#setting1').change(function(){
|
||||
setting1();
|
||||
});
|
||||
//Show 1st degree neighbours
|
||||
$('#setting1b').change(function(){
|
||||
setting1b();
|
||||
});
|
||||
//Show 2nd degree neighbours
|
||||
$('#setting1c').change(function(){
|
||||
setting1c();
|
||||
});
|
||||
|
||||
//show all channels (reload script with different graph.json)
|
||||
$('#setting2').change(function(){
|
||||
setting2();
|
||||
});
|
||||
reinit();
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
|
||||
function reinit() {
|
||||
$( function(){
|
||||
setTimeout(() => {
|
||||
setting1();
|
||||
setting1b();
|
||||
setting1c();
|
||||
neighbours();
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
init();
|
50
plebnet/assets/js/ui.js
Normal file
50
plebnet/assets/js/ui.js
Normal file
@ -0,0 +1,50 @@
|
||||
function neighbours() {
|
||||
var all_neighbours;
|
||||
var nodes = [];
|
||||
$.getJSON( "graphs/neighbours.json", function( data ) {
|
||||
all_neighbours = data;
|
||||
});
|
||||
$.getJSON( "graphs/graph_full.json", function( graph ) {
|
||||
for(var node in graph["nodes"]) {
|
||||
nodes.push(graph["nodes"][node]["id"]);
|
||||
}
|
||||
});
|
||||
|
||||
$(".node").click(function(){
|
||||
if ($(".selected")[0] != $(this)[0]) {
|
||||
$(".neighbour2nd").removeClass("neighbour2nd");
|
||||
$(".neighbour").removeClass("neighbour");
|
||||
$(".selected").removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
|
||||
$("#graph_svg").removeClass("enable1st");
|
||||
$("#graph_svg").removeClass("enable2nd");
|
||||
|
||||
let node = this.id;
|
||||
$("." + nodes.indexOf(node)).addClass("neighbour");
|
||||
for (var i = 0; i < all_neighbours[node].length; i++) {
|
||||
first_deg_neighbour = all_neighbours[node][i];
|
||||
$("#" + first_deg_neighbour).addClass("neighbour");
|
||||
$("." + nodes.indexOf(first_deg_neighbour)).addClass("neighbour2nd");
|
||||
|
||||
for (var j = 0; j < all_neighbours[first_deg_neighbour].length; j++) {
|
||||
second_deg_neighbour = all_neighbours[first_deg_neighbour][j];
|
||||
$("#" + second_deg_neighbour).addClass("neighbour2nd");
|
||||
}
|
||||
}
|
||||
var sleep = 400
|
||||
setTimeout(function(){
|
||||
setting1b();
|
||||
setTimeout(function(){
|
||||
setting1c();
|
||||
}, sleep);
|
||||
}, sleep);
|
||||
}
|
||||
});
|
||||
}
|
||||
function showSettings() {
|
||||
//spin cogwheel
|
||||
$("#settings").toggleClass("active");
|
||||
//Show settings menu
|
||||
$("#bar").toggleClass("visible");
|
||||
}
|
Reference in New Issue
Block a user