searx.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. if(searx.autocompleter) {
  2. window.addEvent('domready', function() {
  3. new Autocompleter.Request.JSON('q', '/autocompleter', {
  4. postVar:'q',
  5. postData:{
  6. 'format': 'json'
  7. },
  8. ajaxOptions:{
  9. timeout: 5 // Correct option?
  10. },
  11. 'minLength': 4,
  12. 'selectMode': false,
  13. cache: true,
  14. delay: 300
  15. });
  16. });
  17. }
  18. (function (w, d) {
  19. 'use strict';
  20. function addListener(el, type, fn) {
  21. if (el.addEventListener) {
  22. el.addEventListener(type, fn, false);
  23. } else {
  24. el.attachEvent('on' + type, fn);
  25. }
  26. }
  27. function placeCursorAtEnd() {
  28. if (this.setSelectionRange) {
  29. var len = this.value.length * 2;
  30. this.setSelectionRange(len, len);
  31. }
  32. }
  33. addListener(w, 'load', function () {
  34. var qinput = d.getElementById('q');
  35. if (qinput !== null && qinput.value === "") {
  36. addListener(qinput, 'focus', placeCursorAtEnd);
  37. qinput.focus();
  38. }
  39. });
  40. if (!!('ontouchstart' in window)) {
  41. document.getElementsByTagName("html")[0].className += " touch";
  42. }
  43. })(window, document);
  44. var xmlHttp
  45. function GetXmlHttpObject(){
  46. var xmlHttp = null;
  47. try {
  48. // Firefox, Opera 8.0+, Safari
  49. xmlHttp = new XMLHttpRequest();
  50. }
  51. catch (e) {
  52. // Internet Explorer
  53. try {
  54. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  55. }
  56. catch (e){
  57. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  58. }
  59. }
  60. return xmlHttp;
  61. }
  62. var timer;
  63. // Calculate the rating
  64. function load_more(query,page){
  65. xmlHttp = GetXmlHttpObject();
  66. clearTimeout(timer);
  67. if(xmlHttp == null){
  68. alert ("Your browser does not support AJAX!");
  69. return;
  70. }
  71. favicons[page] = [];
  72. xmlHttp.onreadystatechange = function(){
  73. var loader = document.getElementById('load_more');
  74. if (xmlHttp.readyState == 4){
  75. //loader.style.display = 'none';
  76. var res = xmlHttp.responseText;
  77. //loader.style.display = 'block';
  78. //loader.innerHTML = '<div class="voted">Vote pris en compte</div>';
  79. clearTimeout(timer);
  80. timer = setTimeout(function(){},6000);
  81. var results = document.getElementById('results_list');
  82. //results_list.innerHTML += res;
  83. var newNode = document.createElement('span');
  84. newNode.innerHTML = res;
  85. results_list.appendChild(newNode);
  86. var scripts = newNode.getElementsByTagName('script');
  87. for (var ix = 0; ix < scripts.length; ix++) {
  88. eval(scripts[ix].text);
  89. }
  90. load_images(page);
  91. document.getElementById("load_more").onclick = function() { load_more(query, (page+1)); }
  92. loader.removeAttribute("disabled");
  93. } else {
  94. //loader.innerHTML = '<img src="images/rating_loading.gif" alt="loading" />';
  95. loader.disabled = 'disabled';
  96. }
  97. }
  98. var url = "/";
  99. var params = "q="+query+"&pageno="+page+"&category_general=1&category_files=1&category_images=1&category_it=1&category_map=1&category_music=1&category_news=1&category_social+media=1&category_videos=1";
  100. xmlHttp.open("POST",url,true);
  101. xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  102. xmlHttp.setRequestHeader("Content-length", params.length);
  103. xmlHttp.setRequestHeader("Connection", "close");
  104. xmlHttp.send(params);
  105. }
  106. function load_images(page){
  107. var arrayLength = favicons[page].length;
  108. for (var i = 1; i < arrayLength+1; i++) {
  109. var img = new Image();
  110. img.setAttribute("i",i)
  111. img.onload = function () {
  112. var id = 'canvas-'+page+'-'+this.getAttribute("i");
  113. var can = document.getElementById(id);
  114. var ctx = can.getContext("2d");
  115. ctx.drawImage(this, 0, 0, 16, 16);
  116. };
  117. img.src = favicons[page][i];
  118. }
  119. }