dict.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $("#pre_search_result").hide();
  6. if(!localStorage.searchword){
  7. localStorage.searchword="";
  8. }
  9. let oldHistory=localStorage.searchword;
  10. let arrOldHistory=oldHistory.split(",");
  11. let isExist=false;
  12. for(let i=0;i<arrOldHistory.length;i++){
  13. if(arrOldHistory[i]==word){
  14. isExist=true;
  15. }
  16. }
  17. if(!isExist){
  18. localStorage.searchword=word+","+oldHistory;
  19. }
  20. $.get("dict_lookup.php",
  21. {
  22. op:"search",
  23. word:word
  24. },
  25. function(data,status){
  26. $("#dict_search_result").html(data);
  27. $("#dict_list").html($("#dictlist").html());
  28. $("#dictlist").html("");
  29. });
  30. }
  31. function dict_pre_search(word){
  32. if(dict_pre_searching==true){return;}
  33. dict_pre_searching=true;
  34. dict_pre_search_curr_word=word;
  35. $.get("dict_lookup.php",
  36. {
  37. op:"pre",
  38. word:word
  39. },
  40. function(data,status){
  41. dict_pre_searching=false;
  42. dict_pre_search_curr_word="";
  43. $("#pre_search_word_content").html(data);
  44. $("#pre_search_result").css("display","block");
  45. });
  46. }
  47. function dict_pre_word_click(word){
  48. $("#dict_ref_search_input").val(word);
  49. $("#pre_search_result").hide();
  50. dict_search(word);
  51. }
  52. function dict_input_change(obj){
  53. dict_pre_search(obj.value);
  54. }
  55. function dict_input_onfocus(){
  56. if($("#dict_ref_search_input").val()==""){
  57. dict_show_history();
  58. }
  59. }
  60. function dict_input_keyup(e,obj){
  61. var keynum
  62. var keychar
  63. var numcheck
  64. if($("#dict_ref_search_input").val()==""){
  65. dict_show_history();
  66. return;
  67. }
  68. if(window.event) // IE
  69. {
  70. keynum = e.keyCode
  71. }
  72. else if(e.which) // Netscape/Firefox/Opera
  73. {
  74. keynum = e.which
  75. }
  76. var keychar = String.fromCharCode(keynum)
  77. if(keynum==13){
  78. dict_search(obj.value);
  79. }
  80. else{
  81. dict_input_split(obj.value);
  82. if(obj.value.indexOf("+")==-1){
  83. dict_pre_search(obj.value);
  84. }
  85. else{
  86. dict_input_split(obj.value);
  87. $("#pre_search_result").hide();
  88. }
  89. }
  90. }
  91. function dict_input_split(word){
  92. if(word.indexOf("+")>=0){
  93. var wordParts=word.split("+");
  94. var strParts="";
  95. for(var i in wordParts){
  96. strParts+="<a onclick='dict_search(\""+wordParts[i]+"\")'>"+wordParts[i]+"</a>";
  97. }
  98. $("#input_parts").html(strParts);
  99. }
  100. else{
  101. $("#input_parts").html("");
  102. }
  103. }
  104. function dict_show_history(){
  105. if(!localStorage.searchword){
  106. localStorage.searchword="";
  107. }
  108. var arrHistory=localStorage.searchword.split(",");
  109. var strHistory="";
  110. if(arrHistory.length>0){
  111. strHistory+="<a onclick=\"cls_word_search_history()\">清空历史记录</a>";
  112. }
  113. for(var i=0;i<arrHistory.length;i++){
  114. var word=arrHistory[i];
  115. strHistory+="<div class='dict_word_list'>";
  116. strHistory+="<a onclick='dict_pre_word_click(\""+word+"\")'>"+word+"</a>";
  117. strHistory+="</div>";
  118. }
  119. $("#dict_ref_search_result").html(strHistory);
  120. }
  121. function cls_word_search_history(){
  122. localStorage.searchword="";
  123. $("#dict_ref_search_result").html("");
  124. }
  125. function trubo_split(){
  126. $("#pre_search_result").hide();
  127. $.post("split.php",
  128. {
  129. word:$("#dict_ref_search_input").val()
  130. },
  131. function(data,status){
  132. try{
  133. let result= JSON.parse(data);
  134. let html="<div>";
  135. if(result.length>0){
  136. for( const part of result[0]["data"]){
  137. html += '<div class="dropdown_ctl">';
  138. html += '<div class="content">';
  139. html += '<div class="main_view">'+"<part>"+part[0].word.replace(/\+/g,"</part><part>")+"</part>"+'</div>';
  140. html += '<div class="more_button">'+part.length+'</div>';
  141. html += '</div>';
  142. html += '<div class="menu" >';
  143. for(const one_part of part){
  144. html += '<div class="part_list">'+one_part.word+'</div>';
  145. }
  146. html += '</div>';
  147. html += '</div>';
  148. }
  149. }
  150. html += "</div>";
  151. $("#input_parts").html(html);
  152. $(".more_button").click(function(){
  153. $(this).parent().siblings(".menu").toggle();
  154. }
  155. );
  156. $(".part_list").click(function(){
  157. let html="<part>"+$(this).text().replace(/\+/g,"</part><part>")+"</part>";
  158. $(this).parent().parent().find(".main_view").html(html);
  159. $(this).parent().hide();
  160. $("part").click(function(){
  161. dict_search($(this).text());
  162. });
  163. }
  164. );
  165. $("part").click(function(){
  166. dict_search($(this).text());
  167. }
  168. );
  169. }
  170. catch(e){
  171. }
  172. });
  173. }