dict.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. var dict_pre_searching=false;
  2. var dict_pre_search_curr_word="";
  3. var dict_search_xml_http=null;
  4. function dict_bold_word_all_select(){
  5. var wordcount=$("#bold_word_count").val();
  6. for(var i=0;i<wordcount;i++){
  7. document.getElementById("bold_word_"+i).checked=document.getElementById("bold_all_word").checked;
  8. }
  9. dict_update_bold(0);
  10. }
  11. function dict_bold_word_select(id){
  12. var wordcount=$("#bold_word_count").val();
  13. for(var i=0;i<wordcount;i++){
  14. document.getElementById("bold_word_"+i).checked=false;
  15. }
  16. document.getElementById("bold_word_"+id).checked=true;
  17. dict_update_bold(0);
  18. }
  19. function dict_bold_book_select(id){
  20. var bookcount=$("#bold_book_count").val();
  21. for(var i=0;i<bookcount;i++){
  22. document.getElementById("bold_book_"+i).checked=false;
  23. }
  24. document.getElementById("bold_book_"+id).checked=true;
  25. dict_update_bold(0);
  26. }
  27. function dict_update_bold(currpage){
  28. var wordlist="(";
  29. var wordcount=$("#bold_word_count").val();
  30. for(var i=0;i<wordcount;i++){
  31. if(document.getElementById("bold_word_"+i).checked){
  32. wordlist+="'"+$("#bold_word_"+i).val()+"',";
  33. }
  34. }
  35. wordlist=wordlist.slice(0,-1);
  36. wordlist+=")";
  37. var booklist="(";
  38. var bookcount=$("#bold_book_count").val();
  39. for(var i=0;i<bookcount;i++){
  40. if(document.getElementById("bold_book_"+i).checked){
  41. booklist+="'"+$("#bold_book_"+i).val()+"',";
  42. }
  43. }
  44. booklist=booklist.slice(0,-1);
  45. booklist+=")";
  46. $.get("./dict_find3.php",
  47. {
  48. op:"update",
  49. target:"bold",
  50. word:"",
  51. wordlist:wordlist,
  52. booklist:booklist,
  53. currpage:currpage
  54. },
  55. function(data,status){
  56. //alert("Data: " + data + "\nStatus: " + status);
  57. $("#dict_bold_right").html(data);
  58. $("#bold_book_list").html($("#bold_book_list_new").html());
  59. $("#bold_book_list_new").html("");
  60. });
  61. }
  62. function dict_search(word){
  63. if(!localStorage.searchword){
  64. localStorage.searchword="";
  65. }
  66. let oldHistory=localStorage.searchword;
  67. let arrOldHistory=oldHistory.split(",");
  68. let isExist=false;
  69. for(let i=0;i<arrOldHistory.length;i++){
  70. if(arrOldHistory[i]==word){
  71. isExist=true;
  72. }
  73. }
  74. if(!isExist){
  75. localStorage.searchword=word+","+oldHistory;
  76. }
  77. if(window.XMLHttpRequest)
  78. {// code for IE7, Firefox, Opera, etc.
  79. dict_search_xml_http=new XMLHttpRequest();
  80. }
  81. else if(window.ActiveXObject)
  82. {// code for IE6, IE5
  83. dict_search_xml_http=new ActiveXObject("Microsoft.XMLHTTP");
  84. }
  85. if (dict_search_xml_http!=null)
  86. {
  87. dict_search_xml_http.onreadystatechange=dict_search_serverResponse;
  88. word=word.replace(/\+/g,"%2b");
  89. dict_search_xml_http.open("GET", "./dict_find3.php?op=search&word="+word, true);
  90. dict_search_xml_http.send();
  91. }
  92. else
  93. {
  94. alert("Your browser does not support XMLHTTP.");
  95. }
  96. }
  97. function dict_search_serverResponse(){
  98. if (dict_search_xml_http.readyState==4)// 4 = "loaded"
  99. {
  100. if (dict_search_xml_http.status==200)
  101. {// 200 = "OK"
  102. var serverText = dict_search_xml_http.responseText;
  103. dict_result=document.getElementById("dict_ref_search_result");
  104. if(dict_result){
  105. dict_result.innerHTML=serverText;
  106. $("#dict_ref_dict_link").html($("#dictlist").html());
  107. $("#dictlist").html("");
  108. }
  109. $("#dict_type").html($("#real_dict_tab").html());
  110. }
  111. else
  112. {
  113. alert(dict_pre_search_xml_http.statusText,0);
  114. }
  115. }
  116. }
  117. var dict_pre_search_xml_http=null;
  118. function dict_pre_search(word){
  119. if(dict_pre_searching==true){return;}
  120. dict_pre_searching=true;
  121. dict_pre_search_curr_word=word;
  122. if(window.XMLHttpRequest)
  123. {// code for IE7, Firefox, Opera, etc.
  124. dict_pre_search_xml_http=new XMLHttpRequest();
  125. }
  126. else if(window.ActiveXObject)
  127. {// code for IE6, IE5
  128. dict_pre_search_xml_http=new ActiveXObject("Microsoft.XMLHTTP");
  129. }
  130. if (dict_pre_search_xml_http!=null)
  131. {
  132. dict_pre_search_xml_http.onreadystatechange=dict_pre_search_serverResponse;
  133. dict_pre_search_xml_http.open("GET", "./dict_find3.php?op=pre&word="+word, true);
  134. dict_pre_search_xml_http.send();
  135. }
  136. else
  137. {
  138. alert("Your browser does not support XMLHTTP.");
  139. }
  140. }
  141. function dict_pre_search_serverResponse(){
  142. if (dict_pre_search_xml_http.readyState==4)// 4 = "loaded"
  143. {
  144. if (dict_pre_search_xml_http.status==200)
  145. {// 200 = "OK"
  146. var serverText = dict_pre_search_xml_http.responseText;
  147. $("#dict_ref_search_result").html(serverText);
  148. }
  149. else
  150. {
  151. alert(dict_pre_search_xml_http.statusText,0);
  152. }
  153. dict_pre_searching=false;
  154. var newword = document.getElementById("dict_ref_search_input").value;
  155. if(newword!=dict_pre_search_curr_word){
  156. dict_pre_search(newword);
  157. }
  158. }
  159. }
  160. function dict_pre_word_click(word){
  161. document.getElementById("dict_ref_search_input").value=word;
  162. dict_search(word);
  163. }
  164. function dict_input_change(obj){
  165. dict_pre_search(obj.value);
  166. }
  167. function dict_input_onfocus(){
  168. if($("#dict_ref_search_input").val()==""){
  169. dict_show_history();
  170. }
  171. }
  172. function dict_input_keypress(e,obj){
  173. var keynum
  174. var keychar
  175. var numcheck
  176. if(window.event) // IE
  177. {
  178. keynum = e.keyCode
  179. }
  180. else if(e.which) // Netscape/Firefox/Opera
  181. {
  182. keynum = e.which
  183. }
  184. var keychar = String.fromCharCode(keynum)
  185. if(keynum==13){
  186. }
  187. }
  188. function dict_input_keyup(e,obj){
  189. var keynum
  190. var keychar
  191. var numcheck
  192. if($("#dict_ref_search_input").val()==""){
  193. dict_show_history();
  194. return;
  195. }
  196. if(window.event) // IE
  197. {
  198. keynum = e.keyCode
  199. }
  200. else if(e.which) // Netscape/Firefox/Opera
  201. {
  202. keynum = e.which
  203. }
  204. var keychar = String.fromCharCode(keynum)
  205. if(keynum==13){
  206. dict_search(obj.value);
  207. }
  208. else{
  209. dict_input_split(obj.value);
  210. dict_pre_search(obj.value);
  211. }
  212. }
  213. function dict_input_split(word){
  214. if(word.indexOf("+")>=0){
  215. var wordParts=word.split("+");
  216. var strParts="";
  217. for(var i in wordParts){
  218. strParts+="<a onclick='dict_search(\""+wordParts[i]+"\")'>"+wordParts[i]+"</a>";
  219. }
  220. document.getElementById("input_parts").innerHTML=strParts;
  221. }
  222. else{
  223. document.getElementById("input_parts").innerHTML="";
  224. }
  225. }
  226. function dict_show_history(){
  227. if(!localStorage.searchword){
  228. localStorage.searchword="";
  229. }
  230. var arrHistory=localStorage.searchword.split(",");
  231. var strHistory="";
  232. if(arrHistory.length>0){
  233. strHistory+="<a onclick=\"cls_word_search_history()\">清空历史记录</a>";
  234. }
  235. for(var i=0;i<arrHistory.length;i++){
  236. var word=arrHistory[i];
  237. strHistory+="<div class='dict_word_list'>";
  238. strHistory+="<a onclick='dict_pre_word_click(\""+word+"\")'>"+word+"</a>";
  239. strHistory+="</div>";
  240. }
  241. $("#dict_ref_search_result").html(strHistory);
  242. }
  243. function cls_word_search_history(){
  244. localStorage.searchword="";
  245. $("#dict_ref_search_result").html("");
  246. }
  247. function dict_show_edit(){
  248. $("#user_word_edit").slideToggle();
  249. }
  250. function dict_edit_now(book,para,title){
  251. var res_list = new Array();
  252. res_list.push({"type":"1","album_id":"-1","book":book,"parNum":para,"parlist":para,"title":title+"-"+para});
  253. res_list.push({"type":"6","album_id":"-1","book":book,"parNum":para,"parlist":para,"title":title+"-"+para});
  254. var res_data = JSON.stringify(res_list);
  255. window.open("../studio/project.php?op=create&data="+res_data,"_blank");
  256. }