WordEditor.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. //注册桌面office里面的word里面的编辑器命名空间。
  2. Namespace.register("U.MD.O.W.E");
  3. U.MD.O.W.E.colorPickerClickEl = null; /*点击按钮*/
  4. U.MD.O.W.E.ColorPickerEl = null; /*当前颜色div*/
  5. U.MD.O.W.E.Range; //word的光标
  6. U.MD.O.W.E.fontSize = {
  7. '0_42': '初号', '0_36': '小初', '0_26': '一号', '0_24': '小一', '0_22': '二号', '0_18': '小二', '0_16': '三号', '0_15': '小三', '0_14': '四号', '0_12': '小四', '0_10.5': '五号', '0_9': '小五',
  8. '1_10': '10', '1_12': '12', '1_14': '14', '1_16': '16', '1_18': '18', '1_20': '20', '1_22': '22', '1_24': '24', '1_26': '26', '1_28': '28', '1_36': '36', '1_42': '42', '1_48': '48', '1_72': '72'
  9. }; //字体对照
  10. /**
  11. * Word初始化
  12. * U.MD.O.W.E.initEditor(el):新建空白word
  13. * U.MD.O.W.E.initEditor(el,""),从数据库加载一篇有内容的word。
  14. * @param el 添加到元素里面
  15. * @param contentDom 元素节点
  16. */
  17. U.MD.O.W.E.initEditor = function (synergy) {
  18. var _el = $("#U_MD_O_H_wordEditor")[0]; //获取编辑区域的元素
  19. if (U.MD.O.W.init) {
  20. U.UF.E.initEditor(_el, synergy ? U.MD.O.W.E.operationNotice : null, U.MD.O.W.fileinfo.UsOffice, U.MD.O.W.E.styleStateManage); //初始化编辑区域
  21. }
  22. else {
  23. U.UF.E.initEditor(_el, synergy ? U.MD.O.W.E.operationNotice : null, U.MD.O.W.fileinfo.UsOffice, U.MD.O.W.E.styleStateManage); //初始化编辑区域
  24. U.MD.O.W.init = true;
  25. }
  26. }
  27. /**
  28. * 样式状态管理函数
  29. * @param style {object} 当前光标所在元素样式
  30. */
  31. U.MD.O.W.E.styleStateManage = function (style) {
  32. var _focusColor = "#E1E2E3"; //聚焦样式
  33. $('#U_MD_O_H_fontWeight').css('backgroundColor', (style["font-weight"] == "bold" || style["font-weight"] == "bolder" || parseInt(style["font-weight"]) > 400) ? _focusColor : ""); //是否加粗
  34. $('#U_MD_O_H_italic').css('backgroundColor', (style["font-style"].indexOf("italic") > -1) ? _focusColor : ""); //是否斜体
  35. $('#U_MD_O_H_underline').css('backgroundColor', (style["text-decoration"].indexOf("underline") > -1) ? _focusColor : ""); //是否下划线
  36. $('#U_MD_O_H_lineThrough').css('backgroundColor', (style["text-decoration"].indexOf("line-through") > -1) ? _focusColor : ""); //是否删除线
  37. $('.U_MD_O_H_alignFocus')[0] && $('.U_MD_O_H_alignFocus').removeClass('U_MD_O_H_alignFocus', 0); //删除文件对齐方式选中样式
  38. var _align = ""; //定义变了
  39. switch (style["text-align"]) {
  40. case "end": //end 为 right
  41. case "right":
  42. _align = "right";
  43. break;
  44. default: //否则直接获取属性
  45. _align = style["text-align"];
  46. }
  47. $("#U_MD_O_H_align" + _align).addClass("U_MD_O_H_alignFocus"); //设置当前对齐方式为选中状态
  48. $("#U_MD_O_SetFontSize").Child()[0].children[0].innerText = U.MD.O.W.E.fontSize["0_" + parseFloat(style["font-size"])] || U.MD.O.W.E.fontSize["1_" + parseFloat(style["font-size"])] || parseFloat(style["font-size"]); //设置字体大小
  49. $("#U_MD_O_SetFontFamily").Child()[0].children[0].innerText = style["font-family"] || ""; //设置字体样式
  50. // $("#U_MD_O_SetFontSize").children()[0].children[0].innerText = U.MD.O.W.E.fontSize["0_" + parseFloat(style["font-size"])] || U.MD.O.W.E.fontSize["1_" + parseFloat(style["font-size"])] || parseFloat(style["font-size"]); //设置字体大小
  51. // $("#U_MD_O_SetFontFamily").children()[0].children[0].innerText = style["font-family"] || ""; //设置字体样式
  52. var _type = ""; //定义类型
  53. switch (style["name"]) { //判断类型
  54. case 'U_MD_O_W_Font_Normal': //正文
  55. _type = "正文";
  56. break;
  57. case 'U_MD_O_W_Font_Heading1': //标题一
  58. _type = "标题1";
  59. break;
  60. case 'U_MD_O_W_Font_Heading2': //标题二
  61. _type = "标题2";
  62. break;
  63. case 'U_MD_O_W_Font_Heading3': //标题三
  64. _type = "标题3";
  65. break;
  66. case 'U_MD_O_W_Font_Heading4': //标题四
  67. _type = "标题4";
  68. break;
  69. }
  70. $("#U_MD_O_SetTitle").Child()[0].children[0].innerText = _type || "正文"; //设置类型
  71. //$("#U_MD_O_SetTitle").children()[0].children[0].innerText = _type || "正文"; //设置类型
  72. }
  73. //#region 互联编辑
  74. /*
  75. * 修改行内容
  76. */
  77. U.MD.O.W.E.updateEditorLine = function (opera) {
  78. if ($('#' + opera.id)[0]) {
  79. $('#' + opera.id)[0].outerHTML = opera.content;
  80. } else {
  81. console.log('updateError', opera.id);
  82. }
  83. };
  84. /*
  85. * 删除行
  86. */
  87. U.MD.O.W.E.deleteEditorLine = function (opera) {
  88. $('#' + opera.id).remove();
  89. };
  90. /*
  91. * 添加行
  92. */
  93. U.MD.O.W.E.addEditorLine = function (opera) {
  94. var _next;
  95. if (opera.nextId && (_next = $('#' + opera.nextId))[0]) {//判断有没有nextid,nextid是否存在
  96. _next.Parent().insertBefore($$('div', { innerHTML: opera.content, id: opera.id }), _next[0]);
  97. //有的话插入在nexid 元素前
  98. } else {
  99. $('.U_MD_O_H_wordEditor').append($$('div', { innerHTML: opera.content, id: opera.id })); //没有就生成在编辑中
  100. }
  101. }
  102. /*
  103. * 加入文档
  104. */
  105. U.MD.O.W.E.addDoc = function () {
  106. if (U.MD.O.W.fileinfo.UserDirectoryID && U.MD.O.W.userInfo.userid) { //发送请求
  107. U.A.Request(US.SCOKET, ["addWord", JSON.stringify({
  108. docId: U.MD.O.W.fileinfo.UserDirectoryID,
  109. userId: U.MD.O.W.userInfo.userid,
  110. pageId: US.pageId
  111. })], function () { });
  112. }
  113. };
  114. /*
  115. * 监听编辑器操作的回调函数
  116. */
  117. U.MD.O.W.E.operationNotice = function (operaRecord) {
  118. var _addLine = operaRecord.addLine ? U.MD.O.W.E.addLineMessage(operaRecord.addLine) : []; //判断是否是添加行
  119. var _updateLine = operaRecord.updateLine ? U.MD.O.W.E.updateLineMessage(operaRecord.updateLine) : []; //判断是否是修改行
  120. var _deleteLine = operaRecord.deleteLine ? U.MD.O.W.E.deleteLineMessage(operaRecord.deleteLine) : []; //判断是否是添加删除行
  121. var _message = {};
  122. var _type = U.MD.O.W.fileinfo.UserDirectoryExtendType == 'un' ? 'us.nav' : 'us.word';
  123. var _messagearray = Array.prototype.concat(_addLine, _updateLine, _deleteLine);
  124. if (_messagearray.length > 0) {
  125. _message[_type] = _messagearray;
  126. U.A.Request(US.SCOKET, ["send", JSON.stringify(_message)], function (r) { console.log(r); }); //发送send请求
  127. }
  128. console.log('发送的数据', Array.prototype.concat(_addLine, _deleteLine, _updateLine));
  129. };
  130. /*
  131. * 添加行
  132. */
  133. U.MD.O.W.E.addLineMessage = function (array) {
  134. var _i, _nextLine, _message = []; // 申明变量
  135. var _navid = U.MD.O.W.fileinfo.UserDirectoryExtendType == 'un' ? U.MD.O.W.T.N.nowNavId : null;
  136. for (_i = 0; _i < array.length; _i++) {
  137. _message.push(U.MD.O.W.E.wordInfo(array[_i].id, 'add', array[_i].content, array[_i].nextId, _navid)); //添加数据
  138. }
  139. return _message;
  140. };
  141. /*
  142. * 修改行内容
  143. */
  144. U.MD.O.W.E.updateLineMessage = function (array) {
  145. var _i, _message = [];
  146. var _navid = U.MD.O.W.fileinfo.UserDirectoryExtendType == 'un' ? U.MD.O.W.T.N.nowNavId : null;
  147. // console.log('跟新了行:', array);
  148. for (_i = 0; _i < array.length; _i++) {
  149. if (array[_i] !== 'U_MD_O_H_wordEditor') {
  150. // if ($('#' + array[_i])[0]) {
  151. _message.push(U.MD.O.W.E.wordInfo(array[_i].id, 'update', array[_i].content, null, _navid)); //添加数据
  152. // }
  153. }
  154. }
  155. return _message;
  156. };
  157. /*
  158. * 删除行
  159. */
  160. U.MD.O.W.E.deleteLineMessage = function (array) {
  161. var _i, _message = [];
  162. var _navid = U.MD.O.W.fileinfo.UserDirectoryExtendType == 'un' ? U.MD.O.W.T.N.nowNavId : null;
  163. // console.log('删除了行:', array);
  164. for (_i = 0; _i < array.length; _i++) {
  165. _message.push(U.MD.O.W.E.wordInfo(array[_i].id, 'delete', "", null, _navid)); //添加数据
  166. }
  167. return _message;
  168. };
  169. /*
  170. * word 消息类
  171. * 参数一 : id 行id
  172. * 参数二 : type 操作类型
  173. * 参数三 : content 行内容
  174. * 参数四 : next 下一行
  175. */
  176. U.MD.O.W.E.wordInfo = function (id, type, content, next, navid) {
  177. var _data = {
  178. sendId: U.MD.O.W.userInfo.userid, //发送人id
  179. receiveId: U.MD.O.W.fileinfo.UserDirectoryID, //文件id
  180. //type: navid ? 'us.nav' : 'us.word', //消息类型
  181. messageInfo: {
  182. id: id, //操作ID
  183. type: type, //类型
  184. content: content, //内容
  185. docId: U.MD.O.W.fileinfo.UserDirectoryID, //文档id
  186. nextId: next, //下一行ID
  187. pageId: US.pageId //当前页面id
  188. }
  189. };
  190. navid && (_data.messageInfo.navId = navid);
  191. return _data;
  192. };
  193. //#endregion
  194. //#region 工具栏的处理
  195. /**
  196. * 工具栏onmousedown处理
  197. */
  198. U.MD.O.W.E.onmousedown = function () {
  199. var _edel = $("#U_MD_O_H_wordEditor")[0],
  200. _range = U.UF.E.getRangeAt(), //得到光标处理
  201. _el = U.UF.E.getRangeElement(_range), //获取光标聚焦的元素
  202. _pel = U.UF.EL.getAncestorEditElement(_el);
  203. //如果光标聚集在元素内的处理
  204. if (_pel && U.UF.EL.isChild(_edel, _el)) {
  205. U.MD.O.W.E.Range = _range;
  206. }
  207. //如果没有聚焦,那么首先选择上一次是否记录
  208. else {
  209. _range = U.MD.O.W.E.Range;
  210. if (_range) {
  211. _el = U.UF.E.getRangeElement(_range); //得到光标元素
  212. //如果上级的光标聚焦到编辑器中,那么就不修改U.MD.O.W.E.Range
  213. if (_pel && U.UF.EL.isChild(_edel, _el)) {
  214. U.MD.O.W.E.Range = U.MD.O.W.E.Range;
  215. return;
  216. }
  217. }
  218. _edel.focus(); //聚焦
  219. U.MD.O.W.E.Range = U.UF.E.getRangeAt(); //重新设置光标
  220. }
  221. }
  222. /**
  223. * 导航点击事件处理
  224. */
  225. U.MD.O.W.E.onclick = function () {
  226. U.UF.E.reSelectRange(U.MD.O.W.E.Range);
  227. }
  228. /**
  229. * Word颜色选择器
  230. * @param el 绑定了事件的元素
  231. * @param event 鼠标事件
  232. */
  233. U.MD.O.W.E.colorPicker = function (el, event) {
  234. U.MD.O.W.E.colorPickerClickEl = el; /*button*/
  235. U.MD.O.W.E.ColorPickerEl && $(U.MD.O.W.E.ColorPickerEl).css('display', 'none');
  236. /*判断是否创建色板*/
  237. if (!U.MD.O.W.E.ColorPickerEl || !(U.MD.O.W.E.ColorPickerEl = $('.MD_ColorPicker', el)[0])) {
  238. U.MD.O.W.E.ColorPickerEl = U.MD.UI.ColorPicker(el, U.MD.O.W.E.changeColor); /*生成色板*/
  239. U.MD.O.W.E.ColorPickerEl.style.position = 'fixed'; /*将绝对定位赋值给色板*/
  240. }
  241. U.MD.O.W.E.ColorPickerEl.style.left = el.getBoundingClientRect().left + 'px'; /*定位色板x位置*/
  242. U.MD.O.W.E.ColorPickerEl.style.top = el.getBoundingClientRect().top + event.target.previousElementSibling.getBoundingClientRect().height + 'px'; /*定位色板y位置*/
  243. U.MD.O.W.E.ColorPickerEl.style.display = "block"; /*让色板显示出来*/
  244. U.UF.EV.stopBubble(event);
  245. }
  246. /**
  247. * 改变两个小块的颜色
  248. * @param r 返回颜色值
  249. */
  250. U.MD.O.W.E.changeColor = function (r) {
  251. var _changeEl = $("." + U.MD.O.W.E.colorPickerClickEl.id, U.MD.O.W.E.colorPickerClickEl)[0]; /*获取自定义属性的元素*/
  252. _changeEl.style.background = r; /*改变小块的颜色*/
  253. if (U.MD.O.W.E.colorPickerClickEl.id == "U_MD_O_H_colorPick_fontColor") { /*判断自定义属性的内容*/
  254. U.UF.E.setRangeStyle({ 'color': r }); /*设置光标选中的样式*/
  255. } else {
  256. U.UF.E.setRangeStyle({ 'background': r }); /*设置光标选中的样式*/
  257. }
  258. U.MD.O.W.E.ColorPickerEl.style.display = "none"; /*选择完后隐藏起来*/
  259. }
  260. /**
  261. * 动态创建下拉框
  262. *
  263. */
  264. U.MD.O.W.E.createSelection = function () {
  265. var _els = $('.U_MD_O_H_select'), /*获取字体颜色的div*/
  266. csstext = "font-weight: normal;white-space: pre; min-height: 1.2em; padding:6px 4px; cursor: pointer;background:#fff"; /*下拉框样式*/
  267. _els[0].innerHTML = "";
  268. U.MD.UI.editor.Select({ '宋体': '宋体', 'sans-serif': 'sans-serif', '微软雅黑': '微软雅黑', '楷体': '楷体', '黑体': '黑体', '隶书': '隶书', 'andale mono': 'andale mono', 'arial black': 'arial black' },
  269. { "className": "U_MD_O_H_select_list", id: "U_MD_O_SetFontFamily" },
  270. function (v) { U.UF.E.setRangeStyle({ 'font-family': v }) }, _els[0]) /*创建下拉框*/
  271. _els[1].innerHTML = "";
  272. U.MD.UI.editor.Select(U.MD.O.W.E.fontSize, { "className": "U_MD_O_H_select_list", id: 'U_MD_O_SetFontSize' },
  273. function (key) { U.UF.E.setRangeStyle({ 'font-size': key.split('_')[1] + 'pt' }) }, _els[1])/*创建下拉框*/
  274. _els[2].innerHTML = "";
  275. U.MD.UI.editor.Select({ 'U_MD_O_W_Font_Normal': '正文', 'U_MD_O_W_Font_Heading1': '标题1', 'U_MD_O_W_Font_Heading2': '标题2', 'U_MD_O_W_Font_Heading3': '标题3', 'U_MD_O_W_Font_Heading4': '标题4' },
  276. { "className": "U_MD_O_H_select_list", id: 'U_MD_O_SetTitle' },
  277. function (value) { U.MD.O.W.E.titleStyle(value) }, _els[2])/*创建下拉框*/
  278. _els[3].innerHTML = "";
  279. U.MD.UI.editor.Select({ 10: 1, 15: 1.5, 20: 2, 25: 2.5, 30: 3 }, { "className": "U_MD_O_H_select_list", id: 'U_MD_O_SetLineHeight', style: { width: "auto" } },
  280. function (value) {
  281. U.UF.E.setLineStyle({ 'line-height': value / 10 });
  282. // U.UF.E.setRangeStyle({ 'line-height': value / 10 });
  283. $('#U_MD_O_SetLineHeight > .U_MD_O_H_select_list > div')[0].innerHTML = ' <div class="U_MD_O_H_icon" style="background-position: -1133px -590px; height: 28px;position: absolute;top: 0;">'
  284. }, _els[3])/*创建下拉框*/
  285. $('#U_MD_O_SetLineHeight > .U_MD_O_H_select_list > div')[0].innerHTML = ' <div class="U_MD_O_H_icon" style="background-position: -1133px -590px; height: 28px;position: absolute;top: 0;">';
  286. var _selectBtn = $('.U_MD_O_H_select_list'); //失焦隐藏下拉框
  287. for (var i = 0; i < _selectBtn.length; i++) {
  288. _selectBtn[i].onclick = function () {
  289. for (var j = 0; j < 3; j++) {
  290. $(".selectBox")[j].style.display = "none";
  291. }
  292. }
  293. }
  294. }
  295. /**
  296. * Word标题样式
  297. */
  298. U.MD.O.W.E.titleStyle = function (key) {
  299. var _range = U.UF.E.getRangeAt() /*获取光标位置*/
  300. var _rangeline = U.UF.E.getRangeLineElement(_range); //获取光标所在行
  301. var _size = "12pt"; //设置字体
  302. var _weight = "bold";
  303. switch (key) {
  304. case 'U_MD_O_W_Font_Normal': //正文
  305. _size = "10.5pt";
  306. _weight = "normal";
  307. break;
  308. case 'U_MD_O_W_Font_Heading1': //标题一
  309. _size = "22pt";
  310. break;
  311. case 'U_MD_O_W_Font_Heading2': //标题二
  312. _size = "16pt";
  313. break;
  314. case 'U_MD_O_W_Font_Heading3': //标题三
  315. _size = "15pt";
  316. break;
  317. case 'U_MD_O_W_Font_Heading4': //标题四
  318. _size = "14pt";
  319. break;
  320. }
  321. var _textcsstext = "font-family:微软雅黑;font-weight:" + _weight + ";font-size:" + _size + ";line-height: 2;"; //字体样式
  322. var i, j, _nowline, _allchild; //定义变量
  323. for (i = 0; i < _rangeline.length; i++) { //设置样式
  324. _nowline = _rangeline[i];
  325. _nowline.setAttribute("name", key); //设置name属性
  326. _nowline.style.cssText = _textcsstext; //设置样式
  327. for (var j = 0; j < _rangeline[i].childNodes.length; j++) {
  328. if (_rangeline[i].childNodes[j].nodeName !== "#text") {
  329. _rangeline[i].childNodes[j].style.cssText = _textcsstext; //设置样式*/
  330. }
  331. }
  332. }
  333. }
  334. /**
  335. * 下拉框显示隐藏
  336. * @param el
  337. */
  338. U.MD.O.W.E.loadLineHeight = function (el, conel) {
  339. conel = conel || el.nextElementSibling; /*拿到下拉框选择区域内容*/
  340. conel.style.display === 'block' ? conel.style.display = 'none' : conel.style.display = 'block'; /*显示隐藏*/
  341. }
  342. /**
  343. * 下拉框显示隐藏
  344. * @param el
  345. */
  346. U.MD.O.W.E.morelocation = function (e, el, conel) {
  347. U.MD.O.W.E.loadLineHeight(el, conel);
  348. conel.style.right = "0px";
  349. conel.style.right = "auto";
  350. if (conel.offsetWidth < el.offsetLeft + el.offsetWidth) {
  351. conel.style.right = window.innerWidth - el.offsetLeft - el.offsetWidth + "px";
  352. } else {
  353. conel.style.left = "0px";
  354. conel.style.right = "auto";
  355. }
  356. // if (conel.offsetHeight <= 47 && conel.offsetWidth <= window.innerWidth && conel.offsetWidth <= (el.offsetLeft + el.offsetWidth)) {
  357. //
  358. // }
  359. }
  360. /**
  361. * 显示隐藏工具栏交换函数
  362. * @param el
  363. */
  364. U.MD.O.W.E.hideChange = function (el) {
  365. if (!el.children.length) /*判断是否有子元素*/
  366. return;
  367. el.style.display === 'table-row' ? el.style.display = 'none' : el.style.display = 'table-row'; /*显示隐藏*/
  368. }
  369. /**
  370. * 给工具栏绑定onresize事件
  371. * @param moreareael 存放超出内容的div
  372. */
  373. U.MD.O.W.E.toolsbind = function () {
  374. var _toolsel = $('#tools')[0];
  375. //给工具栏绑定onresize事件
  376. window.onresize = function () {
  377. U.MD.O.W.E.toolbarCheck(_toolsel);
  378. };
  379. //工具栏更多处理,下拉框显示隐藏
  380. $('#U_MD_O_H_More').Child()[0].onclick = function (e) {
  381. // $('#U_MD_O_H_More').children()[0].onclick = function (e) {
  382. U.MD.O.W.E.morelocation(e, this, $('.U_MD_O_H_More_Area')[0]);
  383. }
  384. //工具栏大小初始化
  385. U.MD.O.W.E.toolbarCheck(_toolsel);
  386. }
  387. /**
  388. * 工具栏检测内容区域大小
  389. * @param forms 工具栏div
  390. */
  391. U.MD.O.W.E.toolbarCheck = function (forms) {
  392. var _more = $('#U_MD_O_H_More', forms)[0]; //更多按钮
  393. var _morearea = $('.U_MD_O_H_More_Area', forms)[0]; //更多功能区域
  394. var _area = $('> .U_MD_O_H_Area', forms); //获取所有分区
  395. var i; //定义循环变量
  396. var _allwidth = 0; //设置记录宽度变量
  397. var _ismax = false; //设置是否超出最大值变量
  398. _morearea.style.display = "block"; //显示更多功能区域 否则offsetWidth获取不到宽度
  399. for (i = 0; i < _area.length - 1; i++) { //循环判断每个分区的内容是否可完全显示
  400. _allwidth += _area[i].offsetWidth; //记录宽度递加
  401. if (!_ismax && _allwidth >= forms.offsetWidth - _more.offsetWidth) { //已超出最大值或者 该分区添加后超出最大值
  402. _ismax = true; //设置变量已超出最大值
  403. break;
  404. }
  405. }
  406. if (_ismax) { //超出最大值
  407. var j; //定义循环变量
  408. for (j = _area.length - 2; j >= i; j--) { //循环判断每个分区的内容是否可完全显示 倒叙添加
  409. _morearea.children[0] ? _morearea.insertBefore(_area[j], _morearea.children[0]) : _morearea.appendChild(_area[j]); //将分区追加到跟多功能按钮之前
  410. }
  411. }
  412. while (_morearea.children[0] && !_ismax) { //循环将工具栏多余的位置放置分区
  413. _allwidth += _morearea.children[0].offsetWidth; //将分区添加后记录宽度
  414. var _morewidth = _morearea.children.length == 1 ? 0 : _more.offsetWidth; //计算更多按钮的宽度
  415. var _curoff = _morearea.children.length == 1 ? 0 : 8; //判断最后一个分区的功能是否需要显示分割线 分割线占用宽度为8
  416. var _length = forms.offsetWidth - _morewidth - _curoff; //计算当前可用宽度
  417. if (_allwidth < _length) { //如果显示宽度为超出可用宽度 则将分区提至工具栏中
  418. forms.insertBefore(_morearea.children[0], _more); //将分区追加到跟多功能按钮之前
  419. _area = $('> .U_MD_O_H_Area', forms); //重新获取分区
  420. }
  421. else {
  422. _ismax = true; //否则设置已超出最大区域
  423. }
  424. }
  425. if (_ismax || _morearea.children.length) { //判断是否已超出区域或者更多功能区存在分区
  426. _area[_area.length - 1].style.display = ""; //显示更多功能按钮
  427. $('.U_MD_O_H_cutoff', _area[_area.length - 2])[0].style.display = "inline-block"; //显示最后一个分区的分割线
  428. } else {
  429. _area[_area.length - 1].style.display = "none"; //隐藏更多功能按钮
  430. $('.U_MD_O_H_cutoff', _area[_area.length - 2])[0].style.display = "none"; //隐藏最后一个分区的分割线
  431. }
  432. _morearea.style.display = "none"; //影藏更多功能区
  433. }
  434. /**
  435. * 站点预览
  436. */
  437. U.MD.O.W.E.sitePreview = function () {
  438. var _wordinfo = U.MD.O.W.fileinfo; //获取文档信息
  439. if (_wordinfo.UserDirectoryID && _wordinfo.UserId && _wordinfo.UserallDirectoryName) { //判断文档是否存在
  440. U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_DNS", 'GetDnsInfoByFileId', _wordinfo.UserDirectoryID], function (r) {
  441. var _data = r.value; //获取该文档的域名
  442. if (_data.length) { //判断域名是否存在
  443. window.open('http://' + _data[0].AppId + '.1473.cn/' + _data[0].Domain) //跳转页面
  444. }
  445. else {
  446. var _type = _wordinfo.UserDirectoryExtendType && _wordinfo.UserDirectoryExtendType.toLowerCase(), //获取文档类型
  447. _callback = { //设置回调接口
  448. modifyDomain: function (res) { $('#U_MD_O_H_body_left_href_pay_a')[0].innerHTML = ""; U.MD.O.W.Panel.loadlink({ UserDirectoryID: res.FileId }) }, //修改命名后的回调
  449. addDomain: function (res) { $('#U_MD_O_H_body_left_href_pay_a')[0].innerHTML = ""; U.MD.O.W.Panel.loadlink({ UserDirectoryID: res.FileId }) }, //添加域名后的回调
  450. deleteDomain: function (res) { $('#U_MD_O_H_body_left_href_pay_a')[0].innerHTML = ""; U.MD.O.W.Panel.loadlink({ UserDirectoryID: res.FileId }) } //删除域名后的回调
  451. };
  452. switch (_type) { //转文档类型字符串
  453. case 'uw': case 'un': _type = 'word'; break;
  454. case 'ue': _type = 'execl'; break;
  455. default: _type = 'word'; break;
  456. }
  457. window.open("http://" + _wordinfo.UserDirectoryID + ".1473.cn");
  458. // top.U.MD.DS.createDefaultDomainInit(_wordinfo, _type, _callback); //调用域名管理中心的接口
  459. }
  460. });
  461. }
  462. else {
  463. U.MD.O.W.save(); //调用文档保存接口
  464. }
  465. }
  466. //#endregion
  467. //#region 互联文档转本地文档
  468. /* U.MD.O.W.E.downOfficeWord
  469. 参数一:type(str) 文档类型
  470. 参数二:content(str) 文档元素
  471. */
  472. U.MD.O.W.E.downOfficeWord = function (type, content, downname) {//调用函数
  473. if (type == 'doc') { //判断是都这个文件等于doc如果是执行函数
  474. var _doc = ""; //定义一个变量储存函数
  475. _doc += "<div>"; //这个里面需要有大div包裹起来
  476. var _html = content.innerHTML; //打印出里的内容显示在页面上
  477. _doc += _html;
  478. _doc += "</div>";
  479. var docFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office'>";
  480. docFile = docFile + '<html><meta charset="UTF-8"/><head></head>' + _doc + "</body></html>";
  481. var base64data = "base64," + window.btoa(unescape(encodeURIComponent(docFile)));
  482. window.open('data:application/msword;' + base64data);
  483. }
  484. // var doc = "";
  485. // doc += "<table>";
  486. // var html = document.getElementById("score").innerHTML;
  487. // doc += html;
  488. // doc += "</table>";
  489. // var a = document.body.innerHTML;
  490. // var docFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:" + a + "' xmlns='http://www.w3.org/TR/REC-html40'>";
  491. // docFile = docFile + "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>" + doc + "</body></html>";
  492. // var base64data = "base64," + window.btoa(unescape(encodeURIComponent(docFile)));
  493. // if (type == 'doc') {
  494. // window.open('data:application/msword;' + base64data);
  495. // } else if (type == 'excel') {
  496. // window.open('data:application/vnd.ms-excel;' + base64data);
  497. // }
  498. }
  499. //#endregion