common.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function() {
  2. var locale_options = false;
  3. try {
  4. (0).toLocaleString('i');
  5. } 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
  6. locale_options = e.name == 'RangeError';
  7. }
  8. Object.append(window.ykill, {
  9. 'api': function(path, cb) {
  10. new Request.JSON({
  11. 'url': ykill.api_host + path,
  12. 'onSuccess': cb,
  13. 'onFailure': function(xhr) {
  14. $('wrapper').empty().grab(new Element('div', {
  15. 'class': 'error',
  16. 'html': 'as you pass through the wormhole you realize that it collapses behind you.' +
  17. '<br>have you become trapped?'
  18. }));
  19. },
  20. }).get();
  21. },
  22. 'portrait': function(id, text, img_dir, img_suffix) {
  23. var img = new Element('img', {
  24. 'src': '//image.eveonline.com/' + img_dir + '/' + id + img_suffix,
  25. 'alt': text,
  26. });
  27. return img;
  28. },
  29. 'format_isk': function(isk) {
  30. isk /= 100;
  31. if (!locale_options)
  32. return parseFloat(isk.toFixed(0)).toLocaleString();
  33. return isk.toLocaleString('en-US', {'maximumFractionDigits': 0});
  34. },
  35. 'format_millions': function(isk) {
  36. isk /= 100 * 1000 * 1000;
  37. if (!locale_options)
  38. return parseFloat(isk.toFixed(2)).toLocaleString();
  39. return isk.toLocaleString('en-US', {'minimumFractionDigits': 2, 'maximumFractionDigits': 2});
  40. },
  41. 'format_billions': function(isk) {
  42. return ykill.format_millions(isk / 1000);
  43. },
  44. 'format_system': function(system, security, security_status) {
  45. if (security_status == '?') // placeholder for w-space
  46. security = '?';
  47. else
  48. security = security.toFixed(1);
  49. return system + ' <span class="' + security_status + '">' + security + '</span>';
  50. }
  51. });
  52. })();