paliword.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. "paliword_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. $("#pre_search_result_1").hide();
  78. if (!localStorage.searchword) {
  79. localStorage.searchword = "";
  80. }
  81. let oldHistory = localStorage.searchword;
  82. let arrOldHistory = oldHistory.split(",");
  83. let isExist = false;
  84. for (let i = 0; i < arrOldHistory.length; i++) {
  85. if (arrOldHistory[i] == word) {
  86. isExist = true;
  87. }
  88. }
  89. if (!isExist) {
  90. localStorage.searchword = word + "," + oldHistory;
  91. }
  92. if (window.XMLHttpRequest) {
  93. // code for IE7, Firefox, Opera, etc.
  94. dict_search_xml_http = new XMLHttpRequest();
  95. } else if (window.ActiveXObject) {
  96. // code for IE6, IE5
  97. dict_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  98. }
  99. if (dict_search_xml_http != null) {
  100. dict_search_xml_http.onreadystatechange = dict_search_serverResponse;
  101. word = word.replace(/\+/g, "%2b");
  102. dict_search_xml_http.open(
  103. "GET",
  104. "paliword_search.php?op=search&word=" + word,
  105. true
  106. );
  107. dict_search_xml_http.send();
  108. } else {
  109. alert("Your browser does not support XMLHTTP.");
  110. }
  111. }
  112. function dict_search_serverResponse() {
  113. if (dict_search_xml_http.readyState == 4) {
  114. // 4 = "loaded"
  115. if (dict_search_xml_http.status == 200) {
  116. // 200 = "OK"
  117. var serverText = dict_search_xml_http.responseText;
  118. dict_result = document.getElementById("dict_ref_search_result");
  119. if (dict_result) {
  120. dict_result.innerHTML = serverText;
  121. $("#index_list").hide();
  122. $("#dict_ref_dict_link").html($("#dictlist").html());
  123. $("#dictlist").html("");
  124. }
  125. //$("#dict_type").html($("#real_dict_tab").html());
  126. } else {
  127. alert(dict_pre_search_xml_http.statusText, 0);
  128. }
  129. }
  130. }
  131. var dict_pre_search_xml_http = null;
  132. function search_pre_search(word) {
  133. if (dict_pre_searching == true) {
  134. return;
  135. }
  136. dict_pre_searching = true;
  137. dict_pre_search_curr_word = word;
  138. if (window.XMLHttpRequest) {
  139. // code for IE7, Firefox, Opera, etc.
  140. dict_pre_search_xml_http = new XMLHttpRequest();
  141. } else if (window.ActiveXObject) {
  142. // code for IE6, IE5
  143. dict_pre_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  144. }
  145. if (dict_pre_search_xml_http != null) {
  146. dict_pre_search_xml_http.onreadystatechange = dict_pre_search_serverResponse;
  147. dict_pre_search_xml_http.open(
  148. "GET",
  149. "paliword_search.php?op=pre&word=" + word,
  150. true
  151. );
  152. dict_pre_search_xml_http.send();
  153. } else {
  154. alert("Your browser does not support XMLHTTP.");
  155. }
  156. }
  157. function dict_pre_search_serverResponse() {
  158. if (dict_pre_search_xml_http.readyState == 4) {
  159. // 4 = "loaded"
  160. if (dict_pre_search_xml_http.status == 200) {
  161. // 200 = "OK"
  162. var serverText = dict_pre_search_xml_http.responseText;
  163. $("#pre_search_word_content").html(serverText);
  164. } else {
  165. alert(dict_pre_search_xml_http.statusText, 0);
  166. }
  167. dict_pre_searching = false;
  168. var newword = document.getElementById("dict_ref_search_input").value;
  169. if (newword != dict_pre_search_curr_word) {
  170. search_pre_search(newword);
  171. }
  172. }
  173. }
  174. function dict_pre_word_click(word) {
  175. $("#pre_search_result").hide();
  176. $("#pre_search_result_1").hide();
  177. let inputSearch = $("#dict_ref_search_input").val();
  178. let arrSearch = inputSearch.split(" ");
  179. arrSearch[arrSearch.length - 1] = word;
  180. let strSearchWord = arrSearch.join(" ");
  181. $("#dict_ref_search_input").val(strSearchWord);
  182. $("#dict_ref_search_input_1").val(strSearchWord);
  183. search_search(word);
  184. }
  185. function dict_input_change(obj) {
  186. search_pre_search(obj.value);
  187. }
  188. function search_show_history() {
  189. if (!localStorage.searchword) {
  190. localStorage.searchword = "";
  191. }
  192. var arrHistory = localStorage.searchword.split(",");
  193. var strHistory = "";
  194. if (arrHistory.length > 0) {
  195. strHistory += '<a onclick="cls_word_search_history()">清空历史记录</a>';
  196. }
  197. const max_history_len = 20;
  198. let history_len = 0;
  199. if (arrHistory.length > max_history_len) {
  200. history_len = max_history_len;
  201. } else {
  202. history_len = arrHistory.length;
  203. }
  204. for (var i = 0; i < history_len; i++) {
  205. var word = arrHistory[i];
  206. strHistory += "<div class='dict_word_list'>";
  207. strHistory +=
  208. "<a onclick='dict_pre_word_click(\"" + word + "\")'>" + word + "</a>";
  209. strHistory += "</div>";
  210. }
  211. $("#search_histray").html(strHistory);
  212. }
  213. function search_input_onfocus() {
  214. if ($("#dict_ref_search_input").val() == "") {
  215. //search_show_history();
  216. }
  217. }
  218. function search_input_keyup(e, obj) {
  219. var keynum;
  220. var keychar;
  221. var numcheck;
  222. if ($("#dict_ref_search_input").val() == "") {
  223. //search_show_history();
  224. $("#pre_search_result").hide();
  225. $("#pre_search_result_1").hide();
  226. return;
  227. }
  228. if (window.event) {
  229. // IE
  230. keynum = e.keyCode;
  231. } else if (e.which) {
  232. // Netscape/Firefox/Opera
  233. keynum = e.which;
  234. }
  235. var keychar = String.fromCharCode(keynum);
  236. if (keynum == 13) {
  237. //search_search(obj.value);
  238. window.location.assign("../search/paliword.php?key=" + obj.value);
  239. } else {
  240. if (obj.value.indexOf(" ") >= 0) {
  241. //search_pre_sent(obj.value);
  242. } else {
  243. $("#pre_search_sent").hide();
  244. }
  245. $("#pre_search_result").show();
  246. $("#pre_search_result_1").show();
  247. search_pre_search(obj.value);
  248. }
  249. }
  250. function search_pre_sent(word) {
  251. pali_sent_get_word(word, function (result) {
  252. let html = "";
  253. try {
  254. let arrResult = JSON.parse(result);
  255. for (x in arrResult) {
  256. html += arrResult[x].text + "<br>";
  257. }
  258. $("#pre_search_sent_title_right").html("总共" + arrResult.lenght);
  259. $("#pre_search_sent_content").html(html);
  260. $("#pre_search_sent").show();
  261. } catch (e) {
  262. console.error(e.message);
  263. }
  264. });
  265. }
  266. function cls_word_search_history() {
  267. localStorage.searchword = "";
  268. $("#dict_ref_search_result").html("");
  269. }
  270. function search_edit_now(book, para, title) {
  271. var res_list = new Array();
  272. res_list.push({
  273. type: "1",
  274. album_id: "-1",
  275. book: book,
  276. parNum: para,
  277. parlist: para,
  278. title: title + "-" + para,
  279. });
  280. res_list.push({
  281. type: "6",
  282. album_id: "-1",
  283. book: book,
  284. parNum: para,
  285. parlist: para,
  286. title: title + "-" + para,
  287. });
  288. var res_data = JSON.stringify(res_list);
  289. window.open("../studio/project.php?op=create&data=" + res_data, "_blank");
  290. }