PageRenderTime 1198ms CodeModel.GetById 11ms RepoModel.GetById 4ms app.codeStats 0ms

/share/spice/bible/bible.js

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 47 lines | 40 code | 5 blank | 2 comment | 3 complexity | 0dd901d3b7148335507a3b9cb20d4398 MD5 | raw file
Possible License(s): Apache-2.0
  1. (function(env) {
  2. "use strict";
  3. env.ddg_spice_bible = function(api_result) {
  4. // Validity check
  5. if (!api_result || !api_result.length){
  6. return Spice.failed('bible');
  7. }
  8. var result = api_result[0],
  9. source_url = "https://net.bible.org/#!bible/" + DDG.get_query();
  10. Spice.add({
  11. id: 'bible',
  12. name: 'Answer',
  13. data: result,
  14. meta: {
  15. sourceName: 'Bible',
  16. sourceUrl: source_url,
  17. sourceIconUrl: 'http://bible.org/sites/bible.org/files/borg6_favicon.ico'
  18. },
  19. templates: {
  20. group: 'text',
  21. options: {
  22. content: Spice.bible.content,
  23. moreAt: true
  24. }
  25. },
  26. normalize: function(item){
  27. // text come with a link at the end that needs to be removed
  28. var text = $('<span />').html(item.text).text(),
  29. subtitle = (item.title) ? $('<span />').html(item.title).text() : '',
  30. text = $.trim(DDG.strip_html(text).replace('©NET', '').replace(/(|)/g, '').replace('[[EMPTY]]', ''));
  31. if (!text) {
  32. return Spice.failed('bible');
  33. }
  34. return {
  35. title: item.bookname + ' ' + item.chapter + ':' + item.verse,
  36. subtitle: subtitle,
  37. text: text
  38. };
  39. }
  40. });
  41. }
  42. }(this));