searxng.head.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * @license
  3. * (C) Copyright Contributors to the SearXNG project.
  4. * (C) Copyright Contributors to the searx project (2014 - 2021).
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. /* global DocumentTouch:readonly */
  8. (function(w, d) {
  9. 'use strict';
  10. // add data- properties
  11. var script = d.currentScript || (function() {
  12. var scripts = d.getElementsByTagName('script');
  13. return scripts[scripts.length - 1];
  14. })();
  15. // try to detect touch screen
  16. w.searxng = {
  17. touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false,
  18. method: script.getAttribute('data-method'),
  19. autocompleter: script.getAttribute('data-autocompleter') === 'true',
  20. search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
  21. infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
  22. hotkeys: script.getAttribute('data-hotkeys') === 'true',
  23. static_path: script.getAttribute('data-static-path'),
  24. translations: JSON.parse(script.getAttribute('data-translations')),
  25. theme : {
  26. // image that is displayed if load of <img src='...'> failed
  27. img_load_error: 'img/img_load_error.svg'
  28. }
  29. };
  30. // update the css
  31. var hmtlElement = d.getElementsByTagName("html")[0];
  32. hmtlElement.classList.remove('no-js');
  33. hmtlElement.classList.add('js');
  34. if (w.searxng.touch) {
  35. hmtlElement.classList.add('touch');
  36. }
  37. })(window, document);