-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsix-degs-app.js
67 lines (57 loc) · 1.69 KB
/
six-degs-app.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
Polymer('six-degs-app', {
showTeams: true,
getSourceValue: function() {
return this.$.source.value;
},
getDestValue: function() {
return this.$.dest.value;
},
getPath: function() {
this.$.ajax.body = "source="+this.getSourceValue()+"&dest="+this.getDestValue();
this.$.ajax.go();
},
substringMatcher: function(strs) {
return function findMatches(q, cb) {
var matches, substrRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q, 'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`, add it to the `matches` array
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
// the typeahead jQuery plugin expects suggestions to a
// JavaScript object, refer to typeahead docs for more info
matches.push({ value: str });
}
});
cb(matches);
};
},
ready: function() {
$.getJSON('player-names.json')
.done(function(data) {
$('html /deep/ #source').typeahead({
hint: false,
highlight: true,
minLength: 1
},
{
name: 'players',
displayKey: 'value',
source: this.substringMatcher(data)
});
$('html /deep/ #dest').typeahead({
hint: false,
highlight: true,
minLength: 1
},
{
name: 'players',
displayKey: 'value',
source: this.substringMatcher(data)
});
}.bind(this));
}
});