(seen)
| 98 | } |
| 99 | |
| 100 | function processSeen (seen) { |
| 101 | var i |
| 102 | var total = seen.total |
| 103 | var shown = [] |
| 104 | |
| 105 | seen.pokemon.sort(function (a, b) { |
| 106 | var sort = document.getElementById('sort') |
| 107 | var order = document.getElementById('order') |
| 108 | |
| 109 | if (order.options[order.selectedIndex].value === 'desc') { |
| 110 | var tmp = b |
| 111 | b = a |
| 112 | a = tmp |
| 113 | } |
| 114 | |
| 115 | if (sort.options[sort.selectedIndex].value === 'id') { |
| 116 | return a['pokemon_id'] - b['pokemon_id'] |
| 117 | } else if (sort.options[sort.selectedIndex].value === 'name') { |
| 118 | if (a['pokemon_name'].toLowerCase() < b['pokemon_name'].toLowerCase()) { |
| 119 | return 1 |
| 120 | } |
| 121 | if (a['pokemon_name'].toLowerCase() > b['pokemon_name'].toLowerCase()) { |
| 122 | return -1 |
| 123 | } |
| 124 | return 0 |
| 125 | } else { |
| 126 | // Default to count |
| 127 | if (a['count'] === b['count']) { // Same count: order by id |
| 128 | return b['pokemon_id'] - a['pokemon_id'] |
| 129 | } |
| 130 | return a['count'] - b['count'] |
| 131 | } |
| 132 | }) |
| 133 | |
| 134 | for (i = seen.pokemon.length - 1; i >= 0; i--) { |
| 135 | var item = seen.pokemon[i] |
| 136 | var percentage = (item['count'] / total * 100).toFixed(4) |
| 137 | var lastSeen = new Date(item['disappear_time']) |
| 138 | lastSeen = lastSeen.getHours() + ':' + |
| 139 | ('0' + lastSeen.getMinutes()).slice(-2) + ':' + |
| 140 | ('0' + lastSeen.getSeconds()).slice(-2) + ' ' + |
| 141 | lastSeen.getDate() + ' ' + |
| 142 | monthArray[lastSeen.getMonth()] + ' ' + |
| 143 | lastSeen.getFullYear() |
| 144 | var location = (item['latitude'] * 1).toFixed(7) + ', ' + (item['longitude'] * 1).toFixed(7) |
| 145 | if (!$('#seen_' + item['pokemon_id']).length) { |
| 146 | addElement(item['pokemon_id'], item['pokemon_name']) |
| 147 | } |
| 148 | $('#count_' + item['pokemon_id']).html('<strong>Seen:</strong> ' + item['count'].toLocaleString() + ' (' + percentage + '%)') |
| 149 | $('#lastseen_' + item['pokemon_id']).html('<strong>Last Seen:</strong> ' + lastSeen) |
| 150 | $('#location_' + item['pokemon_id']).html('<strong>Location:</strong> ' + location) |
| 151 | $('#seen_' + item['pokemon_id']).show() |
| 152 | // Reverting to classic javascript here as it's supposed to increase performance |
| 153 | document.getElementById('seen_container').insertBefore(document.getElementById('seen_' + item['pokemon_id']), document.getElementById('seen_container').childNodes[0]) |
| 154 | shown.push(item['pokemon_id']) |
| 155 | } |
| 156 | |
| 157 | // Hide any unneeded items |
no test coverage detected