paliword.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. $("#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. "paliword_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. $("#pre_search_result_1").hide();
  176. let inputSearch = $("#dict_ref_search_input").val();
  177. let arrSearch = inputSearch.split(" ");
  178. arrSearch[arrSearch.length - 1] = word;
  179. let strSearchWord = arrSearch.join(" ");
  180. $("#dict_ref_search_input").val(strSearchWord);
  181. $("#dict_ref_search_input_1").val(strSearchWord);
  182. search_search(word);
  183. }
  184. function dict_input_change(obj) {
  185. search_pre_search(obj.value);
  186. }
  187. function search_show_history() {
  188. if (!localStorage.searchword) {
  189. localStorage.searchword = "";
  190. }
  191. var arrHistory = localStorage.searchword.split(",");
  192. var strHistory = "";
  193. if (arrHistory.length > 0) {
  194. strHistory += '<a onclick="cls_word_search_history()">清空历史记录</a>';
  195. }
  196. for (var i = 0; i < arrHistory.length; i++) {
  197. var word = arrHistory[i];
  198. strHistory += "<div class='dict_word_list'>";
  199. strHistory +=
  200. "<a onclick='dict_pre_word_click(\"" + word + "\")'>" + word + "</a>";
  201. strHistory += "</div>";
  202. }
  203. $("#dict_ref_search_result").html(strHistory);
  204. }
  205. function search_input_onfocus() {
  206. if ($("#dict_ref_search_input").val() == "") {
  207. search_show_history();
  208. }
  209. }
  210. function search_input_keyup(e, obj) {
  211. var keynum;
  212. var keychar;
  213. var numcheck;
  214. if ($("#dict_ref_search_input").val() == "") {
  215. search_show_history();
  216. $("#pre_search_result").hide();
  217. $("#pre_search_result_1").hide();
  218. return;
  219. }
  220. if (window.event) {
  221. // IE
  222. keynum = e.keyCode;
  223. } else if (e.which) {
  224. // Netscape/Firefox/Opera
  225. keynum = e.which;
  226. }
  227. var keychar = String.fromCharCode(keynum);
  228. if (keynum == 13) {
  229. //search_search(obj.value);
  230. window.location.assign("../search/paliword.php?key=" + obj.value);
  231. } else {
  232. if (obj.value.indexOf(" ") >= 0) {
  233. //search_pre_sent(obj.value);
  234. } else {
  235. $("#pre_search_sent").hide();
  236. }
  237. $("#pre_search_result").show();
  238. $("#pre_search_result_1").show();
  239. search_pre_search(obj.value);
  240. }
  241. }
  242. function search_pre_sent(word) {
  243. pali_sent_get_word(word, function (result) {
  244. let html = "";
  245. try {
  246. let arrResult = JSON.parse(result);
  247. for (x in arrResult) {
  248. html += arrResult[x].text + "<br>";
  249. }
  250. $("#pre_search_sent_title_right").html("总共" + arrResult.lenght);
  251. $("#pre_search_sent_content").html(html);
  252. $("#pre_search_sent").show();
  253. } catch (e) {
  254. console.error(e.message);
  255. }
  256. });
  257. }
  258. function cls_word_search_history() {
  259. localStorage.searchword = "";
  260. $("#dict_ref_search_result").html("");
  261. }
  262. function search_edit_now(book, para, title) {
  263. var res_list = new Array();
  264. res_list.push({
  265. type: "1",
  266. album_id: "-1",
  267. book: book,
  268. parNum: para,
  269. parlist: para,
  270. title: title + "-" + para,
  271. });
  272. res_list.push({
  273. type: "6",
  274. album_id: "-1",
  275. book: book,
  276. parNum: para,
  277. parlist: para,
  278. title: title + "-" + para,
  279. });
  280. var res_data = JSON.stringify(res_list);
  281. window.open("../studio/project.php?op=create&data=" + res_data, "_blank");
  282. }