viewer.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var Viewer = function() {
  2. var docEditor;
  3. var innerAlert = function (message) {
  4. if (console && console.log)
  5. console.log(message);
  6. };
  7. var onAppReady = function () {
  8. innerAlert("文档查看已就绪~");
  9. };
  10. var onDocumentStateChange = function (event) {
  11. var title = document.title.replace(/\*$/g, "");
  12. document.title = title + (event.data ? "*" : "");
  13. };
  14. var onError = function (event) {
  15. if (event) {
  16. innerAlert(event.data);
  17. }
  18. };
  19. var onOutdatedVersion = function (event) {
  20. location.reload(true);
  21. };
  22. var getUrlParam = function (name) {
  23. //构造一个含有目标参数的正则表达式对象
  24. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  25. //匹配目标参数
  26. var r = window.location.search.substr(1).match(reg);
  27. //返回参数值
  28. if (r != null) {
  29. return decodeURI(r[2]);
  30. }
  31. return null;
  32. };
  33. var getDocumentConfig = function (document) {
  34. if (document) {
  35. return {
  36. "document": document
  37. };
  38. }
  39. innerAlert("文档未指定!");
  40. return null;
  41. };
  42. var connectEditor = function (document, documentEditParam) {
  43. var config = getDocumentConfig(document);
  44. config.width = "100%";
  45. config.height = "100%";
  46. config.type = "desktop";
  47. config.events = {
  48. "onAppReady": onAppReady,
  49. "onDocumentStateChange": onDocumentStateChange,
  50. "onError": onError,
  51. "onOutdatedVersion": onOutdatedVersion
  52. };
  53. config.editorConfig = {
  54. "lang": "zh-CN",
  55. "mode": "edit",
  56. "recent": [],
  57. // 自定义一些配置
  58. "customization": {
  59. "about": true,
  60. "comments": true,
  61. "feedback": true,
  62. "forcesave": false,
  63. "goback": false,
  64. "submitForm": false,
  65. "features": {
  66. "spellcheck": false
  67. },
  68. }
  69. //自定义一些配置
  70. /* "customization": {
  71. "chat": false, // 禁用聊天菜单按钮
  72. "commentAuthorOnly": true, // 仅能编辑和删除其注释
  73. "comments": true, // 隐藏文档注释菜单按钮
  74. "compactHeader": false, // 隐藏附加操作按钮
  75. "compactToolbar": false, // 完整工具栏(true代表紧凑工具栏)
  76. "about": true,
  77. "feedback": true,
  78. "forcesave": false, // true 表示强制文件保存请求添加到回调处理程序
  79. "goback": false,/!*{
  80. "blank": true, // 转到文档时,在新窗口打开网站(false表示当前窗口打开)
  81. "text": "转到文档位置(可以考虑放文档打开源页面)",
  82. // 文档打开失败时的跳转也是该地址
  83. "url": "http://www.lezhixing.com.cn"
  84. },*!/
  85. "features": {
  86. "spellcheck": {
  87. "mode": true
  88. }
  89. },
  90. "help": false, // 隐藏帮助按钮
  91. "hideRightMenu": false, // 首次加载时隐藏右侧菜单(true 为显示)
  92. "showReviewChanges": false, // 加载编辑器时自动显示/隐藏审阅更改面板(true显示 false隐藏)
  93. "toolbarNoTabs": false, // 清楚地显示顶部工具栏选项卡(true 代表仅突出显示以查看选择了哪一个)
  94. "zoom": 100 // 定义文档显示缩放百分比值
  95. }*/
  96. };
  97. $.extend(config.editorConfig, documentEditParam);
  98. console.log('文档参数',config)
  99. console.log('documentEditParam文档参数',documentEditParam)
  100. docEditor = new DocsAPI.DocEditor("iframeEditor", config);
  101. };
  102. return {
  103. init : function(document, documentEditParam) {
  104. connectEditor(document,documentEditParam);
  105. }
  106. }
  107. }();