2
0

wiki.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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='#'>" + gLocal.gui.like + "</a></button>";
  97. html +=
  98. "<button class='icon_btn'><a href='#'>" + gLocal.gui.favorite + "</a></button></span>";
  99. html += "</div>";
  100. html += "</div>";
  101. //term_block_bar 结束
  102. html +=
  103. "<div class='term_note' guid='" +
  104. iterator.guid +
  105. "'>" +
  106. note_init(iterator.note) +
  107. "</div>";
  108. html += "<div class='term_edit' id='term_edit_" + iterator.guid + "' ></div>";
  109. //html += "</div>";
  110. }
  111. html += "</div>";
  112. //end of right
  113. html += "</div>";
  114. // end of term_list_div
  115. } else {
  116. if (_active != "new"){
  117. html = "词条尚未创建 <a href='./wiki.php?word="+strWord+"&active=new'>现在创建</a>";
  118. }
  119. else{
  120. html = "无";
  121. }
  122. }
  123. $("#"+eDiv).html(html);
  124. note_refresh_new();
  125. document.title = result[0].word + "[" + result[0].meaning + "]-圣典百科";
  126. } catch (e) {
  127. console.error("term_render_word_to_div:" + e + " data:" + data);
  128. }
  129. } else {
  130. console.error("term error:" + data);
  131. }
  132. }
  133. );
  134. }
  135. function wiki_term_edit(id) {
  136. for (const iterator of _term_list) {
  137. if (iterator.guid == id) {
  138. $("#term_edit_" + id).html(render_term_form(iterator));
  139. $("#term_edit_" + id).show();
  140. $(".term_note[guid='" + id + "']").hide();
  141. return id;
  142. }
  143. }
  144. return false;
  145. }
  146. function term_edit_cancel() {
  147. $(".term_edit").hide();
  148. $(".term_edit").html("");
  149. $(".term_note").show();
  150. }
  151. function render_term_form(item) {
  152. let html = "";
  153. html += "<form id='form_term'>";
  154. html += '<input type="hidden" name="id" value="' + item.guid + '" />';
  155. html += "<ul>";
  156. html += "<li ><span class='field'>" + gLocal.gui.pali_word + "</span>";
  157. html +=
  158. '<span class="input"><input id="form_word" type="input" name="word" value="' +
  159. item.word +
  160. '" placeholder="' +
  161. gLocal.gui.required +
  162. '"/></span></li>';
  163. html += "<li ><span class='field'>" + gLocal.gui.first_choice_word + "</span>";
  164. html +=
  165. '<span class="input"><input id="form_mean" type="input" name="mean" value="' +
  166. item.meaning +
  167. '" placeholder="' +
  168. gLocal.gui.required +
  169. '"/></span></li>';
  170. html += "<li ><span class='field'>" + gLocal.gui.other_meaning + "</span>";
  171. html +=
  172. '<span class="input"><input type="input" name="mean2" value="' +
  173. item.other_meaning +
  174. '" placeholder="' +
  175. gLocal.gui.optional +
  176. '"/></span></li>';
  177. html += "<li ><span class='field'>" + gLocal.gui.tag + "</span>";
  178. html +=
  179. '<span class="input"><input type="input" name="tag" value="' +
  180. item.tag +
  181. '" placeholder="' +
  182. gLocal.gui.optional +
  183. '"/></span></li>';
  184. html += "<li ><span class='field'>" + gLocal.gui.channel + "</span>";
  185. html +=
  186. '<span class="input"><input type="input" name="channal" value="' +
  187. item.channel +
  188. '" placeholder="' +
  189. gLocal.gui.optional +
  190. '"/></span></li>';
  191. html += "<li ><span class='field'>" + gLocal.gui.language + "</span>";
  192. html +=
  193. '<span class="input"><input id="form_lang" type="input" name="language" value="' +
  194. item.language +
  195. '" placeholder="' +
  196. gLocal.gui.required +
  197. '"/></span></li>';
  198. html += "<li ><span class='field'>" + gLocal.gui.note + "</span>";
  199. html += "<span class='input'><textarea name='note'>" + item.note + "</textarea></span></li>";
  200. html += "</ul>";
  201. html += "</form>";
  202. html += "<button onclick='term_save()'>" + gLocal.gui.save + "</button>";
  203. if (item.guid != "") {
  204. html += "<button onclick='term_edit_cancel()'>" + gLocal.gui.cancel + "</button>";
  205. }
  206. return html;
  207. }
  208. function term_render_new_word(title, word) {
  209. let html = "";
  210. html += "<div class='term_word_head_pali'>" + title + "</div>";
  211. $("#wiki_head").html(html);
  212. html = render_term_form({
  213. guid: "",
  214. word: word,
  215. meaning: "",
  216. other_meaning: "",
  217. owner: "",
  218. channel: _channel,
  219. language: "",
  220. tag: "",
  221. note: "",
  222. });
  223. html += "<h2 style='border-top: 1px solid var(--border-line-color);padding-top: 0.5em;'>其他解释</h2>"
  224. html += "<div id='term_list'>loading……</div>"
  225. $("#wiki_body_left").html(html);
  226. term_render_word_to_div(word,"term_list");
  227. }
  228. function term_save() {
  229. if ($("#form_word").val() == "") {
  230. alert(gLocal.gui.pali_word + " 不能为空");
  231. return;
  232. }
  233. if ($("#form_mean").val() == "") {
  234. alert(gLocal.gui.first_choice_word + "不能为空");
  235. return;
  236. }
  237. if ($("#form_lang").val() == "") {
  238. alert(gLocal.gui.language + "不能为空");
  239. return;
  240. }
  241. $.ajax({
  242. type: "POST", //方法类型
  243. dataType: "json", //预期服务器返回的数据类型
  244. url: "../term/term_post.php", //url
  245. data: $("#form_term").serialize(),
  246. success: function (result) {
  247. console.log(result); //打印服务端返回的数据(调试用)
  248. if (result.status == 0) {
  249. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  250. window.location.assign("../wiki/wiki.php?word=" + result.message);
  251. } else {
  252. alert("error:" + result.message);
  253. }
  254. },
  255. error: function (data, status) {
  256. alert("异常!" + data.responseText);
  257. switch (status) {
  258. case "timeout":
  259. break;
  260. case "error":
  261. break;
  262. case "notmodified":
  263. break;
  264. case "parsererror":
  265. break;
  266. default:
  267. break;
  268. }
  269. },
  270. });
  271. }
  272. function wiki_load_id(guid) {
  273. note_create();
  274. note_lookup_guid_json(guid, "wiki_body_left");
  275. }
  276. function wiki_load_word(word) {
  277. note_create();
  278. if (_active == "new") {
  279. term_render_new_word(gLocal.gui.new_technic_term, word);
  280. }else{
  281. term_render_word_to_div(word,"wiki_body_left");
  282. }
  283. }
  284. function wiki_goto_word(guid, strWord) {
  285. window.open("wiki.php?word=" + strWord, "_blank");
  286. }
  287. function wiki_word_loaded(wordlist) {
  288. $("#doc_title").text(wordlist[0].word + "[" + wordlist[0].meaning + "]-圣典百科");
  289. }
  290. function term_show_win(guid, word) {
  291. window.location.assign("wiki.php?word=" + word);
  292. }
  293. function wiki_search_keyup(e, obj) {
  294. var keynum;
  295. var keychar;
  296. var numcheck;
  297. if ($("#wiki_search_input").val() == "") {
  298. $("#search_result").html("");
  299. return;
  300. }
  301. if (window.event) {
  302. // IE
  303. keynum = e.keyCode;
  304. } else if (e.which) {
  305. // Netscape/Firefox/Opera
  306. keynum = e.which;
  307. }
  308. var keychar = String.fromCharCode(keynum);
  309. if (keynum == 13) {
  310. window.location.assign("wiki.php?word=" + obj.value);
  311. } else {
  312. wiki_pre_search(obj.value);
  313. }
  314. }
  315. function wiki_pre_search(keyword) {
  316. $.get(
  317. "../term/term.php",
  318. {
  319. op: "pre",
  320. word: keyword,
  321. format: "json",
  322. },
  323. function (data, status) {
  324. let result = JSON.parse(data);
  325. let html = "<ul class='wiki_search_list'>";
  326. if (result.length > 0) {
  327. for (x in result) {
  328. html +=
  329. "<li><a href='./wiki.php?op=get&word=" +
  330. result[x].word +
  331. "'>" +
  332. result[x].word +
  333. "[" +
  334. result[x].meaning +
  335. "]</a></li>";
  336. }
  337. }
  338. html += "</ul>";
  339. $("#search_result").html(html);
  340. }
  341. );
  342. }
  343. function set_channal(channalid) {
  344. location.assign("../wiki/wiki.php?word=" + _word + "&channal=" + channalid);
  345. }