scripts.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. _ _ _
  3. | |__ ___ ___ | |_ ___| |_ _ __ __ ___ __
  4. | '_ \ / _ \ / _ \| __/ __| __| '__/ _` \ \/ /
  5. | |_) | (_) | (_) | |_\__ | |_| | | (_| |> <
  6. |_.__/ \___/ \___/ \__|___/\__|_| \__,_/_/\_\.js
  7. */
  8. if(searx.autocompleter) {
  9. searx.searchResults = new Bloodhound({
  10. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  11. queryTokenizer: Bloodhound.tokenizers.whitespace,
  12. remote: '/autocompleter?q=%QUERY'
  13. });
  14. searx.searchResults.initialize();
  15. }
  16. $(document).ready(function(){
  17. $('.btn-toggle .btn').click(function() {
  18. var btnClass = 'btn-' + $(this).data('btn-class');
  19. var btnLabelDefault = $(this).data('btn-label-default');
  20. var btnLabelToggled = $(this).data('btn-label-toggled');
  21. if(btnLabelToggled != '') {
  22. if($(this).hasClass('btn-default')) {
  23. var html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
  24. } else {
  25. var html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
  26. }
  27. $(this).html(html);
  28. }
  29. $(this).toggleClass(btnClass);
  30. $(this).toggleClass('btn-default');
  31. });
  32. $('.btn-collapse').click(function() {
  33. var btnTextCollapsed = $(this).data('btn-text-collapsed');
  34. var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
  35. if(btnTextCollapsed != '' && btnTextNotCollapsed != '') {
  36. if($(this).hasClass('collapsed')) {
  37. var html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
  38. } else {
  39. var html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
  40. }
  41. $(this).html(html);
  42. }
  43. });
  44. $(".select-all-on-click").click(function () {
  45. $(this).select();
  46. });
  47. if(searx.autocompleter) {
  48. $('#q').typeahead(null, {
  49. name: 'search-results',
  50. displayKey: function(result) {
  51. return result;
  52. },
  53. source: searx.searchResults.ttAdapter()
  54. });
  55. }
  56. });