paliword.js 15 KB

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