/share/spice/astrobin/apod/astrobin_apod.js

https://github.com/pardocz/zeroclickinfo-spice · JavaScript · 73 lines · 64 code · 5 blank · 4 comment · 8 complexity · 2fb1546159eef66c4ef1cc94c83f4885 MD5 · raw file

  1. (function(env) {
  2. "use strict";
  3. // Prevent jQuery from appending "_={timestamp}" in our url when we use $.getScript.
  4. // If cache was set to false, it would be calling /js/spice/hackage/packages/hello?_=12345
  5. // and that's something that we don't want.
  6. $.ajaxSetup({ cache: true });
  7. // Fetch our json and pass to getScript
  8. env.ddg_spice_astrobin_apod = function(api_result) {
  9. if(!api_result) {
  10. return Spice.failed('apod');
  11. }
  12. var getimageid = api_result.objects[0].image.split("/");
  13. $.getScript("/js/spice/astrobin/fetch_id/" + getimageid[4]);
  14. };
  15. env.ddg_spice_astrobin_fetch_id = function(api_result) {
  16. if (!api_result) {
  17. return Spice.failed('apod');
  18. }
  19. Spice.add({
  20. id: "apod",
  21. name: "Astronomy",
  22. data: api_result,
  23. signal: 'high',
  24. meta: {
  25. itemType: "Astrophoto",
  26. sourceName: "AstroBin",
  27. sourceUrl: "http://www.astrobin.com/" + api_result.id
  28. },
  29. normalize: function(item) {
  30. if(!item.title) {
  31. item.title = "Astronomy picture of the Day";
  32. }
  33. var boxData;
  34. if (item.imaging_telescopes || item.imaging_cameras) {
  35. boxData = [{heading: 'Imaging Info:'}];
  36. boxData.push({
  37. label: "Size: " + item.w + " x " + item.h
  38. });
  39. if(item.subjects.length) {
  40. boxData.push({
  41. label: "Subjects: " + item.subjects
  42. });
  43. }
  44. if(item.imaging_telescopes.length) {
  45. boxData.push({
  46. label: "Telescopes: " + item.imaging_telescopes
  47. });
  48. }
  49. if(item.imaging_cameras.length) {
  50. boxData.push({
  51. label: "Cameras: " + item.imaging_cameras
  52. });
  53. }
  54. }
  55. return {
  56. image: item.url_duckduckgo,
  57. title: item.title,
  58. url: "http://www.astrobin.com/" + item.id,
  59. infoboxData: boxData,
  60. description: DDG.strip_html(item.description)
  61. };
  62. },
  63. templates: {
  64. group: 'info'
  65. },
  66. });
  67. };
  68. }(this));