Text.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. 问题:
  3. 1、txt的问题变化 键盘处理流程
  4. */
  5. Namespace.register("U.MD.D.Txt"); //txt命名空间
  6. /*
  7. * txt初始化方法
  8. *param {obj} 要导入的文件对象
  9. */
  10. U.MD.D.Txt.textCreate = function (obj) {
  11. var text_div = $$("div", { "className": "U_MD_F_T_Text_div",
  12. style: {
  13. width: "100%",
  14. height: "100%"
  15. }
  16. }); //创建最外层的div对象
  17. var text_center = $$("div", { "className": "U_MD_F_T_Text_center",
  18. style: {
  19. width: "100%",
  20. height: "39px",
  21. color: "white",
  22. background: "#fafafa",
  23. U_MD_O_E_borderBottom: "1px solid #a5a3a3"
  24. }
  25. }, text_div); //创建中间行的div对象
  26. var New = $$("div", { "className": "U_MD_F_T_New",
  27. style: {
  28. backgroundColor: "white",
  29. float: " left",
  30. lineHeight: "25px",
  31. cursor: " pointer",
  32. marginLeft: " 10px",
  33. height: "25px",
  34. marginTop: "6px",
  35. border: " 1px solid #CDCDCD",
  36. color: " #000"
  37. }
  38. }, text_center); //创建新建按钮的div对象
  39. var img = $$("div", { "className": "U_MD_F_T_New_img",
  40. style: {
  41. float: "left",
  42. marginLeft: "8px",
  43. width: "20px",
  44. height: "25px",
  45. background: "url(/img/Editor_img1.png) no-repeat",
  46. backgroundPosition: "0px -25px"
  47. }
  48. }, New); //点击新建的img
  49. var span = $$("div", { "className": "U_MD_F_T_New_span",
  50. style: {
  51. width: "40px",
  52. height: "25px",
  53. float: "left",
  54. marginLeft: "5px",
  55. fontFamily: "微软雅黑",
  56. fontSize: "12.5px"
  57. }
  58. , innerHTML: "新建"
  59. }, New); //创建新建的span
  60. var save = $$("div", { "className": "U_MD_F_T_Save",
  61. style: {
  62. backgroundColor: "white",
  63. float: " left",
  64. lineHeight: "25px",
  65. cursor: " pointer",
  66. marginLeft: " 10px",
  67. height: "25px",
  68. marginTop: "6px",
  69. border: " 1px solid #CDCDCD",
  70. color: " #000"
  71. }
  72. }, text_center); //创建保存的div对象
  73. img = $$("div", { "className": "U_MD_F_T_Save_img",
  74. style: {
  75. float: "left",
  76. marginLeft: "4px",
  77. width: "25px",
  78. height: "25px",
  79. background: "url(/img/Editor_img1.png) no-repeat",
  80. backgroundPosition: "-25px -25px"
  81. }
  82. }, save); //创建保存的img
  83. span = $$("div", { "className": "U_MD_F_T_Save_span",
  84. style: {
  85. width: "40px",
  86. height: "25px",
  87. float: "left",
  88. marginLeft: "5px",
  89. fontFamily: "微软雅黑",
  90. fontSize: "12.5px"
  91. }, innerHTML: "保存"
  92. }, save); //创建保存的span
  93. var font = U.MD.UI.Font(); //调用方法,生成字体表
  94. text_center.appendChild(font); //插入到中间div中
  95. font.className = "UD_font";
  96. font.style.height = "27px";
  97. font.style.marginLeft = "10px";
  98. font.style.marginTop = "6px"; //修改样式
  99. font.style.fontSize = "14px";
  100. font.style.fontFamily = "微软雅黑";
  101. var fontsize = U.MD.UI.WordSize(); //调用方法,生成字号表
  102. fontsize.className = "UD_fontsize";
  103. text_center.appendChild(fontsize); //插入到中间div中
  104. fontsize.style.height = "27px";
  105. fontsize.style.marginLeft = "10px";
  106. fontsize.style.marginTop = "6px"; //设置样式
  107. fontsize.style.fontSize = "14px";
  108. fontsize.style.fontFamily = "微软雅黑";
  109. var text = $$("textarea", {
  110. "className": "U_MD_F_T_Text",
  111. placeholder: "点击编辑内容...."
  112. }, text_div); //创建text对象在最外div中
  113. font.onchange = function () {
  114. U.MD.D.Txt.fontOnchange(text, this);
  115. } //设置字体表的点击事件
  116. fontsize.onchange = function () {
  117. U.MD.D.Txt.fontSizeOnchange(text, this);
  118. } //设置字号表的点击事件
  119. var form = new U.UF.UI.form("", text_div, { "style": { "width": "50%", "height": "50%"} }); //调用方法,创建窗体
  120. if (obj) {//判断是否有输入文件对象,如果有
  121. U.MD.D.Txt.objFun(obj, text, form); //调用obj对象处理方法
  122. } else {
  123. form.form.childNodes[1].innerHTML = "新建文本文件";
  124. }
  125. form.form.childNodes[1].style.textIndent = "15px";
  126. New.onclick = function () {//定义新建按钮的点击事件
  127. U.MD.D.Txt.NewFun();
  128. }
  129. save.onclick = function () {//定义保存事件
  130. U.MD.D.Txt.SaveFun(text, form); //调用保存方法
  131. }
  132. return form.form; //返回创建好的窗体
  133. }
  134. /*
  135. *txt字体改变方法
  136. *param {obj} txt文本对象
  137. *param1 {obj} 点击的对象
  138. */
  139. U.MD.D.Txt.fontOnchange = function (text, thisobj) {
  140. text.style.fontFamily = thisobj.value;
  141. }
  142. /*
  143. *txt字号改变方法
  144. *param {obj} txt文本对象
  145. *param1 {obj} 点击的对象
  146. */
  147. U.MD.D.Txt.fontSizeOnchange = function (text, thisobj) {
  148. text.style.fontSize = thisobj.value;
  149. }
  150. /*
  151. * obj对象处理方法
  152. *param {obj} 要导入的文件对象
  153. *param1 {obj} txt文本对象
  154. *param2 {obj} 窗体对象
  155. */
  156. U.MD.D.Txt.objFun = function (obj, text, form) {
  157. U.A.Request(US.AUTH, ["GetFileContent", obj.UserDirectoryID], function (r) {//调用方法,获取内容后输出
  158. text.value = r.value.UsOffice;
  159. }, []);
  160. form.form.childNodes[1].innerHTML = obj.UserallDirectoryName; //修改txt中的值
  161. text.userid = obj.UserId;
  162. text.id = obj.UserDirectoryID; //修改txt的id
  163. }
  164. /*
  165. *txt新建方法
  166. */
  167. U.MD.D.Txt.NewFun = function () {
  168. U.MD.D.Txt.textCreate();
  169. }
  170. /*
  171. *txt保存方法
  172. *param {obj} txt文本对象
  173. *param1 {obj} 窗体对象
  174. */
  175. U.MD.D.Txt.SaveFun = function (text, form) {
  176. if (text.id) {//如果是修改文件内容
  177. U.A.Request(US.AUTH, ["SaveFileContent", text.userid, text.id, text.value, form.form.childNodes[1].innerHTML], function (r) {
  178. U.alert("保存成功", 2000);
  179. }, []); //调用接口,修改文件内容
  180. } else {
  181. if (US.disk.UserDisk == null) {
  182. U.MD.DK.RE.newText({});
  183. } else {
  184. U.MD.DK.RE.newText(US.disk.UserDisk, function (fileinfo) {
  185. text.userid = fileinfo.UserId; //修改前台内容
  186. text.id = fileinfo.UserDirectoryID; //修改前台内容
  187. form.form.childNodes[1].innerHTML = fileinfo.UserDirectoryName; //修改前台内容
  188. U.A.Request(US.AUTH, ["SaveFileContent", text.userid, text.id, text.value, _name], function (r) {
  189. U.alert("创建成功", 2000);
  190. }, []); //调用接口,修改文件内容
  191. });
  192. }
  193. }
  194. }