wiki.js 9.8 KB

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