PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 72 lines | 63 code | 5 blank | 4 comment | 8 complexity | f97b5cc62e2c9ad662f03157bbf9431d MD5 | raw file
Possible License(s): Apache-2.0
  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. sourceName: "AstroBin",
  26. sourceUrl: "http://www.astrobin.com/" + api_result.id
  27. },
  28. normalize: function(item) {
  29. if(!item.title) {
  30. item.title = "Astronomy picture of the Day";
  31. }
  32. var boxData;
  33. if (item.imaging_telescopes || item.imaging_cameras) {
  34. boxData = [{heading: 'Imaging Info:'}];
  35. boxData.push({
  36. label: "Size: " + item.w + " x " + item.h
  37. });
  38. if(item.subjects.length) {
  39. boxData.push({
  40. label: "Subjects: " + item.subjects
  41. });
  42. }
  43. if(item.imaging_telescopes.length) {
  44. boxData.push({
  45. label: "Telescopes: " + item.imaging_telescopes
  46. });
  47. }
  48. if(item.imaging_cameras.length) {
  49. boxData.push({
  50. label: "Cameras: " + item.imaging_cameras
  51. });
  52. }
  53. }
  54. return {
  55. image: item.url_duckduckgo,
  56. title: item.title,
  57. url: "http://www.astrobin.com/" + item.id,
  58. infoboxData: boxData,
  59. description: DDG.strip_html(item.description)
  60. };
  61. },
  62. templates: {
  63. group: 'info'
  64. },
  65. });
  66. };
  67. }(this));