wiki.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. var _id = "";
  2. var _word = "";
  3. var _channel = "";
  4. var _lang = "";
  5. var _author = "";
  6. var _active = "";
  7. var _term_list;
  8. function wiki_index_init() {}
  9. function term_render_word_to_div(strWord,eDiv) {
  10. let word = [{ pali: strWord, channal: "", editor: "", lang: "" }];
  11. $.post(
  12. "../term/term_get.php",
  13. {
  14. words: JSON.stringify(word),
  15. },
  16. function (data, status) {
  17. let html = "";
  18. if (status == "success") {
  19. try {
  20. let result = JSON.parse(data);
  21. if (result.length > 0) {
  22. _term_list = result;
  23. //生成头部信息
  24. let type = new Array();
  25. let authors = new Array();
  26. //计算所有贡献者
  27. for (const iterator of result) {
  28. if (iterator.tag == "") {
  29. iterator.tag = "_null_";
  30. }
  31. if (type[iterator.tag] == null) {
  32. type[iterator.tag] = new Array();
  33. }
  34. type[iterator.tag].push(iterator.meaning);
  35. authors[iterator.owner] = iterator.user;
  36. }
  37. html += "<div class='term_word_head'>";
  38. html += "<div class='term_word_head_pali'>";
  39. html += result[0].word;
  40. $("#page_title").text(result[0].word + "-" + gLocal.gui.encyclopedia);
  41. html += "</div>";
  42. for (y in type) {
  43. html += "<div class='term_word_head_mean'>";
  44. if (y != "_null_") {
  45. html += y + ":";
  46. }
  47. for (k in type[y]) {
  48. html += type[y][k];
  49. }
  50. html += "</div>";
  51. }
  52. html += "<div class='term_word_head_authors'>" + gLocal.gui.contributor + ":";
  53. for (y in authors) {
  54. if (authors[y].nickname != "") {
  55. html += '<a onclick="">' + authors[y].nickname + "</a> ";
  56. } else {
  57. html += '<a onclick="">' + y + "</a> ";
  58. }
  59. }
  60. html += "</div>";
  61. html += "</div>";
  62. $("#wiki_head").html(html);
  63. // end of term_word_head
  64. html = "";
  65. html += "<div id='term_list_div' style='display:flex;'>";
  66. html += "<div id='term_list'>";
  67. for (const iterator of result) {
  68. if (iterator.tag == "_null_") {
  69. iterator.tag = "";
  70. }
  71. html += "<div class='term_block'>";
  72. html += "<div class='term_block_bar'>";
  73. html += "<div class='term_block_bar_left'>";
  74. html += "<div class='term_block_bar_left_icon'>";
  75. html += iterator.user.nickname.slice(0, 1);
  76. html += "</div>";
  77. html += "<div class='term_block_bar_left_info'>";
  78. html += "<div class='term_author'>" + iterator.user.nickname + "</div>";
  79. html += "<div class='term_meaning'>" + iterator.meaning;
  80. if (iterator.tag != "_null_") {
  81. html += "<span class='term_tag'>" + iterator.tag + "</span>";
  82. }
  83. html += "</div>";
  84. html += "</div>";
  85. html += "</div>";
  86. html += "<div class='term_block_bar_right'>";
  87. html += "<span>";
  88. if (!iterator.readonly) {
  89. html +=
  90. "<button class='icon_btn' onclick=\"wiki_term_edit('" +
  91. iterator.guid +
  92. "')\">" +
  93. gLocal.gui.edit +
  94. "</button>";
  95. }
  96. html += "<button class='icon_btn'><a href='../article/index.php?view=term&id="+iterator.guid+"&display=sent&mode=edit' target='_blank'>" + gLocal.gui.translate + "</a></button>";
  97. //TODO 增加点赞按钮
  98. //html += "<button class='icon_btn'><a href='#'>" + gLocal.gui.like + "</a></button>";
  99. html += "</span>";
  100. html += "</div>";
  101. html += "</div>";
  102. //term_block_bar 结束
  103. html +=
  104. "<div class='term_note' guid='" +
  105. iterator.guid +
  106. "'>" +
  107. note_init(iterator.note) +
  108. "</div>";
  109. html += "<div class='term_edit' id='term_edit_" + iterator.guid + "' ></div>";
  110. //html += "</div>";
  111. }
  112. html += "</div>";
  113. //end of right
  114. html += "</div>";
  115. // end of term_list_div
  116. } else {
  117. if (_active != "new"){
  118. html = "词条尚未创建 <a href='./wiki.php?word="+strWord+"&active=new'>现在创建</a>";
  119. }
  120. else{
  121. html = "无";
  122. }
  123. }
  124. $("#"+eDiv).html(html);
  125. note_refresh_new();
  126. document.title = result[0].word + "[" + result[0].meaning + "]-圣典百科";
  127. } catch (e) {
  128. console.error("term_render_word_to_div:" + e + " data:" + data);
  129. }
  130. } else {
  131. console.error("term error:" + data);
  132. }
  133. }
  134. );
  135. }
  136. function wiki_term_edit(id) {
  137. for (const iterator of _term_list) {
  138. if (iterator.guid == id) {
  139. $("#term_edit_" + id).html(render_term_form(iterator));
  140. $("#term_edit_" + id).show();
  141. $(".term_note[guid='" + id + "']").hide();
  142. return id;
  143. }
  144. }
  145. return false;
  146. }
  147. function term_edit_cancel() {
  148. $(".term_edit").hide();
  149. $(".term_edit").html("");
  150. $(".term_note").show();
  151. }
  152. function render_term_form(item) {
  153. let html = "";
  154. html += "<form id='form_term'>";
  155. html += '<input type="hidden" name="id" value="' + item.guid + '" />';
  156. html += "<ul>";
  157. html += "<li ><span class='field'>" + gLocal.gui.pali_word + "</span>";
  158. html +=
  159. '<span class="input"><input id="form_word" type="input" name="word" value="' +
  160. item.word +
  161. '" placeholder="' +
  162. gLocal.gui.required +
  163. '"/></span></li>';
  164. html += "<li ><span class='field'>" + gLocal.gui.first_choice_word + "</span>";
  165. html +=
  166. '<span class="input"><input id="form_mean" type="input" name="mean" value="' +
  167. item.meaning +
  168. '" placeholder="' +
  169. gLocal.gui.required +
  170. '"/></span></li>';
  171. html += "<li ><span class='field'>" + gLocal.gui.other_meaning + "</span>";
  172. html +=
  173. '<span class="input"><input type="input" name="mean2" value="' +
  174. item.other_meaning +
  175. '" placeholder="' +
  176. gLocal.gui.optional +
  177. '"/></span></li>';
  178. html += "<li ><span class='field'>" + gLocal.gui.tag + "</span>";
  179. html +=
  180. '<span class="input"><input type="input" name="tag" value="' +
  181. item.tag +
  182. '" placeholder="' +
  183. gLocal.gui.optional +
  184. '"/></span></li>';
  185. html += "<li ><span class='field'>" + gLocal.gui.channel + "</span>";
  186. html +=
  187. '<span class="input"><input type="input" name="channal" value="' +
  188. item.channel +
  189. '" placeholder="' +
  190. gLocal.gui.optional +
  191. '"/></span></li>';
  192. html += "<li ><span class='field'>" + gLocal.gui.language + "</span>";
  193. html +=
  194. '<span class="input"><input id="form_lang" type="input" name="language" value="' +
  195. item.language +
  196. '" placeholder="' +
  197. gLocal.gui.required +
  198. '"/></span></li>';
  199. html += "<li ><span class='field'>" + gLocal.gui.note + "</span>";
  200. html += "<span class='input'><textarea name='note'>" + item.note + "</textarea></span></li>";
  201. html += "</ul>";
  202. html += "</form>";
  203. html += "<button onclick='term_save()'>" + gLocal.gui.save + "</button>";
  204. if (item.guid != "") {
  205. html += "<button onclick='term_edit_cancel()'>" + gLocal.gui.cancel + "</button>";
  206. }
  207. return html;
  208. }
  209. function term_render_new_word(title, word) {
  210. let html = "";
  211. html += "<div class='term_word_head_pali'>" + title + "</div>";
  212. $("#wiki_head").html(html);
  213. html = render_term_form({
  214. guid: "",
  215. word: word,
  216. meaning: "",
  217. other_meaning: "",
  218. owner: "",
  219. channel: _channel,
  220. language: "",
  221. tag: "",
  222. note: "",
  223. });
  224. html += "<h2 style='border-top: 1px solid var(--border-line-color);padding-top: 0.5em;'>其他解释</h2>"
  225. html += "<div id='term_list'>loading……</div>"
  226. $("#wiki_body_left").html(html);
  227. term_render_word_to_div(word,"term_list");
  228. }
  229. function term_save() {
  230. if ($("#form_word").val() == "") {
  231. alert(gLocal.gui.pali_word + " 不能为空");
  232. return;
  233. }
  234. if ($("#form_mean").val() == "") {
  235. alert(gLocal.gui.first_choice_word + "不能为空");
  236. return;
  237. }
  238. if ($("#form_lang").val() == "") {
  239. alert(gLocal.gui.language + "不能为空");
  240. return;
  241. }
  242. $.ajax({
  243. type: "POST", //方法类型
  244. dataType: "json", //预期服务器返回的数据类型
  245. url: "../term/term_post.php", //url
  246. data: $("#form_term").serialize(),
  247. success: function (result) {
  248. console.log(result); //打印服务端返回的数据(调试用)
  249. if (result.status == 0) {
  250. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  251. window.location.assign("../wiki/wiki.php?word=" + result.message);
  252. } else {
  253. alert("error:" + result.message);
  254. }
  255. },
  256. error: function (data, status) {
  257. alert("异常!" + data.responseText);
  258. switch (status) {
  259. case "timeout":
  260. break;
  261. case "error":
  262. break;
  263. case "notmodified":
  264. break;
  265. case "parsererror":
  266. break;
  267. default:
  268. break;
  269. }
  270. },
  271. });
  272. }
  273. function wiki_load_id(guid) {
  274. note_create();
  275. note_lookup_guid_json(guid, "wiki_body_left");
  276. }
  277. function wiki_load_word(word) {
  278. note_create();
  279. if (_active == "new") {
  280. term_render_new_word(gLocal.gui.new_technic_term, word);
  281. }else{
  282. term_render_word_to_div(word,"wiki_body_left");
  283. }
  284. }
  285. function wiki_goto_word(guid, strWord) {
  286. window.open("wiki.php?word=" + strWord, "_blank");
  287. }
  288. function wiki_word_loaded(wordlist) {
  289. $("#doc_title").text(wordlist[0].word + "[" + wordlist[0].meaning + "]-圣典百科");
  290. }
  291. function term_show_win(guid, word) {
  292. window.location.assign("wiki.php?word=" + word);
  293. }
  294. function wiki_search_keyup(e, obj) {
  295. var keynum;
  296. var keychar;
  297. var numcheck;
  298. if ($("#wiki_search_input").val() == "") {
  299. $("#search_result").html("");
  300. return;
  301. }
  302. if (window.event) {
  303. // IE
  304. keynum = e.keyCode;
  305. } else if (e.which) {
  306. // Netscape/Firefox/Opera
  307. keynum = e.which;
  308. }
  309. var keychar = String.fromCharCode(keynum);
  310. if (keynum == 13) {
  311. window.location.assign("wiki.php?word=" + obj.value);
  312. } else {
  313. wiki_pre_search(obj.value);
  314. }
  315. }
  316. function wiki_pre_search(keyword) {
  317. $.get(
  318. "../term/term.php",
  319. {
  320. op: "pre",
  321. word: keyword,
  322. format: "json",
  323. },
  324. function (data, status) {
  325. let result = JSON.parse(data);
  326. let html = "<ul class='wiki_search_list'>";
  327. if (result.length > 0) {
  328. for (x in result) {
  329. html +=
  330. "<li><a href='./wiki.php?op=get&word=" +
  331. result[x].word +
  332. "'>" +
  333. result[x].word +
  334. "[" +
  335. result[x].meaning +
  336. "]</a></li>";
  337. }
  338. }
  339. html += "</ul>";
  340. $("#search_result").html(html);
  341. }
  342. );
  343. }
  344. function set_channal(channalid) {
  345. location.assign("../wiki/wiki.php?word=" + _word + "&channal=" + channalid);
  346. }