summaryrefslogtreecommitdiffstats
path: root/web/static/js/common.js
blob: 9d1451f1abb74c5ee37ea0d4f376dcd992e254de (plain)
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
(function() {
	var locale_options = false;
	try {
		(0).toLocaleString('i');
	} catch (e) { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Example:_Checking_for_support_for_locales_and_options_arguments
		locale_options = e.name == 'RangeError';
	}
	Object.append(window.ykill, {
		'api': function(path, cb) {
			new Request.JSON({
				'url': ykill.api_host + path,
				'onSuccess': cb,
				'onFailure': function(xhr) {
					$('wrapper').empty().grab(new Element('div', {
						'class': 'error',
						'html': 'as you pass through the wormhole you realize that it collapses behind you.' +
							'<br>have you become trapped?'
					}));
				},
			}).get();
		},

		'portrait': function(id, text, img_dir, img_suffix) {
			var img = new Element('img', {
				'src': '//image.eveonline.com/' + img_dir + '/' + id + img_suffix,
				'alt': text,
			});
			return img;
		},

		'format_isk': function(isk) {
			isk /= 100;
			if (!locale_options)
				return parseFloat(isk.toFixed(0)).toLocaleString();
			return isk.toLocaleString('en-US', {'maximumFractionDigits': 0});
		},
		'format_millions': function(isk) {
			isk /= 100 * 1000 * 1000;
			if (!locale_options)
				return parseFloat(isk.toFixed(2)).toLocaleString();
			return isk.toLocaleString('en-US', {'minimumFractionDigits': 2, 'maximumFractionDigits': 2});
		},
		'format_billions': function(isk) {
			return ykill.format_millions(isk / 1000);
		},

		'format_system': function(system, security, security_status) {
			if (security_status == '?') // placeholder for w-space
				security = '?';
			else
				security = security.toFixed(1);
			return system + ' <span class="' + security_status + '">' + security + '</span>';
		}
	});
})();