forked from linkeddata/rdflib.js
/
getFriendsRequire.html
92 lines (78 loc) · 3.16 KB
/
getFriendsRequire.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.js"></script>
</head>
<body>
<script>
require.config({
paths: {
"jquery": "http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery",
"underscore":"http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min",
"q": "http://cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q",
"rdflib": "../../releases/0.1.1/rdflib-stample-0.1.1",
"rdflib-pg-extension": "../../releases/0.1.1/rdflib-stample-pg-extension-0.1.1"
},
shim: {
"jquery": {
exports: '$'
},
"underscore": {
"exports":"_"
},
"rdflib-pg-extension": {
"deps": ["rdflib","jquery","underscore","q"],
"exports":"$rdf.PG"
}
}
});
require(
[
"jquery",
"underscore",
"q",
"rdflib",
"rdflib-pg-extension",
],
function ($, _, Q, rdflib, rdflibPg) {
// make Q globally available because it's not when loading it with require
// and global Q variable is needed by the fetcher :(
window.Q = Q;
var FOAF = $rdf.Namespace("http://xmlns.com/foaf/0.1/");
$rdf.Fetcher.fetcherWithPromiseCrossSiteProxyTemplate = "https://www.stample.io/srv/cors?url=";
//$rdf.Fetcher.fetcherWithPromiseCrossSiteProxyTemplate = "http://data.fm/proxy?uri=";
var fetcherTimeout = 3000;
var store = rdflibPg.createNewStore(fetcherTimeout);
var henryFoafProfileUrl = "http://bblfish.net/people/henry/card#me";
var friendCounter=0;
store.fetcher.fetch(henryFoafProfileUrl)
.then(function(henryPg) {
printPersonFriendNames(henryPg);
});
function printPersonFriendNames(personPg) {
var localFriendPgs = personPg.rel( FOAF("knows") );
_.each(localFriendPgs, function(localFriendPg) {
jumpAndPrintName(localFriendPg);
});
}
function jumpAndPrintName(localFriendPg) {
localFriendPg.jumpAsync()
.then(function(remoteFriendPg) {
var friendName = remoteFriendPg.relFirst(FOAF("name")).pointer.toString();;
$("#friendList").append("<li>"+friendName+"</li>")
friendCounter++;
$("#counter").html(friendCounter);
}).fail(function (jumpError) {
console.warn("Error during jump from ",localFriendPg.printSummary(),jumpError);
});
}
}
);
</script>
<div>
<h3>Nb friends = <span id="counter"/>0</h3>
<ul id="friendList"/>
</div>
</body>
</html>