PageRenderTime 43ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/share/spice/bootic/bootic.js

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 52 lines | 46 code | 5 blank | 1 comment | 3 complexity | 02fb8b3935847c88b2ae7e6aff5863d7 MD5 | raw file
Possible License(s): Apache-2.0
  1. (function(env) {
  2. "use strict";
  3. env.ddg_spice_bootic = function(api_result) {
  4. if (!api_result || $.isEmptyObject(api_result.products)) {
  5. return Spice.failed('bootic');
  6. }
  7. var query = api_result.input_query ?
  8. '?initial=1&q=' + encodeURIComponent(api_result.input_query) : '';
  9. // TODO: Use sorting block for this!
  10. var result = [];
  11. for(var i = 0; i < api_result.sorted.length; i++) {
  12. result.push(api_result.products[api_result.sorted[i]]);
  13. }
  14. Spice.add({
  15. id: 'bootic',
  16. name: 'Products',
  17. data: result,
  18. meta: {
  19. sourceName: 'Bootic',
  20. sourceUrl: 'http://www.bootic.com/?q=' + query,
  21. sourceIcon: true,
  22. itemType: 'Bootic ' + l('Results'),
  23. searchTerm: api_result.input_query
  24. },
  25. normalize: function(o) {
  26. var picture = o.pictures[0];
  27. picture.replace(/_pictures\/\d+x\d+/, "_pictures/200x300");
  28. picture = "http://static.bootic.com/_pictures/" + picture;
  29. return {
  30. parentId: o.id,
  31. url: "http://bootic.com" + o.url,
  32. img: picture,
  33. title: o.name,
  34. heading: o.name,
  35. brand: o.shop_name,
  36. price: "$" + o.price
  37. };
  38. },
  39. templates: {
  40. item: 'products_item',
  41. options: {
  42. rating:false
  43. }
  44. }
  45. });
  46. };
  47. }(this));