-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
executable file
·198 lines (141 loc) · 5.06 KB
/
script.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var cachePortalData ={};
var xhr;
function generatePortalInfoContent(data){
var wrapp = $('<div>').addClass('portal_details');
var level = $('<span>').addClass("level_"+data.level).addClass('portal_level').html("L"+data.level);
var energyWrapp = $('<div>').addClass('energyWrapp');
var energyMax = $('<div>').addClass('energyMax');
if(data.controllingTeam == 'NEUTRAL'){
wrapp.append($('<span>').addClass("level_0").addClass('portal_level').html("NEUTRAL"));
return wrapp;
}
var energyTotal = $('<div>').addClass('energyTotal').addClass("bg_"+data.controllingTeam.toLowerCase()).
css({'width':((data.energy/data.energyMax)*100)+'%'});
energyMax.append(energyTotal);
energyWrapp.append(energyMax);
var energyTxt = $('<div>').addClass('energyTxt').html ("("+data.energy+"/"+data.energyMax+")");
energyWrapp.append(energyTxt);
var fact_icon = $('<div>').addClass('fact_icon').addClass(data.controllingTeam.toLowerCase());
var ownerTxt = $('<div>').addClass('owner').html('Owner ');
var portalOwner = $('<span>').addClass(data.controllingTeam.toLowerCase()).html(data.owner);
ownerTxt.append(portalOwner);
var infoTable = $('<table>').attr('cellspacing','0').attr('cellpadding',0).addClass('clear');
var modsRow = $('<tr>').addClass('mods');
for(i =0; i<data.mods.length;i++){
var elm = $('<td>').addClass('mod');
if(data.mods[i])
elm.html('<span class="'+data.mods[i].rarity.toLowerCase()+'"><img src="img/'+data.mods[i].type+'_'+data.mods[i].rarity.replace("_", "")+'.png" width="40" alt="'+data.mods[i].name+'" title="'+data.mods[i].name+'"/><br />'+data.mods[i].rarity.toLowerCase().replace('_', ' ')+'</span>');
else
elm.html('<br />none');
modsRow.append(elm);
}
infoTable.append(modsRow);
infoTable.append('<tr><td colspan="4">Resonators</td></tr>');
for(i =0; i<8;){
for(j=0; j<2;j++){
if(j==0){
var row = $("<tr>").addClass('resonators').addClass(data.controllingTeam.toLowerCase());
}
var owner = $('<td>').addClass('owner');
var res_energy = $('<td>').addClass('energy');
var res_energy_max = $('<div>').addClass('energy_max');
if(data.resonators[portalDistribution[i]]){
var resonator = data.resonators[portalDistribution[i]];
owner.html(resonator.owner);
var res_energy_total = $('<div>').addClass('energy_total').addClass('subtitle').addClass('bg_level_'+resonator.level).css({'width':((resonator.energyTotal/resonator.energyMax) *100 )+"%"});//.html("L"+resonator.level+" "+((resonator.energyTotal/resonator.energyMax) *100 )+"%");
var res_level = $('<span>').addClass('resonator_level').addClass('subtitle').html("L"+resonator.level);
var res_percent = $('<span>').addClass('resonator_percent').addClass('subtitle').html(Math.round((resonator.energyTotal/resonator.energyMax) *100 )+"%");
res_energy_max.append(res_energy_total,res_level,res_percent);
res_energy.append(res_energy_max);
}
res_energy.append(res_energy_max);
if(j==0){
row.append(owner);
row.append(res_energy);
} else {
row.append(res_energy);
row.append(owner);
infoTable.append(row);
}
i++;
}
}
wrapp.append(level);
wrapp.append(fact_icon);
wrapp.append(energyWrapp);
wrapp.append(ownerTxt);
wrapp.append(infoTable);
return wrapp;
}
function getPortalInfo(guid,timestamp, elm){
if(xhr)
xhr.abort();
if(typeof cachePortalData[guid] == 'undefined'){
xhr = $.ajax({
url: 'portalInfo.php',
type: 'POST',
async: true,
data:{
ajax: true,
guid: guid,
timestamp: timestamp
},
success: function(data,status){
try {
data = $.parseJSON(data);
} catch (e) {
elm.html($('<div class="error">Invalid response!</div>'));
return;
}
if(typeof data.error == 'undefined'){
elm.html( generatePortalInfoContent(data));
cachePortalData[guid] = data;
return;
} else {
elm.html( $('<div class="error">'+data.error+'</div>'));
return;
}
},
error: function(jqXHR, textStatus, errorThrown)
{
console.log(jqXHR + textStatus + errorThrown);
}
});
} else {
elm.html(generatePortalInfoContent(cachePortalData[guid]));
}
return;
}
var portalDistribution = {
0: 2,
1: 1,
2: 3,
3: 0,
4: 4,
5: 7,
6: 5,
7: 6
};
$(document).ready(function(){
try {
var $grid = Grid.init();
} catch(e){
}
$('.sorter').click(function(e){
$grid.closePreview();
if(!$(this).hasClass('active')){
$('.sorter.active').removeClass('active').children('span').html('');
$(this).addClass('active');
}
var sort_way = $(this).data('sortway');
var sort_by = $(this).data('sortby');
if(sort_way =='asc'){
$(this).data('sortway','desc').children('span').html('\u2191');
} else {
$(this).data('sortway','asc').children('span').html('\u2193');;
}
$("#og-grid li").tsort('a', {'attr':'data-'+sort_by,'order':sort_way});
$grid.updateItems();
return false;
});
});