2
0

bold.js 8.2 KB

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