vn.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. var g_is_mobile=false;
  2. var g_language="langrage_cn";
  3. //输出调试信息
  4. function debugOutput(str,level){
  5. str = "<p>"+str+"</p>";
  6. document.getElementById("id_debug_output").innerHTML = str + document.getElementById("id_debug_output").innerHTML;
  7. }
  8. function var_dump(str){
  9. getStyleClass("debug_info").style.display = "-webkit-flex";
  10. //getStyleClass("debug_info").style.opacity = "0.8";
  11. getStyleClass("debug_info").style.animation = "viewbug 2s";
  12. document.getElementById("debug").innerHTML = str;
  13. var t=setTimeout("clearDebugMsg()",2000);
  14. }
  15. function clearDebugMsg(){
  16. document.getElementById("debug").innerHTML = "";
  17. //getStyleClass("debug_info").style.opacity = "0";
  18. getStyleClass("debug_info").style.display = "none";
  19. }
  20. //页面初始字体大小 单位 %
  21. var iStartFontSize = 100;
  22. function setHitsVisibility(isVisible)
  23. {
  24. var c = getStyleClass('hit');
  25. if (isVisible)
  26. {
  27. c.style.backgroundColor = 'blue';
  28. c.style.color = 'white';
  29. }
  30. else
  31. {
  32. c.style.backgroundColor = 'white';
  33. c.style.color = 'black';
  34. }
  35. }
  36. function setPageColor(sColor)
  37. {
  38. var c = getStyleClass('mainbody');
  39. var cToc = getStyleClass('toc');
  40. switch(sColor){
  41. case 0:
  42. c.style.backgroundColor = '#FFFFFF';
  43. c.style.color = '#444444';
  44. cToc.style.backgroundColor = "#F5F5F5";
  45. cToc.style.color = '#444444';
  46. break;
  47. case 1:
  48. c.style.backgroundColor = '#ffead7';
  49. c.style.color = '#844200';
  50. cToc.style.backgroundColor = '#fff0e4';
  51. break;
  52. case 2:
  53. c.style.backgroundColor = '#262822';
  54. c.style.color = '#F6F7EE';
  55. cToc.style.backgroundColor = '#383B32';
  56. cToc.style.color = '#FFFFFF';
  57. break;
  58. }
  59. }
  60. //修改页面字体大小
  61. function setPageFontSize(fChange)
  62. {
  63. iStartFontSize = iStartFontSize * fChange;
  64. var myBody = document.getElementById("mbody");
  65. myBody.style.fontSize= iStartFontSize + "%";
  66. setCookie('fontsize',iStartFontSize,65)
  67. }
  68. function setFootnotesVisibility(isVisible)
  69. {
  70. getStyleClass('note').style.display = (isVisible ? 'inline' : 'none');
  71. }
  72. function setIdVisibility()
  73. {
  74. var isVisible = document.getElementById("B_Id").checked;
  75. getStyleClass('ID').style.display = (isVisible ? 'block' : 'none');
  76. }
  77. function setOrgVisibility()
  78. {
  79. var isVisible = document.getElementById("B_Org").checked;
  80. getStyleClass('org').style.display = (isVisible ? 'block' : 'none');
  81. }
  82. function setMeaningVisibility()
  83. {
  84. var isVisible = document.getElementById("B_Meaning").checked;
  85. getStyleClass('mean').style.display = (isVisible ? 'block' : 'none');
  86. }
  87. function setGrammaVisibility()
  88. {
  89. var isVisible = document.getElementById("B_Gramma").checked;
  90. getStyleClass('case').style.display = (isVisible ? 'block' : 'none');
  91. }
  92. //显示英译
  93. function setParTranEnVisibility()
  94. {
  95. var isVisible = document.getElementById("B_ParTranEn").checked;
  96. getStyleClass('tran_par_en').style.display = (isVisible ? 'block' : 'none');
  97. }
  98. //显示中译
  99. function setParTranCnVisibility()
  100. {
  101. var isVisible = document.getElementById("B_ParTranCn").checked;
  102. getStyleClass('tran_par_cn').style.display = (isVisible ? 'block' : 'none');
  103. }
  104. //显示段对译模式
  105. function setParTranShowMode()
  106. {
  107. var isVisible = document.getElementById("B_ParTranShowMode").checked;
  108. if(isVisible){ /* 上下对读 */
  109. getStyleClass('pali_par').style.width = "auto";
  110. getStyleClass('pali_par').style.float="none";
  111. getStyleClass('pali_par_gatha').style.width = "auto";
  112. getStyleClass('pali_par_gatha').style.float="none";
  113. //getStyleClass('tran_par').style.margin = "0";
  114. }
  115. else{ /* 左右对读 */
  116. getStyleClass('pali_par').style.width = "70%";
  117. getStyleClass('pali_par').style.float = "left";
  118. getStyleClass('pali_par_gatha').style.width = "50%";
  119. getStyleClass('pali_par_gatha').style.float = "left";
  120. //getStyleClass('tran_par').style.margin = "0 0 0 50%-220px";
  121. }
  122. }
  123. //显示单词表
  124. function setWordTableVisibility()
  125. {
  126. var isVisible = document.getElementById("B_WordTableShowMode").checked;
  127. document.getElementById("word_table").style.display = (isVisible ? 'block' : 'none');
  128. }
  129. function getStyle (styleName) {
  130. for (var s = 0; s < document.styleSheets.length; s++)
  131. {
  132. if(document.styleSheets[s].rules)
  133. {
  134. for (var r = 0; r < document.styleSheets[s].rules.length; r++)
  135. {
  136. if (document.styleSheets[s].rules[r].selectorText == styleName)
  137. {
  138. return document.styleSheets[s].rules[r];
  139. }
  140. }
  141. }
  142. else if(document.styleSheets[s].cssRules)
  143. {
  144. for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
  145. {
  146. if (document.styleSheets[s].cssRules[r].selectorText == styleName)
  147. return document.styleSheets[s].cssRules[r];
  148. }
  149. }
  150. }
  151. return null;
  152. }
  153. function getStyleClass (className) {
  154. for (var s = 0; s < document.styleSheets.length; s++)
  155. {
  156. if(document.styleSheets[s].rules)
  157. {
  158. for (var r = 0; r < document.styleSheets[s].rules.length; r++)
  159. {
  160. if (document.styleSheets[s].rules[r].selectorText == '.' + className)
  161. {
  162. return document.styleSheets[s].rules[r];
  163. }
  164. }
  165. }
  166. else if(document.styleSheets[s].cssRules)
  167. {
  168. for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
  169. {
  170. if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
  171. return document.styleSheets[s].cssRules[r];
  172. }
  173. }
  174. }
  175. return null;
  176. }
  177. function getCookie(c_name)
  178. {
  179. if (document.cookie.length>0)
  180. {
  181. c_start=document.cookie.indexOf(c_name + "=")
  182. if (c_start!=-1)
  183. {
  184. c_start=c_start + c_name.length+1
  185. c_end=document.cookie.indexOf(";",c_start)
  186. if (c_end==-1)
  187. c_end=document.cookie.length
  188. return unescape(document.cookie.substring(c_start,c_end))
  189. }
  190. }
  191. return ""
  192. }
  193. function setCookie(c_name,value,expiredays)
  194. {
  195. var exdate=new Date()
  196. exdate.setDate(exdate.getDate()+expiredays)
  197. document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
  198. }
  199. //读取cookie 中的字体大小
  200. function checkCookie(){
  201. mFontSize=getCookie('fontsize')
  202. if (mFontSize!=null && mFontSize!="")
  203. {
  204. iStartFontSize = mFontSize
  205. }
  206. else
  207. {
  208. mFontSize=100
  209. iStartFontSize = 100
  210. setCookie('fontsize',mFontSize,365)
  211. }
  212. setPageFontSize(1);
  213. setPageColor(0);
  214. }
  215. function setObjectVisibilityAlone(strIdGroup , strId){
  216. var hiden = new Array();
  217. hiden=strIdGroup.split('&');
  218. for(i=0;i<hiden.length;i++){
  219. document.getElementById(hiden[i]).style.display="none";
  220. }
  221. var obj = document.getElementById(strId);
  222. obj.style.display="block";
  223. }
  224. function setObjectVisibility(strId){
  225. var obj = document.getElementById(strId);
  226. if(obj.style.display=="none"){
  227. obj.style.display="block";
  228. }
  229. else{
  230. obj.style.display="none";
  231. }
  232. }
  233. function setObjectVisibility2(ControllerId,ObjId){
  234. var isVisible = document.getElementById(ControllerId).checked;
  235. document.getElementById(ObjId).style.display = (isVisible ? 'block' : 'none');
  236. }
  237. function setObjectVisibility3(Controller,ObjId){
  238. var isVisible = Controller.checked;
  239. document.getElementById(ObjId).style.display = (isVisible ? 'block' : 'none');
  240. }
  241. function setAllTitleVisibility(Controller,numTitle){
  242. for(var i=0; i<numTitle; i++){
  243. document.getElementById("titlevisable"+numTitle).checked = Controller.checked;
  244. }
  245. }
  246. function windowsInit(){
  247. var strSertch = location.search;
  248. if(strSertch.length>0){
  249. strSertch = strSertch.substr(1);
  250. var sertchList=strSertch.split('&');
  251. for (x in sertchList){
  252. var item = sertchList[x].split('=');
  253. if(item[0]=="filename"){
  254. g_filename=item[1];
  255. }
  256. }
  257. }
  258. checkCookie();
  259. setUseMode("read");
  260. if(g_filename.length>0){
  261. loadDictFromDB(g_filename);
  262. loadxml(g_filename);
  263. }
  264. else{
  265. alert("error:没有指定文件名。");
  266. }
  267. }
  268. /*静态页面使用的初始化函数*/
  269. function windowsInitStatic(){
  270. checkCookie();
  271. setUseMode_Static("read");
  272. }
  273. function indexInit(){
  274. showUserFilaList();
  275. }
  276. function goHome(){
  277. var r=confirm("在返回前请保存文件。否则所有的更改将丢失。\n 按<确定>回到主页。按<取消>留在当前页面。");
  278. if (r==true)
  279. {
  280. window.location.assign("./index.php?device="+g_device);
  281. }
  282. }
  283. function getLocalGrammaStr(inStr){
  284. for(i in gLocal.grammastr){
  285. inStr=inStr.replace(gLocal.grammastr[i].id,gLocal.grammastr[i].value);
  286. }
  287. return inStr;
  288. }
  289. function getLocalFormulaStr(inGramma,inStr){
  290. if(inStr.indexOf("[")>=0){
  291. return(inStr);
  292. }
  293. var output=inStr;
  294. for(i in gLocal.formula){
  295. if(gLocal.formula[i].id==inGramma){
  296. output=gLocal.formula[i].value.replace("~",inStr);
  297. }
  298. }
  299. return output;
  300. }
  301. function getLocalParentFormulaStr(inGramma,inStr){
  302. var output=inStr;
  303. for(i in gLocal.parent_formula){
  304. if(gLocal.parent_formula[i].id==inGramma){
  305. output=gLocal.parent_formula[i].value.replace("~",inStr);
  306. }
  307. }
  308. return output;
  309. }