调解系统PC端服务

api.js 50KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /*!
  2. * Copyright (c) Ascensio System SIA 2024. All rights reserved
  3. *
  4. * http://www.onlyoffice.com
  5. *
  6. * Version: 8.0.1 (build:31)
  7. */
  8. ;(function(DocsAPI, window, document, undefined) {
  9. /*
  10. # Full #
  11. config = {
  12. type: 'desktop or mobile or embedded',
  13. width: '100% by default',
  14. height: '100% by default',
  15. documentType: 'word' | 'cell' | 'slide' | 'pdf' ,// deprecate 'text' | 'spreadsheet' | 'presentation',
  16. token: <string> encrypted signature
  17. document: {
  18. title: 'document title',
  19. url: 'document url'
  20. fileType: 'document file type',
  21. options: <advanced options>,
  22. key: 'key',
  23. vkey: 'vkey',
  24. referenceData: 'data for external paste',
  25. info: {
  26. owner: 'owner name',
  27. folder: 'path to document',
  28. uploaded: '<uploaded date>',
  29. sharingSettings: [
  30. {
  31. user: 'user name',
  32. permissions: '<permissions>',
  33. isLink: false
  34. },
  35. ...
  36. ],
  37. favorite: '<file is favorite>' // true/false/undefined (undefined - don't show fav. button)
  38. },
  39. permissions: {
  40. edit: <can edit>, // default = true
  41. download: <can download>, // default = true
  42. reader: <can view in readable mode>,
  43. review: <can review>, // default = edit
  44. print: <can print>, // default = true
  45. comment: <can comment in view mode> // default = edit,
  46. modifyFilter: <can add, remove and save filter in the spreadsheet> // default = true
  47. modifyContentControl: <can modify content controls in documenteditor> // default = true
  48. fillForms: <can edit forms in view mode> // default = edit || review,
  49. copy: <can copy data> // default = true,
  50. editCommentAuthorOnly: <can edit your own comments only> // default = false
  51. deleteCommentAuthorOnly: <can delete your own comments only> // default = false,
  52. reviewGroups: ["Group1", ""] // current user can accept/reject review changes made by users from Group1 and users without a group. [] - use groups, but can't change any group's changes
  53. commentGroups: { // {} - use groups, but can't view/edit/delete any group's comments
  54. view: ["Group1", ""] // current user can view comments made by users from Group1 and users without a group.
  55. edit: ["Group1", ""] // current user can edit comments made by users from Group1 and users without a group.
  56. remove: ["Group1", ""] // current user can remove comments made by users from Group1 and users without a group.
  57. },
  58. userInfoGroups: ["Group1", ""], // show tooltips/cursors/info in header only for users in userInfoGroups groups. [""] - means users without group, [] - don't show any users, null/undefined/"" - show all users
  59. protect: <can protect document> // default = true. show/hide protect tab or protect buttons
  60. }
  61. },
  62. editorConfig: {
  63. actionLink: { // open file and scroll to data, used with onMakeActionLink or the onRequestSendNotify event
  64. action: {
  65. type: "bookmark", // or type="comment"
  66. data: <bookmark name> // or comment id
  67. }
  68. },
  69. mode: 'view or edit',
  70. lang: <language code>,
  71. location: <location>,
  72. canCoAuthoring: <can coauthoring documents>,
  73. canBackToFolder: <can return to folder> - deprecated. use "customization.goback" parameter,
  74. createUrl: 'create document url',
  75. sharingSettingsUrl: 'document sharing settings url',
  76. fileChoiceUrl: 'source url', // for mail merge or image from storage
  77. callbackUrl: <url for connection between sdk and portal>,
  78. mergeFolderUrl: 'folder for saving merged file', // must be deprecated, use saveAsUrl instead
  79. saveAsUrl: 'folder for saving files'
  80. licenseUrl: <url for license>,
  81. customerId: <customer id>,
  82. region: <regional settings> // can be 'en-us' or lang code
  83. user: {
  84. id: 'user id',
  85. name: 'user name',
  86. group: 'group name' // for customization.reviewPermissions or permissions.reviewGroups or permissions.commentGroups. Can be multiple groups separated by commas (,) : 'Group1' or 'Group1,Group2'
  87. image: 'image url'
  88. },
  89. recent: [
  90. {
  91. title: 'document title',
  92. url: 'document url',
  93. folder: 'path to document',
  94. },
  95. ...
  96. ],
  97. templates: [
  98. {
  99. title: 'template name', // name - is deprecated
  100. image: 'template icon url',
  101. url: 'http://...'
  102. },
  103. ...
  104. ],
  105. customization: {
  106. logo: {
  107. image: url,
  108. imageDark: url, // logo for dark theme
  109. imageEmbedded: url, // deprecated, use image instead
  110. url: http://...
  111. },
  112. customer: {
  113. name: 'SuperPuper',
  114. address: 'New-York, 125f-25',
  115. mail: 'support@gmail.com',
  116. www: 'www.superpuper.com',
  117. phone: '1234567890',
  118. info: 'Some info',
  119. logo: '',
  120. logoDark: '', // logo for dark theme
  121. },
  122. about: true,
  123. feedback: {
  124. visible: false,
  125. url: http://...
  126. },
  127. goback: {
  128. url: 'http://...',
  129. text: 'Go to London',
  130. blank: true,
  131. requestClose: false // if true - goback send onRequestClose event instead opening url
  132. },
  133. reviewPermissions: {
  134. "Group1": ["Group2"], // users from Group1 can accept/reject review changes made by users from Group2
  135. "Group2": ["Group1", "Group2"] // users from Group2 can accept/reject review changes made by users from Group1 and Group2
  136. "Group3": [""] // users from Group3 can accept/reject review changes made by users without a group
  137. },
  138. anonymous: { // set name for anonymous user
  139. request: bool (default: true), // enable set name
  140. label: string (default: "Guest") // postfix for user name
  141. },
  142. review: {
  143. hideReviewDisplay: false, // hide button Review mode
  144. hoverMode: false, // true - show review balloons on mouse move, not on click on text
  145. showReviewChanges: false,
  146. reviewDisplay: 'original', // original for viewer, markup for editor
  147. trackChanges: undefined // true/false - open editor with track changes mode on/off,
  148. },
  149. layout: { // hide elements, but don't disable feature
  150. toolbar: {
  151. file: { // menu file
  152. close: false / true, // close menu button
  153. settings: false / true, // advanced settings
  154. info: false / true // document info
  155. save: false/true // save button
  156. } / false / true,
  157. home: {
  158. mailmerge: false/true // mail merge button
  159. },
  160. layout: false / true, // layout tab
  161. references: false / true, // de references tab
  162. collaboration: false / true // collaboration tab
  163. draw: false / true // draw tab
  164. protect: false / true, // protect tab
  165. plugins: false / true // plugins tab
  166. view: {
  167. navigation: false/true // navigation button in de
  168. } / false / true, // view tab
  169. save: false/true // save button on toolbar in
  170. } / false / true, // use instead of customization.toolbar,
  171. header: {
  172. users: false/true // users list button
  173. save: false/true // save button
  174. },
  175. leftMenu: {
  176. navigation: false/true,
  177. spellcheck: false/true // spellcheck button in sse,
  178. mode: false/true // init value for left panel, true - is visible, false - is hidden, used for option "Left panel" on the View Tab
  179. } / false / true, // use instead of customization.leftMenu
  180. rightMenu: {
  181. mode: false/true // init value for right panel, true - is visible, false - is hidden, used for option "Right panel" on the View Tab
  182. } / false/true, // use instead of customization.rightMenu
  183. statusBar: {
  184. textLang: false/true // text language button in de/pe
  185. docLang: false/true // document language button in de/pe
  186. actionStatus: false/true // status of operation
  187. } / false / true, // use instead of customization.statusBar
  188. },
  189. features: { // disable feature
  190. spellcheck: {
  191. mode: false/true // init value in de/pe
  192. change: false/true // hide/show feature in de/pe/sse
  193. } / false / true // if false/true - use as init value in de/pe. use instead of customization.spellcheck parameter
  194. },
  195. font: {
  196. name: "Arial",
  197. size: "11px";
  198. },
  199. chat: true,
  200. comments: true,
  201. zoom: 100,
  202. compactToolbar: false,
  203. leftMenu: true, // must be deprecated. use layout.leftMenu instead
  204. rightMenu: true, // must be deprecated. use layout.rightMenu instead
  205. hideRightMenu: false, // hide or show right panel on first loading
  206. toolbar: true, // must be deprecated. use layout.toolbar instead
  207. statusBar: true, // must be deprecated. use layout.statusBar instead
  208. autosave: true,
  209. forcesave: false,
  210. commentAuthorOnly: false, // must be deprecated. use permissions.editCommentAuthorOnly and permissions.deleteCommentAuthorOnly instead
  211. showReviewChanges: false, // must be deprecated. use customization.review.showReviewChanges instead
  212. help: true,
  213. compactHeader: false,
  214. toolbarNoTabs: false,
  215. toolbarHideFileName: false,
  216. reviewDisplay: 'original', // must be deprecated. use customization.review.reviewDisplay instead
  217. spellcheck: true, // must be deprecated. use customization.features.spellcheck instead
  218. compatibleFeatures: false,
  219. unit: 'cm' // cm, pt, inch,
  220. mentionShare : true // customize tooltip for mention,
  221. macros: true // can run macros in document
  222. plugins: true // can run plugins in document
  223. macrosMode: 'warn' // warn about automatic macros, 'enable', 'disable', 'warn',
  224. trackChanges: undefined // true/false - open editor with track changes mode on/off, // must be deprecated. use customization.review.trackChanges instead
  225. hideRulers: false // hide or show rulers on first loading (presentation or document editor)
  226. hideNotes: false // hide or show notes panel on first loading (presentation editor)
  227. uiTheme: 'theme-dark' // set interface theme: id or default-dark/default-light
  228. integrationMode: "embed" // turn off scroll to frame
  229. mobileForceView: true/false (default: true) // turn on/off the 'reader' mode on launch. for mobile document editor only
  230. },
  231. coEditing: {
  232. mode: 'fast', // <coauthoring mode>, 'fast' or 'strict'. if 'fast' and 'customization.autosave'=false -> set 'customization.autosave'=true. 'fast' - default for editor
  233. // for viewer: 'strict' is default, offline viewer; 'fast' - live viewer, show changes from other users
  234. change: true, // can change co-authoring mode. true - default for editor, false - default for viewer
  235. },
  236. plugins: {
  237. autostart: ['asc.{FFE1F462-1EA2-4391-990D-4CC84940B754}'],
  238. pluginsData: [
  239. "helloworld/config.json",
  240. "chess/config.json",
  241. "speech/config.json",
  242. "clipart/config.json",
  243. ]
  244. },
  245. wopi: { // only for wopi
  246. FileNameMaxLength: 250 // max filename length for rename, 250 by default
  247. }
  248. },
  249. events: {
  250. 'onAppReady': <application ready callback>,
  251. 'onDocumentStateChange': <document state changed callback>
  252. 'onDocumentReady': <document ready callback>
  253. 'onRequestEditRights': <request rights for switching from view to edit>,
  254. 'onRequestHistory': <request version history>,// must call refreshHistory method
  255. 'onRequestHistoryData': <request version data>,// must call setHistoryData method
  256. 'onRequestRestore': <try to restore selected version>,
  257. 'onRequestHistoryClose': <request closing history>,
  258. 'onError': <error callback>,
  259. 'onWarning': <warning callback>,
  260. 'onInfo': <document open callback>,// send view or edit mode
  261. 'onOutdatedVersion': <outdated version callback>,// send when previous version is opened
  262. 'onDownloadAs': <download as callback>,// send url of downloaded file as a response for downloadAs method
  263. 'onRequestSaveAs': <try to save copy of the document>,
  264. 'onCollaborativeChanges': <co-editing changes callback>,// send when other user co-edit document
  265. 'onRequestRename': <try to rename document>,
  266. 'onMetaChange': // send when meta information changed
  267. 'onRequestClose': <request close editor>,
  268. 'onMakeActionLink': <request link to document with bookmark, comment...>,// must call setActionLink method
  269. 'onRequestUsers': <request users list for mentions>,// must call setUsers method
  270. 'onRequestSendNotify': //send when user is mentioned in a comment,
  271. 'onRequestInsertImage': <try to insert image>,// must call insertImage method
  272. 'onRequestCompareFile': <request file to compare>,// must call setRevisedFile method. must be deprecated
  273. 'onRequestSharingSettings': <request sharing settings>,// must call setSharingSettings method
  274. 'onRequestCreateNew': <try to create document>,
  275. 'onRequestReferenceData': <try to refresh external data>,
  276. 'onRequestOpen': <try to open external link>,
  277. 'onRequestSelectDocument': <try to open document>, // used for compare and combine documents. must call setRequestedDocument method. use instead of onRequestCompareFile/setRevisedFile
  278. 'onRequestSelectSpreadsheet': <try to open spreadsheet>, // used for mailmerge id de. must call setRequestedSpreadsheet method. use instead of onRequestMailMergeRecipients/setMailMergeRecipients
  279. 'onRequestReferenceSource': <try to change source for external link>, // used for external links in sse. must call setReferenceSource method
  280. }
  281. }
  282. # Embedded #
  283. config = {
  284. type: 'embedded',
  285. width: '100% by default',
  286. height: '100% by default',
  287. documentType: 'word' | 'cell' | 'slide',// deprecate 'text' | 'spreadsheet' | 'presentation',
  288. document: {
  289. title: 'document title',
  290. url: 'document url',
  291. fileType: 'document file type',
  292. key: 'key',
  293. vkey: 'vkey'
  294. },
  295. editorConfig: {
  296. licenseUrl: <url for license>,
  297. customerId: <customer id>,
  298. autostart: 'document', // action for app's autostart. for presentations default value is 'player'
  299. embedded: {
  300. embedUrl: 'url',
  301. fullscreenUrl: 'url',
  302. saveUrl: 'url',
  303. shareUrl: 'url',
  304. toolbarDocked: 'top or bottom'
  305. }
  306. },
  307. events: {
  308. 'onAppReady': <application ready callback>,
  309. 'onBack': <back to folder callback>,
  310. 'onError': <error callback>,
  311. 'onDocumentReady': <document ready callback>,
  312. 'onWarning': <warning callback>
  313. }
  314. }
  315. */
  316. // TODO: allow several instances on one page simultaneously
  317. DocsAPI.DocEditor = function(placeholderId, config) {
  318. var _self = this,
  319. _config = config || {};
  320. extend(_config, DocsAPI.DocEditor.defaultConfig);
  321. _config.editorConfig.canUseHistory = _config.events && !!_config.events.onRequestHistory;
  322. _config.editorConfig.canHistoryClose = _config.events && !!_config.events.onRequestHistoryClose;
  323. _config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
  324. _config.editorConfig.canSendEmailAddresses = _config.events && !!_config.events.onRequestEmailAddresses;
  325. _config.editorConfig.canRequestEditRights = _config.events && !!_config.events.onRequestEditRights;
  326. _config.editorConfig.canRequestClose = _config.events && !!_config.events.onRequestClose;
  327. _config.editorConfig.canRename = _config.events && !!_config.events.onRequestRename;
  328. _config.editorConfig.canMakeActionLink = _config.events && !!_config.events.onMakeActionLink;
  329. _config.editorConfig.canRequestUsers = _config.events && !!_config.events.onRequestUsers;
  330. _config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify;
  331. _config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl;
  332. _config.editorConfig.canRequestSaveAs = _config.events && !!_config.events.onRequestSaveAs;
  333. _config.editorConfig.canRequestInsertImage = _config.events && !!_config.events.onRequestInsertImage;
  334. _config.editorConfig.canRequestMailMergeRecipients = _config.events && !!_config.events.onRequestMailMergeRecipients;
  335. _config.editorConfig.canRequestCompareFile = _config.events && !!_config.events.onRequestCompareFile;
  336. _config.editorConfig.canRequestSharingSettings = _config.events && !!_config.events.onRequestSharingSettings;
  337. _config.editorConfig.canRequestCreateNew = _config.events && !!_config.events.onRequestCreateNew;
  338. _config.editorConfig.canRequestReferenceData = _config.events && !!_config.events.onRequestReferenceData;
  339. _config.editorConfig.canRequestOpen = _config.events && !!_config.events.onRequestOpen;
  340. _config.editorConfig.canRequestSelectDocument = _config.events && !!_config.events.onRequestSelectDocument;
  341. _config.editorConfig.canRequestSelectSpreadsheet = _config.events && !!_config.events.onRequestSelectSpreadsheet;
  342. _config.editorConfig.canRequestReferenceSource = _config.events && !!_config.events.onRequestReferenceSource;
  343. _config.frameEditorId = placeholderId;
  344. _config.parentOrigin = window.location.origin;
  345. (function(){function b(a){this.frame=a;this.x=window.scrollX;this.y=window.scrollY;this.lockCounter=0;document.addEventListener("scroll",this.onScroll.bind(this),!1);window.addEventListener("blur",this.onBlur.bind(this),!1);window.addEventListener("pointermove",this.onMove.bind(this),!1);window.addEventListener("wheel",this.onMove.bind(this),!1);this.frame.addEventListener("pointerover",this.onOver.bind(this),!1);this.frame.addEventListener("pointerleave",this.onLeave.bind(this),!1)}window.AscEmbed=
  346. window.AscEmbed||{};b.prototype.onScroll=function(){document.activeElement===this.frame||0!==this.lockCounter?window.scrollTo(this.x,this.y):(this.x=window.scrollX,this.y=window.scrollY)};b.prototype.onBlur=function(){document.activeElement===this.frame&&this.lockWithTimeout(500)};b.prototype.onOver=function(){};b.prototype.onLeave=function(){this.lockWithTimeout(100);this.frame.blur()};b.prototype.onMove=function(){document.activeElement===this.frame&&(this.lockWithTimeout(100),this.frame.blur())};
  347. b.prototype.lockWithTimeout=function(a){this.lockCounter++;var c=this;setTimeout(function(){c.lockCounter--},a)};window.AscEmbed.initWorker=function(a){window.AscEmbed.workers=window.AscEmbed.workers||[];a=new b(a);window.AscEmbed.workers.push(a);return a}})();
  348. var onMouseUp = function (evt) {
  349. _processMouse(evt);
  350. };
  351. var _attachMouseEvents = function() {
  352. if (window.addEventListener) {
  353. window.addEventListener("mouseup", onMouseUp, false)
  354. } else if (window.attachEvent) {
  355. window.attachEvent("onmouseup", onMouseUp);
  356. }
  357. };
  358. var _detachMouseEvents = function() {
  359. if (window.removeEventListener) {
  360. window.removeEventListener("mouseup", onMouseUp, false)
  361. } else if (window.detachEvent) {
  362. window.detachEvent("onmouseup", onMouseUp);
  363. }
  364. };
  365. var _onAppReady = function() {
  366. if (_config.type === 'mobile') {
  367. document.body.onfocus = function(e) {
  368. setTimeout(function(){
  369. iframe.contentWindow.focus();
  370. _sendCommand({
  371. command: 'resetFocus',
  372. data: {}
  373. })
  374. }, 10);
  375. };
  376. }
  377. _attachMouseEvents();
  378. if (_config.editorConfig) {
  379. _init(_config.editorConfig);
  380. }
  381. if (_config.document) {
  382. _openDocument(_config.document);
  383. }
  384. };
  385. var _onMessage = function(msg) {
  386. if ( msg ) {
  387. if ( msg.type === "onExternalPluginMessage" ) {
  388. _sendCommand(msg);
  389. } else if ((window.parent !== window) && msg.type === "onExternalPluginMessageCallback") {
  390. postMessage(window.parent, msg);
  391. } else
  392. if ( msg.frameEditorId == placeholderId ) {
  393. var events = _config.events || {},
  394. handler = events[msg.event],
  395. res;
  396. if (msg.event === 'onRequestEditRights' && !handler) {
  397. _applyEditRights(false, 'handler isn\'t defined');
  398. } else {
  399. if (msg.event === 'onAppReady') {
  400. _onAppReady();
  401. }
  402. if (handler && typeof handler == "function") {
  403. res = handler.call(_self, {target: _self, data: msg.data});
  404. }
  405. }
  406. }
  407. }
  408. };
  409. var _checkConfigParams = function() {
  410. if (_config.document) {
  411. if (!_config.document.url || ((typeof _config.document.fileType !== 'string' || _config.document.fileType=='') &&
  412. (typeof _config.documentType !== 'string' || _config.documentType==''))) {
  413. window.alert("One or more required parameter for the config object is not set");
  414. return false;
  415. }
  416. var appMap = {
  417. 'text': 'docx',
  418. 'text-pdf': 'pdf',
  419. 'spreadsheet': 'xlsx',
  420. 'presentation': 'pptx',
  421. 'word': 'docx',
  422. 'cell': 'xlsx',
  423. 'slide': 'pptx',
  424. 'pdf': 'pdf'
  425. }, app;
  426. if (_config.documentType=='text' || _config.documentType=='spreadsheet' ||_config.documentType=='presentation')
  427. console.warn("The \"documentType\" parameter for the config object must take one of the values word/cell/slide/pdf.");
  428. if (typeof _config.documentType === 'string' && _config.documentType != '') {
  429. app = appMap[_config.documentType.toLowerCase()];
  430. if (!app) {
  431. window.alert("The \"documentType\" parameter for the config object is invalid. Please correct it.");
  432. return false;
  433. } else if (typeof _config.document.fileType !== 'string' || _config.document.fileType == '') {
  434. _config.document.fileType = app;
  435. }
  436. }
  437. if (typeof _config.document.fileType === 'string' && _config.document.fileType != '') {
  438. _config.document.fileType = _config.document.fileType.toLowerCase();
  439. var type = /^(?:(xls|xlsx|ods|csv|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb|sxc|et|ett)|(pps|ppsx|ppt|pptx|odp|gslides|pot|potm|potx|ppsm|pptm|fodp|otp|sxi|dps|dpt)|(pdf|djvu|xps|oxps)|(doc|docx|odt|gdoc|txt|rtf|mht|htm|html|mhtml|epub|docm|dot|dotm|dotx|fodt|ott|fb2|xml|oform|docxf|sxw|stw|wps|wpt))$/
  440. .exec(_config.document.fileType);
  441. if (!type) {
  442. window.alert("The \"document.fileType\" parameter for the config object is invalid. Please correct it.");
  443. return false;
  444. } else if (typeof _config.documentType !== 'string' || _config.documentType == ''){
  445. if (typeof type[1] === 'string') _config.documentType = 'cell'; else
  446. if (typeof type[2] === 'string') _config.documentType = 'slide'; else
  447. if (typeof type[3] === 'string') _config.documentType = 'pdf'; else
  448. if (typeof type[4] === 'string') _config.documentType = 'word';
  449. }
  450. }
  451. var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(_config.document.fileType);
  452. if (type && typeof type[1] === 'string') {
  453. _config.editorConfig.canUseHistory = false;
  454. }
  455. if (!_config.document.title || _config.document.title=='')
  456. _config.document.title = 'Unnamed.' + _config.document.fileType;
  457. if (!_config.document.key) {
  458. _config.document.key = 'xxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, function (c) {var r = Math.random() * 16 | 0; return r.toString(16);});
  459. } else if (typeof _config.document.key !== 'string') {
  460. window.alert("The \"document.key\" parameter for the config object must be string. Please correct it.");
  461. return false;
  462. }
  463. if (_config.editorConfig.user && _config.editorConfig.user.id && (typeof _config.editorConfig.user.id == 'number')) {
  464. _config.editorConfig.user.id = _config.editorConfig.user.id.toString();
  465. console.warn("The \"id\" parameter for the editorConfig.user object must be a string.");
  466. }
  467. _config.document.token = _config.token;
  468. }
  469. return true;
  470. };
  471. (function() {
  472. var result = /[\?\&]placement=(\w+)&?/.exec(window.location.search);
  473. if (!!result && result.length) {
  474. if (result[1] == 'desktop') {
  475. _config.editorConfig.targetApp = result[1];
  476. // _config.editorConfig.canBackToFolder = false;
  477. if (!_config.editorConfig.customization) _config.editorConfig.customization = {};
  478. _config.editorConfig.customization.about = false;
  479. _config.editorConfig.customization.compactHeader = false;
  480. }
  481. }
  482. })();
  483. var target = document.getElementById(placeholderId),
  484. iframe;
  485. if (target && _checkConfigParams()) {
  486. iframe = createIframe(_config);
  487. if (_config.editorConfig.customization && _config.editorConfig.customization.integrationMode==='embed')
  488. window.AscEmbed && window.AscEmbed.initWorker(iframe);
  489. if (_config.document && (_config.document.isForm!==true && _config.document.isForm!==false)) {
  490. iframe.onload = function() {
  491. _sendCommand({
  492. command: 'checkParams',
  493. data: {
  494. url: _config.document.url,
  495. directUrl: _config.document.directUrl,
  496. token: _config.document.token,
  497. key: _config.document.key
  498. }
  499. })
  500. };
  501. }
  502. if (iframe.src) {
  503. var pathArray = iframe.src.split('/');
  504. this.frameOrigin = pathArray[0] + '//' + pathArray[2];
  505. }
  506. target.parentNode && target.parentNode.replaceChild(iframe, target);
  507. var _msgDispatcher = new MessageDispatcher(_onMessage, this);
  508. }
  509. /*
  510. cmd = {
  511. command: 'commandName',
  512. data: <command specific data>
  513. }
  514. */
  515. var _destroyEditor = function(cmd) {
  516. var target = document.createElement("div");
  517. target.setAttribute('id', placeholderId);
  518. if (iframe) {
  519. _msgDispatcher && _msgDispatcher.unbindEvents();
  520. _detachMouseEvents();
  521. iframe.parentNode && iframe.parentNode.replaceChild(target, iframe);
  522. }
  523. };
  524. var _sendCommand = function(cmd) {
  525. if (iframe && iframe.contentWindow)
  526. postMessage(iframe.contentWindow, cmd);
  527. };
  528. var _init = function(editorConfig) {
  529. _sendCommand({
  530. command: 'init',
  531. data: {
  532. config: editorConfig
  533. }
  534. });
  535. };
  536. var _openDocument = function(doc) {
  537. _sendCommand({
  538. command: 'openDocument',
  539. data: {
  540. doc: doc
  541. }
  542. });
  543. };
  544. var _showMessage = function(title, msg) {
  545. msg = msg || title;
  546. _sendCommand({
  547. command: 'showMessage',
  548. data: {
  549. msg: msg
  550. }
  551. });
  552. };
  553. var _applyEditRights = function(allowed, message) {
  554. _sendCommand({
  555. command: 'applyEditRights',
  556. data: {
  557. allowed: allowed,
  558. message: message
  559. }
  560. });
  561. };
  562. var _processSaveResult = function(result, message) {
  563. _sendCommand({
  564. command: 'processSaveResult',
  565. data: {
  566. result: result,
  567. message: message
  568. }
  569. });
  570. };
  571. // TODO: remove processRightsChange, use denyEditingRights
  572. var _processRightsChange = function(enabled, message) {
  573. _sendCommand({
  574. command: 'processRightsChange',
  575. data: {
  576. enabled: enabled,
  577. message: message
  578. }
  579. });
  580. };
  581. var _denyEditingRights = function(message) {
  582. _sendCommand({
  583. command: 'processRightsChange',
  584. data: {
  585. enabled: false,
  586. message: message
  587. }
  588. });
  589. };
  590. var _refreshHistory = function(data, message) {
  591. _sendCommand({
  592. command: 'refreshHistory',
  593. data: {
  594. data: data,
  595. message: message
  596. }
  597. });
  598. };
  599. var _setHistoryData = function(data, message) {
  600. _sendCommand({
  601. command: 'setHistoryData',
  602. data: {
  603. data: data,
  604. message: message
  605. }
  606. });
  607. };
  608. var _setEmailAddresses = function(data) {
  609. _sendCommand({
  610. command: 'setEmailAddresses',
  611. data: {
  612. data: data
  613. }
  614. });
  615. };
  616. var _setActionLink = function (data) {
  617. _sendCommand({
  618. command: 'setActionLink',
  619. data: {
  620. url: data
  621. }
  622. });
  623. };
  624. var _processMailMerge = function(enabled, message) {
  625. _sendCommand({
  626. command: 'processMailMerge',
  627. data: {
  628. enabled: enabled,
  629. message: message
  630. }
  631. });
  632. };
  633. var _downloadAs = function(data) {
  634. _sendCommand({
  635. command: 'downloadAs',
  636. data: data
  637. });
  638. };
  639. var _setUsers = function(data) {
  640. _sendCommand({
  641. command: 'setUsers',
  642. data: data
  643. });
  644. };
  645. var _showSharingSettings = function(data) {
  646. _sendCommand({
  647. command: 'showSharingSettings',
  648. data: data
  649. });
  650. };
  651. var _setSharingSettings = function(data) {
  652. _sendCommand({
  653. command: 'setSharingSettings',
  654. data: data
  655. });
  656. };
  657. var _insertImage = function(data) {
  658. _sendCommand({
  659. command: 'insertImage',
  660. data: data
  661. });
  662. };
  663. var _setMailMergeRecipients = function(data) {
  664. _sendCommand({
  665. command: 'setMailMergeRecipients',
  666. data: data
  667. });
  668. };
  669. var _setRevisedFile = function(data) {
  670. _sendCommand({
  671. command: 'setRevisedFile',
  672. data: data
  673. });
  674. };
  675. var _setRequestedDocument = function(data) {
  676. _sendCommand({
  677. command: 'setRequestedDocument',
  678. data: data
  679. });
  680. };
  681. var _setRequestedSpreadsheet = function(data) {
  682. _sendCommand({
  683. command: 'setRequestedSpreadsheet',
  684. data: data
  685. });
  686. };
  687. var _setReferenceSource = function(data) {
  688. _sendCommand({
  689. command: 'setReferenceSource',
  690. data: data
  691. });
  692. };
  693. var _setFavorite = function(data) {
  694. _sendCommand({
  695. command: 'setFavorite',
  696. data: data
  697. });
  698. };
  699. var _requestClose = function(data) {
  700. _sendCommand({
  701. command: 'requestClose',
  702. data: data
  703. });
  704. };
  705. var _processMouse = function(evt) {
  706. var r = iframe.getBoundingClientRect();
  707. var data = {
  708. type: evt.type,
  709. x: evt.x - r.left,
  710. y: evt.y - r.top,
  711. event: evt
  712. };
  713. _sendCommand({
  714. command: 'processMouse',
  715. data: data
  716. });
  717. };
  718. var _grabFocus = function(data) {
  719. setTimeout(function(){
  720. _sendCommand({
  721. command: 'grabFocus',
  722. data: data
  723. });
  724. }, 10);
  725. };
  726. var _blurFocus = function(data) {
  727. _sendCommand({
  728. command: 'blurFocus',
  729. data: data
  730. });
  731. };
  732. var _setReferenceData = function(data) {
  733. _sendCommand({
  734. command: 'setReferenceData',
  735. data: data
  736. });
  737. };
  738. var _serviceCommand = function(command, data) {
  739. _sendCommand({
  740. command: 'internalCommand',
  741. data: {
  742. command: command,
  743. data: data
  744. }
  745. });
  746. };
  747. function _createEmbedWorker() { return AscEmbed.initWorker(iframe); }
  748. return {
  749. createEmbedWorker : _createEmbedWorker,
  750. showMessage : _showMessage,
  751. processSaveResult : _processSaveResult,
  752. processRightsChange : _processRightsChange,
  753. denyEditingRights : _denyEditingRights,
  754. refreshHistory : _refreshHistory,
  755. setHistoryData : _setHistoryData,
  756. setEmailAddresses : _setEmailAddresses,
  757. setActionLink : _setActionLink,
  758. processMailMerge : _processMailMerge,
  759. downloadAs : _downloadAs,
  760. serviceCommand : _serviceCommand,
  761. attachMouseEvents : _attachMouseEvents,
  762. detachMouseEvents : _detachMouseEvents,
  763. destroyEditor : _destroyEditor,
  764. setUsers : _setUsers,
  765. showSharingSettings : _showSharingSettings,
  766. setSharingSettings : _setSharingSettings,
  767. insertImage : _insertImage,
  768. setMailMergeRecipients: _setMailMergeRecipients,
  769. setRevisedFile : _setRevisedFile,
  770. setFavorite : _setFavorite,
  771. requestClose : _requestClose,
  772. grabFocus : _grabFocus,
  773. blurFocus : _blurFocus,
  774. setReferenceData : _setReferenceData,
  775. setRequestedDocument: _setRequestedDocument,
  776. setRequestedSpreadsheet: _setRequestedSpreadsheet,
  777. setReferenceSource: _setReferenceSource
  778. }
  779. };
  780. DocsAPI.DocEditor.defaultConfig = {
  781. type: 'desktop',
  782. width: '100%',
  783. height: '100%',
  784. editorConfig: {
  785. lang: 'en',
  786. canCoAuthoring: true,
  787. customization: {
  788. about: true,
  789. feedback: false
  790. }
  791. }
  792. };
  793. DocsAPI.DocEditor.version = function() {
  794. return '8.0.1';
  795. };
  796. MessageDispatcher = function(fn, scope) {
  797. var _fn = fn,
  798. _scope = scope || window,
  799. eventFn = function(msg) {
  800. _onMessage(msg);
  801. };
  802. var _bindEvents = function() {
  803. if (window.addEventListener) {
  804. window.addEventListener("message", eventFn, false)
  805. }
  806. else if (window.attachEvent) {
  807. window.attachEvent("onmessage", eventFn);
  808. }
  809. };
  810. var _unbindEvents = function() {
  811. if (window.removeEventListener) {
  812. window.removeEventListener("message", eventFn, false)
  813. }
  814. else if (window.detachEvent) {
  815. window.detachEvent("onmessage", eventFn);
  816. }
  817. };
  818. var _onMessage = function(msg) {
  819. // TODO: check message origin
  820. if (msg && window.JSON && _scope.frameOrigin==msg.origin ) {
  821. try {
  822. var msg = window.JSON.parse(msg.data);
  823. if (_fn) {
  824. _fn.call(_scope, msg);
  825. }
  826. } catch(e) {}
  827. }
  828. };
  829. _bindEvents.call(this);
  830. return {
  831. unbindEvents: _unbindEvents
  832. }
  833. };
  834. function getBasePath() {
  835. var scripts = document.getElementsByTagName('script'),
  836. match;
  837. for (var i = scripts.length - 1; i >= 0; i--) {
  838. match = scripts[i].src.match(/(.*)api\/documents\/api.js/i);
  839. if (match) {
  840. return match[1];
  841. }
  842. }
  843. return "";
  844. }
  845. function getExtensionPath() {
  846. if ("undefined" == typeof(extensionParams) || null == extensionParams["url"])
  847. return null;
  848. return extensionParams["url"] + "apps/";
  849. }
  850. function getTestPath() {
  851. var scripts = document.getElementsByTagName('script'),
  852. match;
  853. for (var i = scripts.length - 1; i >= 0; i--) {
  854. match = scripts[i].src.match(/(.*)apps\/api\/documents\/api.js/i);
  855. if (match) {
  856. return match[1] + "test/";
  857. }
  858. }
  859. return "";
  860. }
  861. function getAppPath(config) {
  862. var extensionPath = getExtensionPath(),
  863. path = extensionPath ? extensionPath : (config.type=="test" ? getTestPath() : getBasePath()),
  864. appMap = {
  865. 'text': 'documenteditor',
  866. 'text-pdf': 'documenteditor',
  867. 'spreadsheet': 'spreadsheeteditor',
  868. 'presentation': 'presentationeditor',
  869. 'word': 'documenteditor',
  870. 'cell': 'spreadsheeteditor',
  871. 'slide': 'presentationeditor',
  872. 'pdf': 'pdfeditor'
  873. },
  874. appType = 'word';
  875. if (typeof config.documentType === 'string') {
  876. appType = config.documentType.toLowerCase();
  877. if (config.type !== 'mobile' && config.type !== 'embedded' && !!config.document && typeof config.document.fileType === 'string') {
  878. var type = /^(?:(pdf|djvu|xps|oxps))$/.exec(config.document.fileType);
  879. if (type && typeof type[1] === 'string')
  880. appType = 'pdf';
  881. }
  882. } else
  883. if (!!config.document && typeof config.document.fileType === 'string') {
  884. var type = /^(?:(xls|xlsx|ods|csv|xlst|xlsy|gsheet|xlsm|xlt|xltm|xltx|fods|ots|xlsb)|(pps|ppsx|ppt|pptx|odp|pptt|ppty|gslides|pot|potm|potx|ppsm|pptm|fodp|otp)|(pdf|djvu|xps|oxps))$/
  885. .exec(config.document.fileType);
  886. if (type) {
  887. if (typeof type[1] === 'string') appType = 'cell'; else
  888. if (typeof type[2] === 'string') appType = 'slide'; else
  889. if (typeof type[3] === 'string' && config.type !== 'mobile' && config.type !== 'embedded') appType = 'pdf';
  890. }
  891. }
  892. if (appType === 'pdf' && (config.type === 'mobile' || config.type === 'embedded')) {
  893. appType = 'word';
  894. }
  895. path += appMap[appType] + "/";
  896. const path_type = config.type === "mobile"
  897. ? "mobile" : (config.type === "embedded")
  898. ? "embed" : "main";
  899. path += path_type;
  900. var index = "/index.html";
  901. if (config.editorConfig && path_type!=="forms") {
  902. var customization = config.editorConfig.customization;
  903. if ( typeof(customization) == 'object' && ( customization.toolbarNoTabs ||
  904. (config.editorConfig.targetApp!=='desktop') && (customization.loaderName || customization.loaderLogo))) {
  905. index = "/index_loader.html";
  906. } else if (config.editorConfig.mode === 'editdiagram' || config.editorConfig.mode === 'editmerge' || config.editorConfig.mode === 'editole')
  907. index = "/index_internal.html";
  908. }
  909. path += index;
  910. return path;
  911. }
  912. function getAppParameters(config) {
  913. var params = "?_dc=8.0.1-31";
  914. if (config.editorConfig && config.editorConfig.lang)
  915. params += "&lang=" + config.editorConfig.lang;
  916. if (config.editorConfig && config.editorConfig.targetApp!=='desktop') {
  917. if ( (typeof(config.editorConfig.customization) == 'object') && config.editorConfig.customization.loaderName) {
  918. if (config.editorConfig.customization.loaderName !== 'none') params += "&customer=" + encodeURIComponent(config.editorConfig.customization.loaderName);
  919. } else
  920. params += "&customer=ONLYOFFICE";
  921. if (typeof(config.editorConfig.customization) == 'object') {
  922. if ( config.editorConfig.customization.loaderLogo && config.editorConfig.customization.loaderLogo !== '') {
  923. params += "&logo=" + encodeURIComponent(config.editorConfig.customization.loaderLogo);
  924. }
  925. if ( config.editorConfig.customization.logo ) {
  926. if (config.type=='embedded' && (config.editorConfig.customization.logo.image || config.editorConfig.customization.logo.imageEmbedded))
  927. params += "&headerlogo=" + encodeURIComponent(config.editorConfig.customization.logo.image || config.editorConfig.customization.logo.imageEmbedded);
  928. else if (config.type!='embedded' && (config.editorConfig.customization.logo.image || config.editorConfig.customization.logo.imageDark)) {
  929. config.editorConfig.customization.logo.image && (params += "&headerlogo=" + encodeURIComponent(config.editorConfig.customization.logo.image));
  930. config.editorConfig.customization.logo.imageDark && (params += "&headerlogodark=" + encodeURIComponent(config.editorConfig.customization.logo.imageDark));
  931. }
  932. }
  933. }
  934. }
  935. if (config.editorConfig && (config.editorConfig.mode == 'editdiagram' || config.editorConfig.mode == 'editmerge' || config.editorConfig.mode == 'editole'))
  936. params += "&internal=true";
  937. if (config.frameEditorId)
  938. params += "&frameEditorId=" + config.frameEditorId;
  939. var type = config.document ? /^(?:(pdf))$/.exec(config.document.fileType) : null;
  940. if (!(type && typeof type[1] === 'string') && (config.editorConfig && config.editorConfig.mode == 'view' ||
  941. config.document && config.document.permissions && (config.document.permissions.edit === false && !config.document.permissions.review )))
  942. params += "&mode=view";
  943. if (config.document) {
  944. config.document.isForm = (type && typeof type[1] === 'string') ? config.document.isForm : false;
  945. (config.document.isForm===true || config.document.isForm===false) && (params += "&isForm=" + config.document.isForm);
  946. }
  947. if (config.editorConfig && config.editorConfig.customization && !!config.editorConfig.customization.compactHeader)
  948. params += "&compact=true";
  949. if (config.editorConfig && config.editorConfig.customization && (config.editorConfig.customization.toolbar===false))
  950. params += "&toolbar=false";
  951. if (config.parentOrigin)
  952. params += "&parentOrigin=" + config.parentOrigin;
  953. if (config.editorConfig && config.editorConfig.customization && config.editorConfig.customization.uiTheme )
  954. params += "&uitheme=" + config.editorConfig.customization.uiTheme;
  955. if (config.document && config.document.fileType)
  956. params += "&fileType=" + config.document.fileType;
  957. return params;
  958. }
  959. function createIframe(config) {
  960. var iframe = document.createElement("iframe");
  961. iframe.src = getAppPath(config) + getAppParameters(config);
  962. iframe.width = config.width;
  963. iframe.height = config.height;
  964. iframe.align = "top";
  965. iframe.frameBorder = 0;
  966. iframe.name = "frameEditor";
  967. config.title && (typeof config.title === 'string') && (iframe.title = config.title);
  968. iframe.allowFullscreen = true;
  969. iframe.setAttribute("allowfullscreen",""); // for IE11
  970. iframe.setAttribute("onmousewheel",""); // for Safari on Mac
  971. iframe.setAttribute("allow", "autoplay; camera; microphone; display-capture; clipboard-write;");
  972. if (config.type == "mobile")
  973. {
  974. iframe.style.position = "fixed";
  975. iframe.style.overflow = "hidden";
  976. document.body.style.overscrollBehaviorY = "contain";
  977. }
  978. return iframe;
  979. }
  980. function postMessage(wnd, msg) {
  981. if (wnd && wnd.postMessage && window.JSON) {
  982. // TODO: specify explicit origin
  983. wnd.postMessage(window.JSON.stringify(msg), "*");
  984. }
  985. }
  986. function extend(dest, src) {
  987. for (var prop in src) {
  988. if (src.hasOwnProperty(prop)) {
  989. if (typeof dest[prop] === 'undefined') {
  990. dest[prop] = src[prop];
  991. } else
  992. if (typeof dest[prop] === 'object' &&
  993. typeof src[prop] === 'object') {
  994. extend(dest[prop], src[prop])
  995. }
  996. }
  997. }
  998. return dest;
  999. }
  1000. })(window.DocsAPI = window.DocsAPI || {}, window, document);