paliword.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. var dict_pre_searching = false;
  2. var dict_pre_search_curr_word = "";
  3. var dict_search_xml_http = null;
  4. var _key_word = "";
  5. var _filter_word = new Array();
  6. $(document).ready(function () {
  7. paliword_search(_key_word);
  8. });
  9. function paliword_search(keyword, words = new Array(), book = new Array()) {
  10. $.get(
  11. "../search/paliword_sc.php",
  12. {
  13. op: "search",
  14. key: keyword,
  15. words: JSON.stringify(words),
  16. book: JSON.stringify(book),
  17. },
  18. function (data) {
  19. let result = JSON.parse(data);
  20. let html = "";
  21. for (const iterator of result.data) {
  22. html += render_word_result(iterator);
  23. }
  24. $("#contents").html(html);
  25. html = "";
  26. html += "<div class='case_item'>";
  27. html += "<div class='spell'><a onclick='case_filter_all()'>all</a> " + result.case_num + " Words</div>";
  28. html += "<div class='tag'>" + result.case_count + "</div>";
  29. html += "</div>";
  30. for (const iterator of result.case) {
  31. html += render_case(iterator);
  32. }
  33. $("#case_content").html(html);
  34. html = "";
  35. html += "<div class='book_tag_div filter'>";
  36. if (result.book_tag) {
  37. for (const iterator of result.book_tag) {
  38. html += render_book_tag(iterator);
  39. }
  40. }
  41. html += "</div>";
  42. if (result.book_list) {
  43. for (const iterator of result.book_list) {
  44. html += render_book_list(iterator);
  45. }
  46. }
  47. $("#book_list").html(html);
  48. $("#contents_nav").html(render_nav(result));
  49. }
  50. );
  51. }
  52. function highlightWords(line, word) {
  53. var regex = new RegExp("(" + word + ")", "gi");
  54. return line.replace(regex, "<highlight>$1</highlight>");
  55. }
  56. function render_word_result(worddata) {
  57. let html = "";
  58. html += "<div class='search_result'>";
  59. let keyword = worddata.keyword;
  60. let link = "<a href='../reader/?view=para&book=" + worddata.book + "&para=" + worddata.para + "' target='_blank'>";
  61. html += "<div class='title'>" + link + worddata.title + "</a></div>";
  62. let newStr = highlightWords(worddata.palitext, keyword);
  63. html += "<div class='wizard_par_div'>" + newStr + "</div>";
  64. html += "<div class='path'>" + worddata.path + "</div>";
  65. html += "<div class='path'>" + worddata.book + "-" + worddata.para + "-" + worddata.wt + "</div>";
  66. html += "</div>";
  67. return html;
  68. }
  69. //渲染单词变格表
  70. function render_case(data) {
  71. let html = "";
  72. let wordid = data.id;
  73. html += "<div class='fileter_item case_item'>";
  74. html += "<div class='spell ";
  75. if (data.selected === true) {
  76. html += "selected";
  77. } else {
  78. html += "invalid";
  79. }
  80. html += "'>";
  81. html += "<input id='bold_word_" + wordid + "' class='wordcase filter' type='checkbox' ";
  82. if (data.selected === true) {
  83. html += " checked ";
  84. }
  85. html += "wordid='" + wordid + "' />";
  86. html += '<a onclick="word_select(' + wordid + ')">';
  87. html += data.spell;
  88. html += "</a>";
  89. html += "</div>";
  90. html += "<div class='tag'>" + data.count + "</div>";
  91. html += "</div>";
  92. return html;
  93. }
  94. //选择需要过滤的单词
  95. function word_search_filter() {
  96. let wordlist = new Array();
  97. $(".wordcase").each(function () {
  98. if ($(this).prop("checked")) {
  99. wordlist.push($(this).attr("wordid"));
  100. }
  101. });
  102. filter_cancel();
  103. _filter_word = wordlist;
  104. paliword_search(_key_word, wordlist);
  105. }
  106. function word_select(wordid) {
  107. _filter_word = [wordid];
  108. paliword_search(_key_word, [wordid]);
  109. }
  110. function case_filter_all() {
  111. paliword_search(_key_word);
  112. }
  113. //渲染书标签过滤
  114. function render_book_tag(data) {
  115. let html = "";
  116. html += "<div class='fileter_item book_tag'>";
  117. html += "<div class='spell'>";
  118. html += "<input booktag='" + data.tag + "' class='book_tag' type='checkbox' checked />";
  119. html += data.title;
  120. html += "</div>";
  121. html += "<div class='tag'>" + data.count + "</div>";
  122. html += "</div>";
  123. return html;
  124. }
  125. //渲染书列表
  126. function render_book_list(data) {
  127. let html = "";
  128. let bookid = data.book;
  129. let classSelected = "selected";
  130. html += "<div class='fileter_item book_item'>";
  131. html += "<div class='spell ";
  132. if (data.selected) {
  133. html += classSelected;
  134. }
  135. html += "'>";
  136. html += "<input book='" + bookid + "' class='book_list filter' type='checkbox' checked />";
  137. html += '<a onclick="book_select(' + bookid + ')">';
  138. html += data.title;
  139. html += "</a>";
  140. html += "</div>";
  141. html += "<div class='tag'>" + data.count + "</div>";
  142. html += "</div>";
  143. return html;
  144. }
  145. function render_nav(result) {
  146. let html = "<ul class='page_nav'>";
  147. if (result["record_count"] > 20) {
  148. let pages = parseInt(result["record_count"] / 20);
  149. for (let index = 0; index < pages; index++) {
  150. html += "<li >" + (index + 1) + "</li> ";
  151. }
  152. }
  153. html += "</ul>";
  154. return html;
  155. }
  156. function onWordFilterStart() {
  157. $(".case_item").children().find(".filter").show();
  158. $("#case_tools").children(".filter").show();
  159. $("#case_tools").children().find(".filter").show();
  160. $("#case_tools").children(".select_button").hide();
  161. }
  162. function filter_cancel() {
  163. $(".filter").hide();
  164. $("#case_tools").children(".select_button").show();
  165. }
  166. function search_filter() {}
  167. function search_book_filter(objid, type) {
  168. if (document.getElementById(objid).checked == true) {
  169. $("." + type).show();
  170. } else {
  171. $("." + type).hide();
  172. }
  173. }
  174. //选择需要过滤的书
  175. function book_select(bookid) {
  176. paliword_search(_key_word, _filter_word, [bookid]);
  177. }
  178. function book_search_filter() {
  179. let booklist = new Array();
  180. $(".booklist").each(function () {
  181. if ($(this).prop("checked")) {
  182. booklist.push($(this).attr("book"));
  183. }
  184. });
  185. book_filter_cancel();
  186. paliword_search(_key_word, _filter_word, booklist);
  187. }
  188. function onBookFilterStart() {
  189. $(".book_item").children().find(".filter").show();
  190. $("#book_tools").children(".filter").show();
  191. $("#book_tools").children().find(".filter").show();
  192. $("#book_tools").children(".select_button").hide();
  193. $(".book_tag_div").show();
  194. }
  195. function book_filter_cancel() {
  196. $(".filter").hide();
  197. $(".book_tag_div").hide();
  198. $("#book_tools").children(".select_button").show();
  199. }
  200. function search_pre_search(word) {
  201. $.get(
  202. "../search/paliword_sc.php",
  203. {
  204. op: "pre",
  205. key: word,
  206. },
  207. function (data) {
  208. let words = JSON.parse(data);
  209. let html = "";
  210. for (const iterator of words) {
  211. html += "<a href='../search/paliword.php?key=" + iterator.word + "'>";
  212. if (parseInt(iterator.bold) > 0) {
  213. html += "<span style='font-weight:700;'>";
  214. } else {
  215. html += "<span>";
  216. }
  217. html += iterator.word + "-" + iterator.count;
  218. html += "</span>";
  219. html += "</a>";
  220. }
  221. $("#pre_search_word_content").html(html);
  222. $("#pre_search_word_content").css("display", "block");
  223. $(document).one("click", function () {
  224. $("#pre_search_word_content").hide();
  225. });
  226. event.stopPropagation();
  227. }
  228. );
  229. }
  230. //以下为旧的函数
  231. function dict_bold_word_all_select() {
  232. var wordcount = $("#bold_word_count").val();
  233. for (var i = 0; i < wordcount; i++) {
  234. document.getElementById("bold_word_" + i).checked = document.getElementById("bold_all_word").checked;
  235. }
  236. dict_update_bold(0);
  237. }
  238. function dict_bold_word_select(id) {
  239. var wordcount = $("#bold_word_count").val();
  240. for (var i = 0; i < wordcount; i++) {
  241. document.getElementById("bold_word_" + i).checked = false;
  242. }
  243. document.getElementById("bold_word_" + id).checked = true;
  244. dict_update_bold(0);
  245. }
  246. function dict_bold_book_select(id) {
  247. var bookcount = $("#bold_book_count").val();
  248. for (var i = 0; i < bookcount; i++) {
  249. document.getElementById("bold_book_" + i).checked = false;
  250. }
  251. document.getElementById("bold_book_" + id).checked = true;
  252. dict_update_bold(0);
  253. }
  254. function dict_update_bold(currpage) {
  255. var wordlist = "(";
  256. var wordcount = $("#bold_word_count").val();
  257. for (var i = 0; i < wordcount; i++) {
  258. if (document.getElementById("bold_word_" + i).checked) {
  259. wordlist += "'" + $("#bold_word_" + i).val() + "',";
  260. }
  261. }
  262. wordlist = wordlist.slice(0, -1);
  263. wordlist += ")";
  264. var booklist = "(";
  265. var bookcount = $("#bold_book_count").val();
  266. for (var i = 0; i < bookcount; i++) {
  267. if (document.getElementById("bold_book_" + i).checked) {
  268. booklist += "'" + $("#bold_book_" + i).val() + "',";
  269. }
  270. }
  271. if (booklist.slice(-1) == ",") {
  272. booklist = booklist.slice(0, -1);
  273. }
  274. booklist += ")";
  275. $.get(
  276. "paliword_search.php",
  277. {
  278. op: "update",
  279. target: "bold",
  280. word: "",
  281. wordlist: wordlist,
  282. booklist: booklist,
  283. currpage: currpage,
  284. },
  285. function (data, status) {
  286. //alert("Data: " + data + "\nStatus: " + status);
  287. $("#dict_bold_right").html(data);
  288. $("#bold_book_list").html($("#bold_book_list_new").html());
  289. $("#bold_book_list_new").html("");
  290. }
  291. );
  292. }
  293. function search_search(word) {
  294. $("#pre_search_result").hide();
  295. $("#pre_search_result_1").hide();
  296. if (!localStorage.searchword) {
  297. localStorage.searchword = "";
  298. }
  299. let oldHistory = localStorage.searchword;
  300. let arrOldHistory = oldHistory.split(",");
  301. let isExist = false;
  302. for (let i = 0; i < arrOldHistory.length; i++) {
  303. if (arrOldHistory[i] == word) {
  304. isExist = true;
  305. }
  306. }
  307. if (!isExist) {
  308. localStorage.searchword = word + "," + oldHistory;
  309. }
  310. if (window.XMLHttpRequest) {
  311. // code for IE7, Firefox, Opera, etc.
  312. dict_search_xml_http = new XMLHttpRequest();
  313. } else if (window.ActiveXObject) {
  314. // code for IE6, IE5
  315. dict_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  316. }
  317. if (dict_search_xml_http != null) {
  318. dict_search_xml_http.onreadystatechange = dict_search_serverResponse;
  319. word = word.replace(/\+/g, "%2b");
  320. dict_search_xml_http.open("GET", "paliword_search.php?op=search&word=" + word, true);
  321. dict_search_xml_http.send();
  322. } else {
  323. alert("Your browser does not support XMLHTTP.");
  324. }
  325. }
  326. function dict_search_serverResponse() {
  327. if (dict_search_xml_http.readyState == 4) {
  328. // 4 = "loaded"
  329. if (dict_search_xml_http.status == 200) {
  330. // 200 = "OK"
  331. var serverText = dict_search_xml_http.responseText;
  332. dict_result = document.getElementById("dict_ref_search_result");
  333. if (dict_result) {
  334. dict_result.innerHTML = serverText;
  335. $("#index_list").hide();
  336. $("#dict_ref_dict_link").html($("#dictlist").html());
  337. $("#dictlist").html("");
  338. }
  339. //$("#dict_type").html($("#real_dict_tab").html());
  340. } else {
  341. alert(dict_pre_search_xml_http.statusText, 0);
  342. }
  343. }
  344. }
  345. /*
  346. var dict_pre_search_xml_http = null;
  347. function search_pre_search(word) {
  348. if (dict_pre_searching == true) {
  349. return;
  350. }
  351. dict_pre_searching = true;
  352. dict_pre_search_curr_word = word;
  353. if (window.XMLHttpRequest) {
  354. // code for IE7, Firefox, Opera, etc.
  355. dict_pre_search_xml_http = new XMLHttpRequest();
  356. } else if (window.ActiveXObject) {
  357. // code for IE6, IE5
  358. dict_pre_search_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
  359. }
  360. if (dict_pre_search_xml_http != null) {
  361. dict_pre_search_xml_http.onreadystatechange = dict_pre_search_serverResponse;
  362. dict_pre_search_xml_http.open("GET", "paliword_search.php?op=pre&word=" + word, true);
  363. dict_pre_search_xml_http.send();
  364. } else {
  365. alert("Your browser does not support XMLHTTP.");
  366. }
  367. }
  368. */
  369. function dict_pre_search_serverResponse() {
  370. if (dict_pre_search_xml_http.readyState == 4) {
  371. // 4 = "loaded"
  372. if (dict_pre_search_xml_http.status == 200) {
  373. // 200 = "OK"
  374. var serverText = dict_pre_search_xml_http.responseText;
  375. $("#pre_search_word_content").html(serverText);
  376. } else {
  377. alert(dict_pre_search_xml_http.statusText, 0);
  378. }
  379. dict_pre_searching = false;
  380. var newword = document.getElementById("dict_ref_search_input").value;
  381. if (newword != dict_pre_search_curr_word) {
  382. search_pre_search(newword);
  383. }
  384. }
  385. }
  386. function dict_pre_word_click(word) {
  387. $("#pre_search_result").hide();
  388. $("#pre_search_result_1").hide();
  389. let inputSearch = $("#dict_ref_search_input").val();
  390. let arrSearch = inputSearch.split(" ");
  391. arrSearch[arrSearch.length - 1] = word;
  392. let strSearchWord = arrSearch.join(" ");
  393. $("#dict_ref_search_input").val(strSearchWord);
  394. $("#dict_ref_search_input_1").val(strSearchWord);
  395. search_search(word);
  396. }
  397. function dict_input_change(obj) {
  398. search_pre_search(obj.value);
  399. }
  400. function search_show_history() {
  401. if (!localStorage.searchword) {
  402. localStorage.searchword = "";
  403. }
  404. var arrHistory = localStorage.searchword.split(",");
  405. var strHistory = "";
  406. if (arrHistory.length > 0) {
  407. strHistory += '<a onclick="cls_word_search_history()">清空历史记录</a>';
  408. }
  409. const max_history_len = 20;
  410. let history_len = 0;
  411. if (arrHistory.length > max_history_len) {
  412. history_len = max_history_len;
  413. } else {
  414. history_len = arrHistory.length;
  415. }
  416. for (var i = 0; i < history_len; i++) {
  417. var word = arrHistory[i];
  418. strHistory += "<div class='dict_word_list'>";
  419. strHistory += "<a onclick='dict_pre_word_click(\"" + word + "\")'>" + word + "</a>";
  420. strHistory += "</div>";
  421. }
  422. $("#search_histray").html(strHistory);
  423. }
  424. function search_input_onfocus() {
  425. if ($("#dict_ref_search_input").val() == "") {
  426. //search_show_history();
  427. }
  428. }
  429. function search_input_keyup(e, obj) {
  430. var keynum;
  431. var keychar;
  432. var numcheck;
  433. if ($("#dict_ref_search_input").val() == "") {
  434. //search_show_history();
  435. $("#pre_search_result").hide();
  436. $("#pre_search_result_1").hide();
  437. return;
  438. }
  439. if (window.event) {
  440. // IE
  441. keynum = e.keyCode;
  442. } else if (e.which) {
  443. // Netscape/Firefox/Opera
  444. keynum = e.which;
  445. }
  446. var keychar = String.fromCharCode(keynum);
  447. if (keynum == 13) {
  448. //search_search(obj.value);
  449. window.location.assign("../search/paliword.php?key=" + obj.value);
  450. } else {
  451. if (obj.value.indexOf(" ") >= 0) {
  452. //search_pre_sent(obj.value);
  453. } else {
  454. $("#pre_search_sent").hide();
  455. }
  456. $("#pre_search_result").show();
  457. $("#pre_search_result_1").show();
  458. search_pre_search(obj.value);
  459. }
  460. }
  461. function search_pre_sent(word) {
  462. pali_sent_get_word(word, function (result) {
  463. let html = "";
  464. try {
  465. let arrResult = JSON.parse(result);
  466. for (x in arrResult) {
  467. html += arrResult[x].text + "<br>";
  468. }
  469. $("#pre_search_sent_title_right").html("总共" + arrResult.lenght);
  470. $("#pre_search_sent_content").html(html);
  471. $("#pre_search_sent").show();
  472. } catch (e) {
  473. console.error(e.message);
  474. }
  475. });
  476. }
  477. function cls_word_search_history() {
  478. localStorage.searchword = "";
  479. $("#dict_ref_search_result").html("");
  480. }
  481. function search_edit_now(book, para, title) {
  482. var res_list = new Array();
  483. res_list.push({
  484. type: "1",
  485. album_id: "-1",
  486. book: book,
  487. parNum: para,
  488. parlist: para,
  489. title: title + "-" + para,
  490. });
  491. res_list.push({
  492. type: "6",
  493. album_id: "-1",
  494. book: book,
  495. parNum: para,
  496. parlist: para,
  497. title: title + "-" + para,
  498. });
  499. var res_data = JSON.stringify(res_list);
  500. window.open("../studio/project.php?op=create&data=" + res_data, "_blank");
  501. }