index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. var new_word_list2=new Array();
  2. var dict_id=-1;
  3. var gCurrWordId=-1;
  4. function init(){
  5. $("#replace_table_main").load("replace_table/"+gDictId+"_main.txt");
  6. $("#replace_table_pali").load("replace_table/"+gDictId+"_pali.txt");
  7. $("#replace_table_type").load("replace_table/"+gDictId+"_type.txt");
  8. $("#replace_table_part").load("replace_table/"+gDictId+"_part.txt");
  9. }
  10. function mean_keyup(obj,id){
  11. var newmean=obj.value;
  12. $("#mean_list_"+id).html(render_mean_list(newmean));
  13. }
  14. function render_mean_list(strMean){
  15. var output="";
  16. var arrMean=strMean.split("$");
  17. for(var i in arrMean){
  18. output+="<div class='one_mean'>"+arrMean[i]+"<span>X</span></div>";
  19. }
  20. return(output);
  21. }
  22. function dict_changed(obj){
  23. var dict_id=obj.value;
  24. window.location.assign("index.php?dict_id="+dict_id);
  25. }
  26. function select_word(id){
  27. gCurrWordId=id;
  28. $("#org_data").load('./get_one_word.php?id='+id,function(responseTxt,statusTxt,xhr){
  29. if(statusTxt=="success"){
  30. var orgword=$("#word_org_text").html();
  31. $("#org_edit_text").val(split_word(orgword));
  32. org_edit_changed();
  33. }
  34. if(statusTxt=="error")
  35. alert("Error: "+xhr.status+": "+xhr.statusText);
  36. });
  37. }
  38. function refresh_word(){
  39. var orgword=$("#word_org_text").html();
  40. $("#org_edit_text").val(split_word(orgword));
  41. org_edit_changed();
  42. }
  43. function split_word(strIn){
  44. var output="w@"+strIn;
  45. var replace_table=$("#replace_table_main").val().split("\n");
  46. try{
  47. for(var x in replace_table){
  48. if(replace_table[x].replace(/\s/g,"").length>0){
  49. eval("output = output.replace("+replace_table[x]+");");
  50. }
  51. }
  52. }
  53. catch(e){
  54. notify(e.message);
  55. }
  56. return(output);
  57. }
  58. function word_obj_clone(obj){
  59. var new_word=create_word_obj();
  60. new_word.pali=obj.pali;
  61. new_word.type=obj.type;
  62. new_word.gramma=obj.gramma;
  63. new_word.parent=obj.parent;
  64. new_word.mean=obj.mean;
  65. new_word.note=obj.note;
  66. new_word.factor=obj.factor;
  67. new_word.factor_mean=obj.factor_mean;
  68. return(new_word);
  69. }
  70. function create_word_obj(){
  71. var new_word=new Object();
  72. new_word.pali="";
  73. new_word.type="";
  74. new_word.gramma="";
  75. new_word.parent="";
  76. new_word.mean="";
  77. new_word.note="";
  78. new_word.factor="";
  79. new_word.factor_mean="";
  80. //new_word.clone=word_obj_clone(new_word);
  81. return(new_word);
  82. }
  83. function org_edit_changed(){
  84. var word_string = document.getElementById("org_edit_text").value;
  85. var arrField=word_string.split("\n");
  86. var mather_word=new Array();
  87. var arrWord=new Array();
  88. var iCurrWord=-1;
  89. for(var x in arrField){
  90. var arrOne = arrField[x].split("@");
  91. switch(arrOne[0]){
  92. case "w":
  93. var new_word=create_word_obj();
  94. arrWord.push(new_word);
  95. iCurrWord=arrWord.length-1;
  96. if(arrOne[1].length>1 && mather_word==""){
  97. mather_word=arrOne[1].replace(/,/g,"$");
  98. }
  99. arrWord[iCurrWord].pali=arrOne[1].replace(/,/g,"$");
  100. if(arrWord[iCurrWord].pali.substring(0,1)=="-"){
  101. var cp=mather_word+arrWord[iCurrWord].pali;
  102. var arr_cp=cp.split(" ");
  103. arrWord[iCurrWord].pali=arr_cp[0]
  104. arrWord[iCurrWord].factor=arr_cp[0];
  105. if(arr_cp[1]){
  106. arrWord[iCurrWord].mean=arr_cp[1];
  107. }
  108. }
  109. if(arrWord[iCurrWord].pali[0]=="【"){
  110. var pali = arrWord[iCurrWord].pali;
  111. arrWord.splice(iCurrWord,1);
  112. var arr_word_case=pali.split("】");
  113. var type=arr_word_case[0];
  114. var arr_word=arr_word_case[1].split(",");
  115. for(var x in arr_word){
  116. var new_word=create_word_obj();
  117. new_word.pali=arr_word[x];
  118. new_word.type=type+"】";
  119. new_word.parent=mather_word;
  120. arrWord.push(new_word);
  121. iCurrWord=arrWord.length-1;
  122. }
  123. }
  124. if(arrWord[iCurrWord].pali.substring(0,1)=="{"){
  125. arrWord[iCurrWord].pali=mather_word;
  126. }
  127. break;
  128. case "c":
  129. arrWord[iCurrWord].type=arrOne[1];
  130. if(arrOne[1].indexOf(" の ")>=0){
  131. var arr_type=arrOne[1].split(" の ");
  132. arrWord[iCurrWord].type=arr_type[1];
  133. arrWord[iCurrWord].parent=arr_type[0];
  134. }
  135. break;
  136. case "g":
  137. arrWord[iCurrWord].gramma=arrOne[1];
  138. break;
  139. case "p":
  140. arrWord[iCurrWord].parent=arrOne[1];
  141. break;
  142. case "m":
  143. arrWord[iCurrWord].mean=arrOne[1].replace(/,/g,"$");
  144. break;
  145. case "n":
  146. arrWord[iCurrWord].note=arrOne[1];
  147. break;
  148. case "f":
  149. arrWord[iCurrWord].factor=arrOne[1];
  150. break;
  151. case "fm":
  152. arrWord[iCurrWord].factor_mean=arrOne[1];
  153. break;
  154. case "cw":
  155. arrWord[iCurrWord].pali=arrOne[1];
  156. arrWord[iCurrWord].parent=mather_word;
  157. break;
  158. }
  159. }
  160. //将一条记录包含多词头的 拆开
  161. var new_word_list=new Array();
  162. for(var row in arrWord){
  163. if(arrWord[row].pali.indexOf("$")>=0){
  164. var pali=arrWord[row].pali.split("$");
  165. for(var iWord in pali){
  166. var new_word=word_obj_clone(arrWord[row]);
  167. new_word.pali=pali[iWord];
  168. new_word_list.push(new_word);
  169. }
  170. }
  171. else{
  172. new_word_list.push(arrWord[row]);
  173. }
  174. }
  175. new_word_list2=new Array();
  176. for(var row in new_word_list){
  177. if(new_word_list[row].parent.indexOf("$")>=0){
  178. var wparent=new_word_list[row].parent.split("$");
  179. for(var iWord in wparent){
  180. var new_word=word_obj_clone(new_word_list[row]);
  181. new_word.parent=wparent[iWord];
  182. new_word_list2.push(new_word);
  183. }
  184. }
  185. else{
  186. new_word_list2.push(new_word_list[row]);
  187. }
  188. }
  189. //整理type
  190. for(var row in new_word_list2){
  191. if(new_word_list2[row].type=="" && new_word_list2[row].pali.slice(-2)=="ti"){
  192. new_word_list2[row].type=".v:base.";
  193. }
  194. new_word_list2[row].type+="#";
  195. var replace_table=$("#replace_table_type").val().split("\n");
  196. try{
  197. for(var x in replace_table){
  198. if(replace_table[x].replace(/\s/g,"").length>0){
  199. eval("new_word_list2[row].type = new_word_list2[row].type.replace("+replace_table[x]+");");
  200. }
  201. }
  202. }
  203. catch(e){
  204. notify(e.message);
  205. }
  206. var arrcase=new_word_list2[row].type.split("#");
  207. new_word_list2[row].type=arrcase[0];
  208. new_word_list2[row].gramma=arrcase[1];
  209. }
  210. var output ="<table>";
  211. output += "<tr>";
  212. output += "<th>pali</th>";
  213. output += "<th>type</th>";
  214. output += "<th>gramma</th>";
  215. output += "<th>parent</th>";
  216. output += "<th>mean</th>";
  217. output += "<th>note</th>";
  218. output += "<th>factor</th>";
  219. output += "</tr>";
  220. for(var row in new_word_list2){
  221. if(new_word_list2[row].pali[0]=="【"){
  222. //break;
  223. }
  224. output += "<tr>";
  225. output += "<td>";
  226. output += new_word_list2[row].pali;
  227. output += "</td>";
  228. output += "<td>";
  229. output += new_word_list2[row].type;
  230. output += "</td>";
  231. output += "<td>";
  232. output += new_word_list2[row].gramma;
  233. output += "</td>";
  234. output += "<td>";
  235. output += new_word_list2[row].parent;
  236. output += "</td>";
  237. output += "<td>";
  238. output += new_word_list2[row].mean;
  239. output += "</td>";
  240. output += "<td>";
  241. output += new_word_list2[row].note;
  242. output += "</td>";
  243. output += "<td>";
  244. output += new_word_list2[row].factor;
  245. output += "</td>";
  246. output += "</tr>";
  247. }
  248. output +="</table>";
  249. $("#word_table").html(output);
  250. }
  251. function res_word_selected(obj,word_id){
  252. gCurrWordId=word_id;
  253. select_word(word_id);
  254. $(".ref_word").removeClass("active");
  255. obj.classList.add("active");
  256. }
  257. function replace_table_show(obj){
  258. $(".replace_table").hide();
  259. $("#replace_table_"+obj.value).show();
  260. }
  261. function save(edit_status){
  262. var word_data=JSON.stringify(new_word_list2);
  263. $.post("./save.php",
  264. {
  265. dict_id:gDictId,
  266. word_id:gCurrWordId,
  267. word_status:edit_status,
  268. data:word_data
  269. },
  270. function(data,status){
  271. notify(data + "<br>Status: " + status);
  272. $("#word_"+gCurrWordId).removeClass("status_2 status_3 status_10");
  273. $("#word_"+gCurrWordId).addClass("status_"+edit_status);
  274. });
  275. }
  276. function save_replace_table(){
  277. $.post("./save_replace_table.php",
  278. {
  279. dict_id:gDictId,
  280. main:$("#replace_table_main").val(),
  281. pali:$("#replace_table_pali").val(),
  282. part:$("#replace_table_part").val(),
  283. type:$("#replace_table_type").val()
  284. },
  285. function(data,status){
  286. notify(data + "<br>Status: " + status);
  287. });
  288. }
  289. function notify(message,time=5000){
  290. $("#message_text").html(message);
  291. $("#message").slideDown();
  292. }
  293. function close_notify(){
  294. $("#message").slideUp();
  295. }
  296. function final_word_show_hide(){
  297. $("#final_word_body").slideToggle();
  298. }
  299. function goto_page(obj,dict_id,totle_page){
  300. var newpage=obj.value;
  301. if(newpage>=0 && newpage<totle_page){
  302. window.location.assign("./index.php?dict_id="+dict_id+"&page_no="+newpage);
  303. }
  304. }