module_function.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Modle Init.
  3. * public
  4. * @param param1 (type)
  5. *
  6. * Example usage:
  7. * @code
  8. * @endcode
  9. */
  10. function editor_layout_init() {}
  11. function layoutWordHeadCode(showTo, obj) {
  12. menu_view_script(showTo, obj.value);
  13. }
  14. function menu_view_script(showto, code) {
  15. var xAllWord = gXmlBookDataBody.getElementsByTagName("word");
  16. if (showto == 0 && code == "org") {
  17. for (iWord = 0; iWord < xAllWord.length; iWord++) {
  18. wordId = getNodeText(xAllWord[iWord], "id");
  19. xDiv = document.getElementById("wb" + wordId);
  20. xPali1 = xDiv.getElementsByClassName("paliword1")[0];
  21. xPali1.innerHTML = getNodeText(xAllWord[iWord], "pali");
  22. }
  23. return;
  24. }
  25. if (showto == 1) {
  26. if (code == "none") {
  27. $(".paliword2").css("display", "none");
  28. return;
  29. } else {
  30. $(".paliword2").css("display", "block");
  31. }
  32. }
  33. var xmlHttp = null;
  34. var xmlText = "";
  35. var xmlScript = null;
  36. if (window.XMLHttpRequest) {
  37. // code for IE7, Firefox, Opera, etc.
  38. xmlHttp = new XMLHttpRequest();
  39. } else if (window.ActiveXObject) {
  40. // code for IE6, IE5
  41. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  42. }
  43. if (xmlHttp != null) {
  44. var d = new Date();
  45. var strLink = "./spt_get.php?code=" + code;
  46. xmlHttp.open("GET", strLink, false);
  47. xmlHttp.send(null);
  48. xmlText = xmlHttp.responseText;
  49. //xmlDict=xmlHttp.responseXML;
  50. } else {
  51. alert("Your browser does not support XMLHTTP.");
  52. }
  53. if (window.DOMParser) {
  54. parser = new DOMParser();
  55. xmlScript = parser.parseFromString(xmlText, "text/xml");
  56. } // Internet Explorer
  57. else {
  58. xmlScript = new ActiveXObject("Microsoft.XMLDOM");
  59. xmlScript.async = "false";
  60. xmlScript.loadXML(xmlText);
  61. }
  62. var arrPaliWords = "";
  63. var xScriptWord = xmlScript.getElementsByTagName("word");
  64. var xPaliWords = document.getElementsByClassName("paliword");
  65. for (iWord = 0; iWord < xAllWord.length; iWord++) {
  66. arrPaliWords = arrPaliWords + "$" + getNodeText(xAllWord[iWord], "real");
  67. }
  68. for (i = 0; i < xScriptWord.length; i++) {
  69. var src = getNodeText(xScriptWord[i], "src");
  70. var dest = getNodeText(xScriptWord[i], "dest");
  71. eval("arrPaliWords = arrPaliWords.replace(/" + src + "/g, dest);");
  72. }
  73. // document.getElementById("scriptinner").innerHTML=arrPaliWords;
  74. var arrDestWords = arrPaliWords.split("$");
  75. for (iWord = 0; iWord < xAllWord.length; iWord++) {
  76. wordId = getNodeText(xAllWord[iWord], "id");
  77. xDiv = document.getElementById("wb" + wordId);
  78. if (xDiv) {
  79. if (showto == 0) {
  80. xPali = xDiv.getElementsByClassName("paliword1")[0];
  81. } else {
  82. xPali = xDiv.getElementsByClassName("paliword2")[0];
  83. }
  84. if (arrDestWords[iWord + 1].length > 0) {
  85. xPali.innerHTML = arrDestWords[iWord + 1];
  86. } else {
  87. xPali.innerHTML = getNodeText(xAllWord[iWord], "pali");
  88. }
  89. }
  90. }
  91. if (xmlScript == null) {
  92. alert("error:can not load dict.");
  93. return;
  94. }
  95. }
  96. function editro_layout_loadStyle() {
  97. var strStyle = getNodeText(gXmlBookDataHead, "style");
  98. document.getElementById("id_layout_style").value = strStyle;
  99. document.getElementById("mycss").innerHTML = strStyle;
  100. }
  101. function editor_layout_applyNewStyle() {
  102. var strStyle = document.getElementById("id_layout_style").value;
  103. document.getElementById("mycss").innerHTML = strStyle;
  104. setNodeText(gXmlBookDataHead, "style", strStyle);
  105. }
  106. //自动将逐词译段落切分为句子
  107. function layout_wbw_auto_cut() {
  108. var xBlock = gXmlBookDataBody.getElementsByTagName("block");
  109. for (var iBlock = 0; iBlock < xBlock.length; iBlock++) {
  110. xmlParInfo = xBlock[iBlock].getElementsByTagName("info")[0];
  111. xmlParData = xBlock[iBlock].getElementsByTagName("data")[0];
  112. var mId = getNodeText(xmlParInfo, "id");
  113. var par_num = getNodeText(xmlParInfo, "paragraph");
  114. var type = getNodeText(xmlParInfo, "type");
  115. if (type == "wbw") {
  116. var splited = getNodeText(xmlParInfo, "splited");
  117. if (splited != 1) {
  118. var Note_Mark = 0;
  119. var sent_gramma_i = 0;
  120. var word_length_count = 0;
  121. var sent_num = 0;
  122. var arr_Para_ID = new Array();
  123. var allWord = xmlParData.getElementsByTagName("word");
  124. for (var iWord = 0; iWord < allWord.length; iWord++) {
  125. var wID = getNodeText(allWord[iWord], "id");
  126. var wPali = getNodeText(allWord[iWord], "pali");
  127. var wReal = getNodeText(allWord[iWord], "real");
  128. var wType = getNodeText(allWord[iWord], "type");
  129. var wGramma = getNodeText(allWord[iWord], "gramma");
  130. var wCase = getNodeText(allWord[iWord], "case");
  131. var wUn = getNodeText(allWord[iWord], "un");
  132. var wStyle = getNodeText(allWord[iWord], "style");
  133. if ((wType == "" || wType == "?") && wCase != "") {
  134. wType = wCase.split("#")[0];
  135. }
  136. word_length_count += wPali.length;
  137. if (iWord >= 1) {
  138. var pre_pali_spell = getNodeText(allWord[iWord - 1], "pali");
  139. var pre_pali_type = getNodeText(allWord[iWord - 1], "type");
  140. var pre_pali_Gramma = getNodeText(allWord[iWord - 1], "gramma");
  141. var pre_pali_Case = getNodeText(allWord[iWord - 1], "case");
  142. if (pre_pali_type == "" && pre_pali_Case != "") {
  143. pre_pali_type = pre_pali_Case.split("#")[0];
  144. }
  145. if (pre_pali_Case != "" && pre_pali_Case.lastIndexOf("$") != -1) {
  146. var pre_case_array = pre_pali_Case.split("$");
  147. pre_pali_Case = pre_case_array[pre_case_array.length - 1];
  148. }
  149. }
  150. if (iWord + 2 <= allWord.length) {
  151. var next_pali_spell = getNodeText(allWord[iWord + 1], "pali");
  152. var next_pali_type = getNodeText(allWord[iWord + 1], "type");
  153. var next_pali_Gramma = getNodeText(allWord[iWord + 1], "gramma");
  154. var next_pali_Case = getNodeText(allWord[iWord + 1], "case");
  155. if (next_pali_type == "" && next_pali_Case != "") {
  156. next_pali_type = next_pali_Case.split("#")[0];
  157. }
  158. if (next_pali_Case != "" && next_pali_Case.lastIndexOf("$") != -1) {
  159. var next_case_array = next_pali_Case.split("$");
  160. next_pali_Case = next_case_array[next_case_array.length - 1];
  161. }
  162. }
  163. if (next_pali_spell == "(") {
  164. Note_Mark = 1;
  165. } else if (pre_pali_spell == ")" && Note_Mark == 1) {
  166. Note_Mark = 0;
  167. } else {
  168. }
  169. var isEndOfSen = false;
  170. if (
  171. wPali == "." &&
  172. iWord >= 1 &&
  173. isNaN(pre_pali_spell) &&
  174. iWord != allWord.length - 1 &&
  175. Note_Mark == 0
  176. ) {
  177. //以.結尾且非註釋
  178. if (next_pali_spell != "(") {
  179. isEndOfSen = true;
  180. }
  181. } else if (
  182. /*else if(wPali=="," && iWord>=1 && isNaN(pre_pali_spell) && iWord!=allWord.length-1 && pre_pali_type==".v." && Note_Mark==0){
  183. isEndOfSen=true;
  184. }导致自动匹配前后,句子切分不一致,注释*/
  185. wPali == "–" &&
  186. allWord.length >= iWord + 2 &&
  187. next_pali_spell == "‘" &&
  188. iWord != allWord.length - 1 &&
  189. Note_Mark == 0
  190. ) {
  191. isEndOfSen = true;
  192. } else if (allWord.length >= iWord + 2 && iWord != allWord.length - 1 && Note_Mark == 0) {
  193. //以!或?或;結尾
  194. if (/*wPali=="!" || */ wPali == ";" || wPali == "?") {
  195. if (next_pali_spell != "(") {
  196. isEndOfSen = true;
  197. }
  198. }
  199. }
  200. if (isEndOfSen == true) {
  201. var wEnter = getNodeText(allWord[iWord], "enter");
  202. if (wEnter == "" || wEnter == 0) {
  203. setNodeText(allWord[iWord], "enter", "1");
  204. }
  205. var sent_ID = "sent_" + par_num + "_" + sent_num;
  206. sent_num += 1;
  207. word_length_count = 0;
  208. sent_gramma_i = 0;
  209. arr_Para_ID.push(wID);
  210. }
  211. if (wPali == ",") {
  212. if (next_pali_Case.lastIndexOf(".voc.") != -1 || pre_pali_Case.lastIndexOf(".voc.") != -1) {
  213. sent_gramma_i += 0;
  214. } else {
  215. sent_gramma_i += 1;
  216. }
  217. }
  218. if (wType == ".v:ind." && allWord.length >= iWord + 2 && next_pali_spell != ",") {
  219. sent_gramma_i += 1;
  220. } else if (
  221. wType == ".v." &&
  222. allWord.length >= iWord + 2 &&
  223. next_pali_spell != "." &&
  224. next_pali_spell != ","
  225. ) {
  226. sent_gramma_i += 1;
  227. }
  228. } //段落结束
  229. //重绘
  230. //_display_sbs=1;
  231. //updateWordParBlockInner(xBlock[iBlock]);
  232. var sent_ID = "sent_" + par_num + "_" + sent_num;
  233. arr_Para_ID.push(wID);
  234. arr_par_sent_num.push(sent_ID);
  235. g_arr_Para_ID[par_num] = arr_Para_ID;
  236. //设置已经切分标志
  237. setNodeText(xmlParInfo, "splited", "1");
  238. }
  239. }
  240. }
  241. }
  242. //channel显示隐藏
  243. function channelDisplay(obj) {
  244. let id = $(obj).attr("channel_id");
  245. $(".trans_text_block[channel_id='" + id + "']").toggle();
  246. let allLen = $(obj).parent().parent().children("li").length;
  247. let checkLen = $(obj).parent().parent().children("li").children("input:checked").length;
  248. if(checkLen==0){
  249. $("#layout_channel_display_all").prop("checked",false);
  250. }else if(allLen===checkLen){
  251. $("#layout_channel_display_all").prop("checked",true);
  252. }else{
  253. $("#layout_channel_display_all").prop({checked:false,indeterminate:true});
  254. }
  255. }
  256. //全选或全不选
  257. function channelDisplayAll(obj) {
  258. let all = $(obj).prop("checked");
  259. if(all){
  260. $("#layout_channel_display").children("li").children("input").prop("checked",true);
  261. $(".trans_text_block").show();
  262. }else{
  263. $("#layout_channel_display").children("li").children("input").prop("checked",false);
  264. $(".trans_text_block").hide();
  265. }
  266. }
  267. function renderChannelList(){
  268. let html ="";
  269. html += "<div>";
  270. html +="<button onclick='renderChannelList()'>";
  271. html += "<svg class='icon' style='fill: var(--box-bg-color1)'>";
  272. html += "<use xlink:href='../../node_modules/bootstrap-icons/bootstrap-icons.svg#arrow-clockwise'>";
  273. html += "</svg>" ;
  274. html += gLocal.gui.refresh;
  275. html +="</button>";
  276. html +="</div>";
  277. html += "<input type='checkbox' id='layout_channel_display_all' checked channel_id='-1' onclick=\"channelDisplayAll(this)\" />全选</li>"
  278. html +="<ul id='layout_channel_display'>";
  279. html += "<li><input type='checkbox' checked channel_id='0' onclick=\"channelDisplay(this)\" />其他</li>"
  280. if (_my_channal != null) {
  281. for (const iterator of _my_channal) {
  282. html += "<li><input type='checkbox' checked channel_id='"+iterator.id+"' onclick=\"channelDisplay(this)\" />"+iterator.name+"</li>"
  283. }
  284. html +="</ul>";
  285. $("#layout_channel").html(html);
  286. }
  287. }