-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.js
114 lines (103 loc) · 3.27 KB
/
basic.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*eslint-env browser, jquery, meteor*/
$(document).ready(function(){
$("#basicTst").on("click",function(){
getAllChampions();
});
$("#getSummoner").on("click",function(){
$("#summonerTable").empty();
$("#summonerTable").append("<tr><th>Match Type</th><th>Match Stats</th></tr>");
var summonerName = $("#summonerName").val();
getBasicSummonerInfoBasic(summonerName);
});
$("#summonerName").on('keypress',function(e){
if(e.keyCode === 13){
$("#getSummoner").trigger('click');
}
});
});
function getAllChampions(){
var base = "https://na.api.pvp.net/api/lol/static-data/na/v1.2/champion?champData=image";
$.ajax({
type : "GET",
url : base + key,
success : function(result){
var sorted = _.sortBy(result.data,'id');
_.each(sorted, function(champ){
createTableRowForChamp(champ, result.version);
});
}
});
}
function createTableRowForChamp(champ, version){
var id = champ.id;
var key = champ.key;
var champName = champ.name;
var title = champ.title;
var ver = version;
var thumbnail = champ.image.full;
var row = "<tr><td><img style='height:50px;width:50px' src='http://ddragon.leagueoflegends.com/cdn/"+ver+"/img/champion/"+thumbnail+"'></td>"+
"<td class=id>"+id+"</td>"+
"<td class=key>"+key+"</td>"+
"<td class=name>"+champName+"</td>"+
"<td class=title>"+title+"</td>"+
+"</tr>";
$("#championTable").append(row);
}
function getBasicSummonerInfoBasic(summonerName){
var base = "https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/";
$.ajax({
type : "GET",
url : base + summonerName + key,
success : function(result){
$("#errorfetchingSummoner").hide();
var keyMap = summonerName.toLowerCase();
if(result != undefined){
getStatsForSummoner(result[keyMap].id);
}else{
$("#errorfetchingSummoner").show().text("No Summoner found for search key.");
}
},
error : function(){
$("#errorfetchingSummoner").show().text("Invalid Summoner name: "+summonerName);
}
});
}
function getStatsForSummoner(sId){
var base = "https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/"+sId+"/summary?season=SEASON2015";
$.ajax({
type : "GET",
url : base + key,
success : function(result){
$("#errorfetchingSummoner").hide();
if(result.playerStatSummaries != undefined){
_.each(result.playerStatSummaries, function(match){
var type = match.playerStatSummaryType;
var aggStats = match.aggregatedStats;
createStatsTable(aggStats,type);
});
}else{
$("#errorfetchingSummoner").show().text("No information found.");
}
},
error : function(){
$("#errorfetchingSummoner").show().text("Invalid Summoner ID: "+sId);
}
});
}
function createStatsTable(stats,type){
var pairsOfStats = _.pairs(stats);
var statsTable = "<table><tbody style='display: block;max-height:100px; overflow-y: auto; width:280px'>";
if(pairsOfStats.length > 0){
statsTable += "<tr><th>Stat</th><th>Value</th></tr>";
_.each(pairsOfStats, function(at){
statsTable += "<tr><td>"+at[0]+"</td><td>"+at[1]+"</td></tr>";
});
}else{
statsTable += "<tr>No Data</tr>";
}
statsTable + "</tbody></table>";
$("#summonerTable").append("<tr>"+
"<td>"+type+"</td>"+
"<td>"+statsTable+"</td>"+
"</tr>");
}