/*
* implement this for IE6
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
* */
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun/*, thisArg*/) {
'use strict';
// if (this === void 0 || this === null) {
if (this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== 'function') {
throw new TypeError();
}
var res = [];
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
if (i in t) {
var val = t[i];
// NOTE: Technically this should Object.defineProperty at
// the next index, as push can be affected by
// properties on Object.prototype and Array.prototype.
// But that method's new, and collisions should be
// rare, so use the more-compatible alternative.
if (fun.call(thisArg, val, i, t)) {
res.push(val);
}
}
}
return res;
};
}
var gResults = null; // keep origin for filtering
var gResultsUsing = null;
var gPageIndex = 0;
var gTotalItems = 0;
var gTotalPages = 0;
var ITEMS_PER_PAGE = 10;
var gSorting = {
defaultSortByField: 'present_rate',
// low to high
present_rate: false,
win_rate: true
};
/*
Reference
- http://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects
*/
var sort_by = function (field, reverse, primer) {
var key = primer ?
function (x) {
return primer(x[field])
} :
function (x) {
return x[field]
};
reverse = [-1, 1][+!!reverse];
return function (a, b) {
return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
}
};
function updateTable() {
gTotalItems = gResultsUsing.length;
gTotalPages = Math.ceil(gTotalItems / ITEMS_PER_PAGE);
if (gResultsUsing.length) {
if (gPageIndex > (gTotalPages - 1)) {
return;
}
}
var output = '';
for (var i = 0; i < ITEMS_PER_PAGE; i++) {
var offset = i + gPageIndex * ITEMS_PER_PAGE;
var item = gResultsUsing[offset];
if (item) {
var firstColumn;
var championPresentRate = item.champion_present_rate;
var champion = championPresentRate.champion;
if (offset >= 0 && offset <= 2) {
firstColumn = '