-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.js
71 lines (62 loc) · 2.11 KB
/
result.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Created by benjaminmeeder on 11/22/16.
*/
$( document ).ready(function() {
main();
});
function main() {
var title = getParameterByName('title');
$('#head').text('Path from ' + title + ' to Hitler');
$.ajax({
url: 'neo4jConnect.php',
data: {title:title},
success: function (data) {
var input = JSON.parse(data);
$(".spinner").remove();
if(input.length == 0) {
$('#cta').after('<section id="intro" class="main"><h2>No Path Found!</h2></section>');
return;
}
var pathCards = [];
for(var i = input.length-1; i>-1; i--) {
var nodeTitle = input[i];
pathCards.push(new PathCard(nodeTitle));
}
},
error: function() {
$(".spinner").remove();
$('#cta').after('<section id="intro" class="main"><h2>Error no article found<br>Try new search</h2></section>');
}
});
}
function getParameterByName(name) {
var url = document.location;
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
class PathCard {
constructor(title) {
this.title = title;
this.url = this.getURLByArticleName();
this.render();
}
getURLByArticleName() {
//this.title ajax REST api query to WIKIPEDIA
return 'https://en.wikipedia.org/wiki/' + this.title;
}
render() {
var card = '<section id="intro" class="main"> <h2>' + this.title + '</h2> <ul class="actions"> <li><a target="_blank" href="' + this.url + '" class="button big">Link to Article</a></li></ul> </section>';
if(this.title != "Adolf Hitler") {
card += '<div style="text-align: center;" class="icon fa-link fa-3x"></div>';
}
var cardNode = $.parseHTML(card);
$('#cta').after(cardNode);
}
}