searxng.head.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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. };
  26. // update the css
  27. var hmtlElement = d.getElementsByTagName("html")[0];
  28. hmtlElement.classList.remove('no-js');
  29. hmtlElement.classList.add('js');
  30. if (w.searxng.touch) {
  31. hmtlElement.classList.add('touch');
  32. }
  33. })(window, document);