search.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*全文搜索引擎*/
  2. var g_pali_word_item_hide_id = new Array();
  3. var search_text_pre_searching = false;
  4. var search_text_pre_search_curr_word = "";
  5. var search_text_search_xml_http = null;
  6. function search_text_search(word) {
  7. if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
  8. search_text_search_xml_http = new XMLHttpRequest();
  9. }
  10. else if (window.ActiveXObject) {// code for IE6, IE5
  11. search_text_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  12. }
  13. if (search_text_search_xml_http != null) {
  14. search_text_search_xml_http.onreadystatechange = search_text_search_serverResponse;
  15. search_text_search_xml_http.open("GET", "./search_text.php?op=search&word=" + word, true);
  16. search_text_search_xml_http.send();
  17. }
  18. else {
  19. alert("Your browser does not support XMLHTTP.");
  20. }
  21. }
  22. function search_text_search_serverResponse() {
  23. if (search_text_search_xml_http.readyState == 4)// 4 = "loaded"
  24. {
  25. //debugOutput("server response.",0);
  26. if (search_text_search_xml_http.status == 200) {// 200 = "OK"
  27. var serverText = search_text_search_xml_http.responseText;
  28. search_text_result = document.getElementById("search_text_result");
  29. if (search_text_result) {
  30. search_text_result.innerHTML = serverText;
  31. }
  32. }
  33. else {
  34. //debugOutput(search_text_pre_search_xml_http.statusText,0);
  35. }
  36. }
  37. path_name_upgrade();
  38. }
  39. var search_text_pre_search_xml_http = null;
  40. function search_text_pre_search(word) {
  41. if (search_text_pre_searching == true) { return; }
  42. search_text_pre_searching = true;
  43. search_text_pre_search_curr_word = word;
  44. if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
  45. search_text_pre_search_xml_http = new XMLHttpRequest();
  46. }
  47. else if (window.ActiveXObject) {// code for IE6, IE5
  48. search_text_pre_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  49. }
  50. if (search_text_pre_search_xml_http != null) {
  51. search_text_pre_search_xml_http.onreadystatechange = search_text_pre_search_serverResponse;
  52. search_text_pre_search_xml_http.open("GET", "./search_text.php?op=pre&word=" + word, true);
  53. search_text_pre_search_xml_http.send();
  54. }
  55. else {
  56. alert("Your browser does not support XMLHTTP.");
  57. }
  58. }
  59. function search_text_pre_search_serverResponse() {
  60. if (search_text_pre_search_xml_http.readyState == 4)// 4 = "loaded"
  61. {
  62. //debugOutput("server response.",0);
  63. if (search_text_pre_search_xml_http.status == 200) {// 200 = "OK"
  64. var serverText = search_text_pre_search_xml_http.responseText;
  65. if (window.DOMParser) {
  66. var parser = new DOMParser();
  67. var wordData = parser.parseFromString(serverText, "text/xml");
  68. }
  69. else { // Internet Explorer
  70. var wordData = new ActiveXObject("Microsoft.XMLDOM");
  71. wordData.async = "false";
  72. wordData.loadXML(serverText);
  73. }
  74. if (wordData) {
  75. var wordlist = wordData.getElementsByTagName("word")
  76. //var obj = JSON.parse(serverText);
  77. var search_text_word = "";
  78. for (var iword = 0; iword < wordlist.length; iword++) {
  79. search_text_word += "<li class=\"pali_book_item\" onclick='search_text_add_key_word(\"" + getNodeText(wordlist[iword], "pali") + "\"," + getNodeText(wordlist[iword], "count") + ",this)'>" + getNodeText(wordlist[iword], "pali") + "-" + getNodeText(wordlist[iword], "count") + "</li>"
  80. }
  81. search_text_result = document.getElementById("search_word_prev");
  82. if (search_text_result) {
  83. search_text_result.innerHTML = search_text_word;
  84. }
  85. }
  86. }
  87. else {
  88. //debugOutput(search_text_pre_search_xml_http.statusText,0);
  89. }
  90. search_text_pre_searching = false;
  91. var newword = document.getElementById("search_text_input").value;
  92. if (newword != search_text_pre_search_curr_word) {
  93. search_text_pre_search(newword);
  94. }
  95. }
  96. }
  97. function search_text_pre_word_click(word) {
  98. //document.getElementById("dict_ref_search_input").value=word;
  99. search_text_search(word);
  100. }
  101. function search_text_input_change(obj) {
  102. search_text_pre_search(obj.value);
  103. }
  104. function search_text_input_keypress(e, obj) {
  105. var keynum
  106. var keychar
  107. var numcheck
  108. if (window.event) // IE
  109. {
  110. keynum = e.keyCode
  111. }
  112. else if (e.which) // Netscape/Firefox/Opera
  113. {
  114. keynum = e.which
  115. }
  116. var keychar = String.fromCharCode(keynum)
  117. if (keynum == 13) {
  118. }
  119. }
  120. function search_text_input_keyup(e, obj) {
  121. var keynum
  122. var keychar
  123. var numcheck
  124. if (window.event) // IE
  125. {
  126. keynum = e.keyCode
  127. }
  128. else if (e.which) // Netscape/Firefox/Opera
  129. {
  130. keynum = e.which
  131. }
  132. var keychar = String.fromCharCode(keynum)
  133. if (keynum == 13) {
  134. search_text_search(obj.value);
  135. }
  136. else {
  137. search_text_pre_search(obj.value);
  138. }
  139. }
  140. function search_text_input_split(word) {
  141. if (word.indexOf("+") >= 0) {
  142. var wordParts = word.split("+");
  143. var strParts = "";
  144. for (var i in wordParts) {
  145. strParts += "<a onclick='dict_search(\"" + wordParts[i] + "\")'>" + wordParts[i] + "</a>";
  146. }
  147. document.getElementById("input_parts").innerHTML = strParts;
  148. }
  149. else {
  150. document.getElementById("input_parts").innerHTML = "";
  151. }
  152. }
  153. var search_text_key_word = new Array();
  154. var index_count = 0;
  155. function search_text_add_key_word(str, count, obj) {
  156. var objWord = new Object();
  157. objWord.pali = str;
  158. objWord.count = count;
  159. objWord.index = index_count;
  160. index_count++;
  161. obj.style = "max-height: 0px; padding: 0px; opacity: 0;";
  162. obj.id = "pali_book_item_hide_" + com_guid();
  163. objWord.idstr = obj.id;
  164. g_pali_word_item_hide_id.push(obj.id);
  165. //obj.style.display="none";
  166. search_text_key_word.push(objWord);
  167. search_text_refresh_key_word();
  168. }
  169. function search_text_remove_key_word(word_index, obj) {
  170. obj.style = "max-width: 0px; padding: 0px; opacity: 0;";
  171. for (var iword = 0; iword < search_text_key_word.length; iword++) {
  172. if (search_text_key_word[iword].index == word_index) {
  173. if (document.getElementById(search_text_key_word[iword].idstr) != null) {
  174. document.getElementById(search_text_key_word[iword].idstr).style = "";
  175. }
  176. search_text_key_word.splice(iword, 1);
  177. break;
  178. }
  179. }
  180. search_text_refresh_key_word();
  181. }
  182. function search_text_remove_all_key_word() {
  183. var search_text_array = document.getElementById("search_word_key_word").getElementsByClassName("pali_book_item");
  184. for (var i_search = 0; i_search < search_text_array.length; i_search++) {
  185. search_text_array[i_search].style = "max-width: 0px; padding: 0px; opacity: 0;"
  186. }
  187. for (var iword = 0; iword < search_text_key_word.length; iword++) {
  188. if (document.getElementById(search_text_key_word[iword] != null)) {
  189. document.getElementById(search_text_key_word[iword].idstr).style = "";
  190. }
  191. }
  192. search_text_key_word = new Array();
  193. search_text_refresh_key_word();
  194. //var pali_book_item_hide_array=document.getElementsByClassName("pali_book_item_hide");
  195. //for(i_pali_book_item_hide in pali_book_item_hide_array){
  196. // pali_book_item_hide_array[i_pali_book_item_hide].className="pali_book_item";
  197. //}
  198. }
  199. function search_text_refresh_key_word() {
  200. var html_key_list = "";
  201. for (var iword = 0; iword < search_text_key_word.length; iword++) {
  202. html_key_list += "<li class=\"pali_book_item\" onclick='search_text_remove_key_word(\"" + search_text_key_word[iword].index + "\",this)'>" + (search_text_key_word[iword].pali) + "-" + (search_text_key_word[iword].count) + "</li>"
  203. }
  204. var search_text_ctl_key_word = document.getElementById("search_word_key_word");
  205. if (search_text_ctl_key_word) {
  206. search_text_ctl_key_word.innerHTML = html_key_list;
  207. }
  208. }
  209. function search_text_advance_search() {
  210. var key_word = "";
  211. for (var iword = 0; iword < search_text_key_word.length; iword++) {
  212. key_word += search_text_key_word[iword].pali + ",";
  213. }
  214. search_text_search(key_word);
  215. }
  216. function path_name_upgrade() {
  217. var path_array = document.getElementsByClassName('book_path');
  218. for (var i_path = 0; i_path < path_array.length; i_path++) {
  219. var path_str = path_array[i_path].innerHTML.split('#');
  220. for (j_path in local_palicannon_index) {
  221. if (local_palicannon_index[j_path].id == path_str[0]) {
  222. path_str[0] = local_palicannon_index[j_path].c1 + ">";
  223. path_str[0] += local_palicannon_index[j_path].c2 + ">";
  224. if (local_palicannon_index[j_path].c3 != "") {
  225. path_str[0] += local_palicannon_index[j_path].c3 + ">";
  226. if (local_palicannon_index[j_path].c4 != "") {
  227. path_str[0] += local_palicannon_index[j_path].c4 + ">";
  228. }
  229. }
  230. path_str[0] += "《" + local_palicannon_index[j_path].title + "》";
  231. }
  232. }
  233. path_array[i_path].innerHTML = path_str[0] + path_str[1];
  234. }
  235. }
  236. function search_edit(bookid, par) {
  237. var newRes = new Object()
  238. newRes.res = "wbw";
  239. newRes.book = bookid;
  240. newRes.parNum = par;
  241. newRes.parEnd = par;
  242. newRes.language = "pali";
  243. newRes.author = "templet";
  244. newRes.editor = "pcds";
  245. newRes.revision = 1;
  246. newRes.edition = 1;
  247. newRes.subver = 1;
  248. var arrRes = new Array();
  249. arrRes.push(newRes);
  250. window.open("./project.php?op=create&data=" + JSON.stringify(arrRes));
  251. }