paliword.js 16 KB

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