search.js 8.3 KB

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