wiki.js 9.8 KB

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