00_init.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * searx is free software: you can redistribute it and/or modify
  3. * it under the terms of the GNU Affero General Public License as published by
  4. * the Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * searx is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Affero General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Affero General Public License
  13. * along with searx. If not, see < http://www.gnu.org/licenses/ >.
  14. *
  15. * (C) 2019 by Alexandre Flament
  16. *
  17. */
  18. (function(w, d) {
  19. 'use strict';
  20. // add data- properties
  21. var script = d.currentScript || (function() {
  22. var scripts = d.getElementsByTagName('script');
  23. return scripts[scripts.length - 1];
  24. })();
  25. // try to detect touch screen
  26. w.searx = {
  27. touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false,
  28. method: script.getAttribute('data-method'),
  29. autocompleter: script.getAttribute('data-autocompleter') === 'true',
  30. search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
  31. infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
  32. static_path: script.getAttribute('data-static-path'),
  33. translations: JSON.parse(script.getAttribute('data-translations')),
  34. }
  35. // update the css
  36. d.getElementsByTagName("html")[0].className = (w.searx.touch)?"js touch":"js";
  37. })(window, document);