dict.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var dict_pre_searching=false;
  2. var dict_pre_search_curr_word="";
  3. var dict_search_xml_http=null;
  4. function dict_search(word){
  5. if(window.XMLHttpRequest)
  6. {// code for IE7, Firefox, Opera, etc.
  7. dict_search_xml_http=new XMLHttpRequest();
  8. }
  9. else if(window.ActiveXObject)
  10. {// code for IE6, IE5
  11. dict_search_xml_http=new ActiveXObject("Microsoft.XMLHTTP");
  12. }
  13. if (dict_search_xml_http!=null)
  14. {
  15. dict_search_xml_http.onreadystatechange=dict_search_serverResponse;
  16. word=word.replace(/\+/g,"%2b");
  17. dict_search_xml_http.open("GET", "./dict_find3.php?op=search&word="+word, true);
  18. dict_search_xml_http.send();
  19. }
  20. else
  21. {
  22. alert("Your browser does not support XMLHTTP.");
  23. }
  24. }
  25. function dict_search_serverResponse(){
  26. if (dict_search_xml_http.readyState==4)// 4 = "loaded"
  27. {
  28. if (dict_search_xml_http.status==200)
  29. {// 200 = "OK"
  30. var serverText = dict_search_xml_http.responseText;
  31. dict_result=document.getElementById("dict_ref_search_result");
  32. if(dict_result){
  33. dict_result.innerHTML=serverText;
  34. document.getElementById("dict_ref_dict_link").innerHTML=document.getElementById("dictlist").innerHTML;
  35. document.getElementById("dictlist").innerHTML="";
  36. }
  37. }
  38. else
  39. {
  40. }
  41. }
  42. }
  43. var dict_pre_search_xml_http=null;
  44. function dict_pre_search(word){
  45. if(dict_pre_searching==true){return;}
  46. dict_pre_searching=true;
  47. dict_pre_search_curr_word=word;
  48. if(window.XMLHttpRequest)
  49. {// code for IE7, Firefox, Opera, etc.
  50. dict_pre_search_xml_http=new XMLHttpRequest();
  51. }
  52. else if(window.ActiveXObject)
  53. {// code for IE6, IE5
  54. dict_pre_search_xml_http=new ActiveXObject("Microsoft.XMLHTTP");
  55. }
  56. if (dict_pre_search_xml_http!=null)
  57. {
  58. dict_pre_search_xml_http.onreadystatechange=dict_pre_search_serverResponse;
  59. dict_pre_search_xml_http.open("GET", "./dict_find3.php?op=pre&word="+word, true);
  60. dict_pre_search_xml_http.send();
  61. }
  62. else
  63. {
  64. alert("Your browser does not support XMLHTTP.");
  65. }
  66. }
  67. function dict_pre_search_serverResponse(){
  68. if (dict_pre_search_xml_http.readyState==4)// 4 = "loaded"
  69. {
  70. if (dict_pre_search_xml_http.status==200)
  71. {// 200 = "OK"
  72. var serverText = dict_pre_search_xml_http.responseText;
  73. dict_result=document.getElementById("dict_ref_search_result");
  74. if(dict_result){
  75. dict_result.innerHTML=serverText;
  76. }
  77. }
  78. else
  79. {
  80. }
  81. dict_pre_searching=false;
  82. var newword = document.getElementById("dict_ref_search_input").value;
  83. if(newword!=dict_pre_search_curr_word){
  84. dict_pre_search(newword);
  85. }
  86. }
  87. }
  88. function dict_pre_word_click(word){
  89. document.getElementById("dict_ref_search_input").value=word;
  90. dict_search(word);
  91. }
  92. function dict_input_change(obj){
  93. dict_pre_search(obj.value);
  94. }
  95. function dict_input_keypress(e,obj){
  96. var keynum
  97. var keychar
  98. var numcheck
  99. if(window.event) // IE
  100. {
  101. keynum = e.keyCode
  102. }
  103. else if(e.which) // Netscape/Firefox/Opera
  104. {
  105. keynum = e.which
  106. }
  107. var keychar = String.fromCharCode(keynum)
  108. if(keynum==13){
  109. }
  110. }
  111. function dict_input_keyup(e,obj){
  112. var keynum
  113. var keychar
  114. var numcheck
  115. if(window.event) // IE
  116. {
  117. keynum = e.keyCode
  118. }
  119. else if(e.which) // Netscape/Firefox/Opera
  120. {
  121. keynum = e.which
  122. }
  123. var keychar = String.fromCharCode(keynum)
  124. if(keynum==13){
  125. dict_search(obj.value);
  126. }
  127. else{
  128. dict_input_split(obj.value);
  129. dict_pre_search(obj.value);
  130. }
  131. }
  132. function dict_input_split(word){
  133. if(word.indexOf("+")>=0){
  134. var wordParts=word.split("+");
  135. var strParts="";
  136. for(var i in wordParts){
  137. strParts+="<a onclick='dict_search(\""+wordParts[i]+"\")'>"+wordParts[i]+"</a>";
  138. }
  139. document.getElementById("input_parts").innerHTML=strParts;
  140. }
  141. else{
  142. document.getElementById("input_parts").innerHTML="";
  143. }
  144. }