Menus.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. (function()
  6. {
  7. // Adds scrollbars for menus that exceed the page height
  8. var mxPopupMenuShowMenu = mxPopupMenu.prototype.showMenu;
  9. mxPopupMenu.prototype.showMenu = function()
  10. {
  11. mxPopupMenuShowMenu.apply(this, arguments);
  12. this.div.style.overflowY = 'auto';
  13. this.div.style.overflowX = 'hidden';
  14. var h0 = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
  15. this.div.style.maxHeight = (h0 - 10) + 'px';
  16. };
  17. Menus.prototype.addLinkToItem = function(item, href)
  18. {
  19. if (item != null)
  20. {
  21. var link = document.createElement('span');
  22. link.setAttribute('title', mxResources.get('help'));
  23. link.style.cssText = 'color:blue;text-decoration:underline;margin-left:12px;cursor:help;';
  24. var icon = document.createElement('img');
  25. icon.setAttribute('border', '0');
  26. icon.setAttribute('valign', 'bottom');
  27. icon.setAttribute('src', Editor.helpImage);
  28. link.appendChild(icon);
  29. mxEvent.addGestureListeners(link, mxUtils.bind(this, function(evt)
  30. {
  31. this.editorUi.menubar.hideMenu();
  32. window.open(href);
  33. mxEvent.consume(evt);
  34. }));
  35. item.firstChild.nextSibling.appendChild(link);
  36. }
  37. };
  38. var menusInit = Menus.prototype.init;
  39. Menus.prototype.init = function()
  40. {
  41. menusInit.apply(this, arguments);
  42. var editorUi = this.editorUi;
  43. var graph = editorUi.editor.graph;
  44. var isGraphEnabled = mxUtils.bind(graph, graph.isEnabled);
  45. var googleEnabled = ((urlParams['embed'] != '1' && urlParams['gapi'] != '0') ||
  46. (urlParams['embed'] == '1' && urlParams['gapi'] == '1')) && mxClient.IS_SVG &&
  47. isLocalStorage && (document.documentMode == null || document.documentMode >= 10);
  48. var dropboxEnabled = ((urlParams['embed'] != '1' && urlParams['db'] != '0') || (urlParams['embed'] == '1' && urlParams['db'] == '1')) &&
  49. mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9);
  50. var oneDriveEnabled = (window.location.hostname == 'www.draw.io' || window.location.hostname == 'test.draw.io' ||
  51. window.location.hostname == 'drive.draw.io' || window.location.hostname == 'legacy.draw.io') &&
  52. (((urlParams['embed'] != '1' && urlParams['od'] != '0') || (urlParams['embed'] == '1' &&
  53. urlParams['od'] == '1')) && !navigator.userAgent.match(/(iPad|iPhone|iPod)/g) &&
  54. (navigator.userAgent.indexOf('MSIE') < 0 || document.documentMode >= 10));
  55. if (!editorUi.isOffline())
  56. {
  57. var img = new Image();
  58. img.src = IMAGE_PATH + '/help.png';
  59. }
  60. editorUi.actions.addAction('new...', function()
  61. {
  62. var compact = editorUi.isOffline();
  63. var dlg = new NewDialog(editorUi, compact);
  64. editorUi.showDialog(dlg.container, (compact) ? 350 : 620, (compact) ? 70 : 440, true, true, function(cancel)
  65. {
  66. if (cancel && editorUi.getCurrentFile() == null)
  67. {
  68. editorUi.showSplash();
  69. }
  70. });
  71. dlg.init();
  72. });
  73. // Export PDF action for chrome OS (same as print with different dialog title)
  74. editorUi.actions.addAction('exportPdf', function()
  75. {
  76. editorUi.showDialog(new PrintDialog(editorUi, mxResources.get('formatPdf')).container, 360,
  77. (editorUi.pages != null && editorUi.pages.length > 1) ?
  78. 420 : 360, true, true);
  79. });
  80. editorUi.actions.addAction('open...', function()
  81. {
  82. editorUi.pickFile();
  83. });
  84. editorUi.actions.addAction('close', function()
  85. {
  86. editorUi.fileLoaded(null);
  87. });
  88. editorUi.actions.addAction('editShape...', mxUtils.bind(this, function()
  89. {
  90. var cells = graph.getSelectionCells();
  91. if (graph.getSelectionCount() == 1)
  92. {
  93. var cell = graph.getSelectionCell();
  94. var state = graph.view.getState(cell);
  95. if (state != null && state.shape != null && state.shape.stencil != null)
  96. {
  97. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  98. editorUi.showDialog(dlg.container, 640, 480, true, false);
  99. dlg.init();
  100. }
  101. }
  102. }));
  103. editorUi.actions.addAction('revisionHistory...', function()
  104. {
  105. var file = editorUi.getCurrentFile();
  106. if (file == null || (file.constructor != DriveFile && file.constructor != DropboxFile) ||
  107. (editorUi.drive == null && file.constructor == DriveFile) ||
  108. (editorUi.dropbox == null && file.constructor == DropboxFile))
  109. {
  110. editorUi.showError(mxResources.get('error'), mxResources.get('notAvailable'), mxResources.get('ok'));
  111. }
  112. else if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  113. {
  114. if (file.constructor == DropboxFile)
  115. {
  116. // Limit is maximum number of entries to return
  117. var promise = editorUi.dropbox.client.filesListRevisions({path: file.stat.path_lower, limit: 100});
  118. promise.then(mxUtils.bind(this, function(response)
  119. {
  120. editorUi.spinner.stop();
  121. try
  122. {
  123. var revs = [];
  124. for (var i = response.entries.length - 1; i >= 0; i--)
  125. {
  126. (function(stat)
  127. {
  128. revs.push({modifiedDate: stat.client_modified, fileSize: stat.size, getXml: function(success, error)
  129. {
  130. editorUi.dropbox.readFile({path: file.stat.path_lower, rev: stat.rev}, success, error);
  131. }, getUrl: function()
  132. {
  133. return editorUi.getUrl(window.location.pathname + '?rev=' + stat.rev + '&chrome=0&edit=_blank') + window.location.hash;
  134. }});
  135. })(response.entries[i]);
  136. }
  137. var dlg = new RevisionDialog(editorUi, revs);
  138. editorUi.showDialog(dlg.container, 640, 480, true, true);
  139. dlg.init();
  140. }
  141. catch (e)
  142. {
  143. editorUi.handleError(e);
  144. }
  145. }));
  146. // Workaround for IE8/9 support with catch function
  147. promise['catch'](function(err)
  148. {
  149. editorUi.spinner.stop();
  150. editorUi.handleError(err);
  151. });
  152. }
  153. // Google Drive File
  154. else
  155. {
  156. editorUi.drive.executeRequest(gapi.client.drive.revisions.list({'fileId': file.getId()}), function(resp)
  157. {
  158. editorUi.spinner.stop();
  159. for (var i = 0; i < resp.items.length; i++)
  160. {
  161. (function(item)
  162. {
  163. item.getXml = function(success, error)
  164. {
  165. // Workaround for vanished head revision is to use current head revision from descriptor
  166. editorUi.drive.executeRequest(gapi.client.drive.revisions.get({'fileId': file.getId(),
  167. 'revisionId': (resp.items[resp.items.length - 1] === item) ?
  168. file.desc.headRevisionId : item.id}), function(resp)
  169. {
  170. editorUi.drive.getXmlFile(resp, null, function(file2)
  171. {
  172. success(file2.getData());
  173. }, function(resp)
  174. {
  175. error(resp);
  176. });
  177. }, function(resp)
  178. {
  179. error(resp);
  180. });
  181. };
  182. item.getUrl = function()
  183. {
  184. return editorUi.getUrl(window.location.pathname + '?rev=' + item.id + '&chrome=0&edit=_blank') + window.location.hash;
  185. };
  186. })(resp.items[i]);
  187. }
  188. var dlg = new RevisionDialog(editorUi, resp.items);
  189. editorUi.showDialog(dlg.container, 640, 480, true, true);
  190. dlg.init();
  191. }, function(resp)
  192. {
  193. editorUi.spinner.stop();
  194. editorUi.handleError(resp);
  195. });
  196. }
  197. }
  198. });
  199. editorUi.actions.addAction('createRevision', function()
  200. {
  201. editorUi.actions.get('save').funct();
  202. }, null, null, 'Ctrl+S');
  203. editorUi.actions.addAction('upload...', function()
  204. {
  205. var file = editorUi.getCurrentFile();
  206. if (file != null)
  207. {
  208. // Data is pulled from global variable after tab loads
  209. // LATER: Change to use message passing to deal with potential cross-domain
  210. window.drawdata = editorUi.getFileData();
  211. var filename = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  212. window.open(window.location.protocol + '//' + window.location.host + '/?create=drawdata&' +
  213. ((editorUi.mode == App.MODE_DROPBOX) ? 'mode=dropbox&' : '') +
  214. 'title=' + encodeURIComponent(filename));
  215. }
  216. });
  217. if (typeof(MathJax) !== 'undefined')
  218. {
  219. var action = editorUi.actions.addAction('mathematicalTypesetting', function()
  220. {
  221. editorUi.setMathEnabled(!editorUi.isMathEnabled());
  222. });
  223. action.setToggleAction(true);
  224. action.setSelectedCallback(function() { return editorUi.isMathEnabled(); });
  225. action.isEnabled = isGraphEnabled;
  226. }
  227. if (isLocalStorage)
  228. {
  229. var action = editorUi.actions.addAction('showStartScreen', function()
  230. {
  231. mxSettings.setShowStartScreen(!mxSettings.getShowStartScreen());
  232. mxSettings.save();
  233. });
  234. action.setToggleAction(true);
  235. action.setSelectedCallback(function() { return mxSettings.getShowStartScreen(); });
  236. }
  237. var autosaveAction = editorUi.actions.addAction('autosave', function()
  238. {
  239. editorUi.editor.setAutosave(!editorUi.editor.autosave);
  240. });
  241. autosaveAction.setToggleAction(true);
  242. autosaveAction.setSelectedCallback(function()
  243. {
  244. return autosaveAction.isEnabled() && editorUi.editor.autosave;
  245. });
  246. editorUi.actions.addAction('editGeometry...', function()
  247. {
  248. var cells = graph.getSelectionCells();
  249. var vertices = [];
  250. for (var i = 0; i < cells.length; i++)
  251. {
  252. if (graph.getModel().isVertex(cells[i]))
  253. {
  254. vertices.push(cells[i]);
  255. }
  256. }
  257. if (vertices.length > 0)
  258. {
  259. var dlg = new EditGeometryDialog(editorUi, vertices);
  260. editorUi.showDialog(dlg.container, 180, 180, true, true);
  261. dlg.init();
  262. }
  263. }, null, null, 'Ctrl+Shift+M');
  264. var copiedStyles = ['rounded', 'shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'fontStyle',
  265. 'align', 'verticalAlign', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor', 'swimlaneFillColor',
  266. 'textOpacity', 'gradientDirection', 'glass', 'labelBackgroundColor', 'labelBorderColor', 'opacity',
  267. 'spacing', 'spacingTop', 'spacingLeft', 'spacingBottom', 'spacingRight', 'endFill', 'endArrow',
  268. 'endSize', 'startStill', 'startArrow', 'startSize', 'arcSize'];
  269. editorUi.actions.addAction('copyStyle', function()
  270. {
  271. var state = graph.view.getState(graph.getSelectionCell());
  272. if (graph.isEnabled() && state != null)
  273. {
  274. editorUi.copiedStyle = mxUtils.clone(state.style);
  275. // Handles special case for value "none"
  276. var cellStyle = graph.getModel().getStyle(state.cell);
  277. var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
  278. for (var j = 0; j < tokens.length; j++)
  279. {
  280. var tmp = tokens[j];
  281. var pos = tmp.indexOf('=');
  282. if (pos >= 0)
  283. {
  284. var key = tmp.substring(0, pos);
  285. var value = tmp.substring(pos + 1);
  286. if (editorUi.copiedStyle[key] == null && value == 'none')
  287. {
  288. editorUi.copiedStyle[key] = 'none';
  289. }
  290. }
  291. }
  292. }
  293. }, null, null, 'Ctrl+Shift+C');
  294. editorUi.actions.addAction('pasteStyle', function()
  295. {
  296. if (graph.isEnabled() && !graph.isSelectionEmpty() && editorUi.copiedStyle != null)
  297. {
  298. graph.getModel().beginUpdate();
  299. try
  300. {
  301. var cells = graph.getSelectionCells();
  302. for (var i = 0; i < cells.length; i++)
  303. {
  304. var state = graph.view.getState(cells[i]);
  305. for (var j = 0; j < copiedStyles.length; j++)
  306. {
  307. var key = copiedStyles[j];
  308. var value = editorUi.copiedStyle[key];
  309. if (state.style[key] != value)
  310. {
  311. graph.setCellStyles(key, value, [cells[i]]);
  312. }
  313. }
  314. }
  315. }
  316. finally
  317. {
  318. graph.getModel().endUpdate();
  319. }
  320. }
  321. }, null, null, 'Ctrl+Shift+V');
  322. editorUi.actions.put('pageBackgroundImage', new Action(mxResources.get('backgroundImage') + '...', function()
  323. {
  324. if (!editorUi.isOffline())
  325. {
  326. var apply = function(image)
  327. {
  328. editorUi.setBackgroundImage(image);
  329. };
  330. var dlg = new BackgroundImageDialog(editorUi, apply);
  331. editorUi.showDialog(dlg.container, 320, 170, true, true);
  332. dlg.init();
  333. }
  334. }));
  335. action = editorUi.actions.put('shadowVisible', new Action(mxResources.get('shadow'), function()
  336. {
  337. graph.setShadowVisible(!graph.shadowVisible);
  338. }));
  339. action.setToggleAction(true);
  340. action.setSelectedCallback(function() { return graph.shadowVisible; });
  341. editorUi.actions.put('about', new Action(mxResources.get('aboutDrawio') + '...', function()
  342. {
  343. editorUi.showDialog(new AboutDialog(editorUi).container, 220, 300, true, true);
  344. }, null, null, 'F1'));
  345. editorUi.actions.addAction('userManual...', function()
  346. {
  347. window.open('https://support.draw.io/display/DO/Draw.io+Online+User+Manual');
  348. });
  349. editorUi.actions.addAction('support...', function()
  350. {
  351. window.open('https://support.draw.io/display/DO/draw.io+Online+Support');
  352. });
  353. editorUi.actions.addAction('exportOptionsDisabled...', function()
  354. {
  355. editorUi.handleError({message: mxResources.get('exportOptionsDisabledDetails')},
  356. mxResources.get('exportOptionsDisabled'));
  357. });
  358. editorUi.actions.addAction('keyboardShortcuts...', function()
  359. {
  360. if (mxClient.IS_CHROMEAPP)
  361. {
  362. window.open('https://www.draw.io/shortcuts.svg');
  363. }
  364. else if (mxClient.IS_SVG)
  365. {
  366. window.open('shortcuts.svg');
  367. }
  368. else
  369. {
  370. window.open('https://www.draw.io/?lightbox=1#Uhttps%3A%2F%2Fwww.draw.io%2Fshortcuts.svg');
  371. }
  372. });
  373. editorUi.actions.addAction('feedback...', function()
  374. {
  375. var dlg = new FeedbackDialog(editorUi);
  376. editorUi.showDialog(dlg.container, 610, 360, true, true);
  377. dlg.init();
  378. });
  379. editorUi.actions.addAction('quickStart...', function()
  380. {
  381. window.open('https://youtu.be/Z0D96ZikMkc');
  382. });
  383. action = editorUi.actions.addAction('tags...', mxUtils.bind(this, function()
  384. {
  385. if (this.tagsWindow == null)
  386. {
  387. this.tagsWindow = new TagsWindow(editorUi, document.body.offsetWidth - 380, 230, 280, 120);
  388. this.tagsWindow.window.addListener('show', function()
  389. {
  390. editorUi.fireEvent(new mxEventObject('tags'));
  391. });
  392. this.tagsWindow.window.addListener('hide', function()
  393. {
  394. editorUi.fireEvent(new mxEventObject('tags'));
  395. });
  396. this.tagsWindow.window.setVisible(true);
  397. editorUi.fireEvent(new mxEventObject('tags'));
  398. }
  399. else
  400. {
  401. this.tagsWindow.window.setVisible(!this.tagsWindow.window.isVisible());
  402. }
  403. }));
  404. action.setToggleAction(true);
  405. action.setSelectedCallback(mxUtils.bind(this, function() { return this.tagsWindow != null && this.tagsWindow.window.isVisible(); }));
  406. action = editorUi.actions.addAction('find...', mxUtils.bind(this, function()
  407. {
  408. if (this.findWindow == null)
  409. {
  410. this.findWindow = new FindWindow(editorUi, document.body.offsetWidth - 300, 110, 204, 140);
  411. this.findWindow.window.addListener('show', function()
  412. {
  413. editorUi.fireEvent(new mxEventObject('find'));
  414. });
  415. this.findWindow.window.addListener('hide', function()
  416. {
  417. editorUi.fireEvent(new mxEventObject('find'));
  418. });
  419. this.findWindow.window.setVisible(true);
  420. editorUi.fireEvent(new mxEventObject('find'));
  421. }
  422. else
  423. {
  424. this.findWindow.window.setVisible(!this.findWindow.window.isVisible());
  425. }
  426. }));
  427. action.setToggleAction(true);
  428. action.setSelectedCallback(mxUtils.bind(this, function() { return this.findWindow != null && this.findWindow.window.isVisible(); }));
  429. editorUi.actions.put('exportVsdx', new Action(mxResources.get('formatVsdx') + ' (beta)...', function()
  430. {
  431. var delayed = mxUtils.bind(this, function()
  432. {
  433. // Checks for signature method
  434. if (typeof(VsdxExport) !== 'undefined')
  435. {
  436. try
  437. {
  438. new VsdxExport(editorUi).exportCurrentDiagrams();
  439. }
  440. catch (e)
  441. {
  442. // ignore
  443. }
  444. }
  445. });
  446. if (typeof(VsdxExport) === 'undefined' && !this.loadingVsdx && !editorUi.isOffline())
  447. {
  448. this.loadingVsdx = true;
  449. // Dependencies included in Devel.js
  450. mxscript('/js/vsdx.min.js', delayed);
  451. }
  452. else
  453. {
  454. // Must be async for cell selection
  455. window.setTimeout(delayed, 0);
  456. }
  457. }));
  458. // Adds language menu to options only if localStorage is available for
  459. // storing the choice. We do not want to use cookies for older browsers.
  460. // Note that the URL param lang=XX is available for setting the language
  461. // in older browsers. URL param has precedence over the saved setting.
  462. if (mxClient.IS_CHROMEAPP || (isLocalStorage && urlParams['offline'] != '1'))
  463. {
  464. this.put('language', new Menu(mxUtils.bind(this, function(menu, parent)
  465. {
  466. var addLangItem = mxUtils.bind(this, function (id)
  467. {
  468. var lang = (id == '') ? mxResources.get('automatic') : mxLanguageMap[id];
  469. var item = null;
  470. if (lang != '')
  471. {
  472. item = menu.addItem(lang, null, mxUtils.bind(this, function()
  473. {
  474. mxSettings.setLanguage(id);
  475. mxSettings.save();
  476. // Shows dialog in new language
  477. mxClient.language = id;
  478. mxResources.loadDefaultBundle = false;
  479. mxResources.add(RESOURCE_BASE);
  480. editorUi.alert(mxResources.get('restartForChangeRequired'));
  481. }), parent);
  482. if (id == mxLanguage || (id == '' && mxLanguage == null))
  483. {
  484. menu.addCheckmark(item, Editor.checkmarkImage);
  485. }
  486. }
  487. return item;
  488. });
  489. var item = addLangItem('');
  490. menu.addSeparator(parent);
  491. // LATER: Sort menu by language name
  492. for(var langId in mxLanguageMap)
  493. {
  494. addLangItem(langId);
  495. }
  496. })));
  497. // Extends the menubar with the language menu
  498. if (uiTheme != 'atlas')
  499. {
  500. var menusCreateMenuBar = Menus.prototype.createMenubar;
  501. Menus.prototype.createMenubar = function(container)
  502. {
  503. var menubar = menusCreateMenuBar.apply(this, arguments);
  504. if (menubar != null)
  505. {
  506. var langMenu = this.get('language');
  507. if (langMenu != null)
  508. {
  509. var elt = menubar.addMenu('', langMenu.funct);
  510. elt.setAttribute('title', mxResources.get('language'));
  511. elt.style.width = '16px';
  512. elt.style.paddingTop = '2px';
  513. elt.style.paddingLeft = '4px';
  514. elt.innerHTML = '<div class="geIcon geSprite geSprite-globe"/>';
  515. elt.style.zIndex = '1';
  516. elt.style.position = 'absolute';
  517. elt.style.top = '2px';
  518. elt.style.right = '17px';
  519. elt.style.display = 'block';
  520. if (!mxClient.IS_VML)
  521. {
  522. mxUtils.setOpacity(elt, 60);
  523. }
  524. document.body.appendChild(elt);
  525. }
  526. }
  527. return menubar;
  528. };
  529. }
  530. }
  531. this.put('help', new Menu(mxUtils.bind(this, function(menu, parent)
  532. {
  533. if (!mxClient.IS_CHROMEAPP && editorUi.isOffline())
  534. {
  535. this.addMenuItems(menu, ['about']);
  536. }
  537. else
  538. {
  539. // No translation for menu item since help is english only
  540. var item = menu.addItem('Search', null, null, parent, null, null, false);
  541. var form = document.createElement('div');
  542. form.style.display = 'inline';
  543. form.innerHTML = ':<form style="display:inline;margin-left:8px;"' +
  544. 'target="_blank" method="get" action="https://desk.draw.io/support/search/solutions">' +
  545. '<input type="text" name="term" size="25"></form>';
  546. item.firstChild.nextSibling.appendChild(form);
  547. item.style.backgroundColor = 'whiteSmoke';
  548. item.style.cursor = 'default';
  549. var realForm = form.getElementsByTagName('form')[0]
  550. var input = form.getElementsByTagName('input')[0];
  551. if (input != null && realForm != null)
  552. {
  553. mxEvent.addListener(realForm, 'submit', function()
  554. {
  555. // Logs search terms for improving search results
  556. if (EditorUi.enableLogging)
  557. {
  558. try
  559. {
  560. var img = new Image();
  561. var logDomain = window.DRAWIO_LOG_URL != null ? window.DRAWIO_LOG_URL : '';
  562. img.src = logDomain + '/log?severity=CONFIG&msg=helpsearch:' + encodeURIComponent(input.value) + '&v=' + encodeURIComponent(EditorUi.VERSION);
  563. }
  564. catch (e)
  565. {
  566. // ignore
  567. }
  568. }
  569. // Workaround for blocked submit on iOS/IE11
  570. window.setTimeout(function()
  571. {
  572. editorUi.menubar.hideMenu();
  573. }, 0);
  574. });
  575. mxEvent.addGestureListeners(item, function(evt)
  576. {
  577. if (document.activeElement != input)
  578. {
  579. input.focus();
  580. }
  581. mxEvent.consume(evt);
  582. }, function(evt)
  583. {
  584. mxEvent.consume(evt);
  585. }, function(evt)
  586. {
  587. mxEvent.consume(evt);
  588. });
  589. // Sets initial focus on input element
  590. window.setTimeout(function()
  591. {
  592. input.focus();
  593. }, 0);
  594. }
  595. this.addMenuItems(menu, ['-', 'quickStart', 'userManual', 'keyboardShortcuts', '-']);
  596. if (!mxClient.IS_CHROMEAPP)
  597. {
  598. this.addMenuItems(menu, ['feedback']);
  599. }
  600. this.addMenuItems(menu, ['support', '-', 'about']);
  601. }
  602. if (urlParams['test'] == '1')
  603. {
  604. // For showing the bounding box
  605. mxResources.parse('showBoundingBox=Show bounding box');
  606. this.editorUi.actions.addAction('showBoundingBox', mxUtils.bind(this, function()
  607. {
  608. var b = graph.getGraphBounds();
  609. var tr = graph.view.translate;
  610. var s = graph.view.scale;
  611. graph.insertVertex(parent, null, '', b.x / s - tr.x, b.y / s - tr.y, b.width / s, b.height / s, 'fillColor=none;strokeColor=red;');
  612. }));
  613. this.addMenuItems(menu, ['-', 'showBoundingBox'], parent);
  614. // For testing local XML export
  615. mxResources.parse('testXmlImageExport=XML Image Export');
  616. this.editorUi.actions.addAction('testXmlImageExport', mxUtils.bind(this, function()
  617. {
  618. var bg = '#ffffff';
  619. var scale = 1;
  620. var b = 1;
  621. var imgExport = new mxImageExport();
  622. var bounds = graph.getGraphBounds();
  623. var vs = graph.view.scale;
  624. // New image export
  625. var xmlDoc = mxUtils.createXmlDocument();
  626. var root = xmlDoc.createElement('output');
  627. xmlDoc.appendChild(root);
  628. // Renders graph. Offset will be multiplied with state's scale when painting state.
  629. var xmlCanvas = new mxXmlCanvas2D(root);
  630. xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
  631. xmlCanvas.scale(scale / vs);
  632. var stateCounter = 0;
  633. var canvasSave = xmlCanvas.save;
  634. xmlCanvas.save = function()
  635. {
  636. stateCounter++;
  637. canvasSave.apply(this, arguments);
  638. };
  639. var canvasRestore = xmlCanvas.restore;
  640. xmlCanvas.restore = function()
  641. {
  642. stateCounter--;
  643. canvasRestore.apply(this, arguments);
  644. };
  645. var exportDrawShape = imgExport.drawShape;
  646. imgExport.drawShape = function(state)
  647. {
  648. mxLog.debug('entering shape', state, stateCounter);
  649. exportDrawShape.apply(this, arguments);
  650. mxLog.debug('leaving shape', state, stateCounter);
  651. };
  652. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  653. // Puts request data together
  654. var w = Math.ceil(bounds.width * scale / vs + 2 * b);
  655. var h = Math.ceil(bounds.height * scale / vs + 2 * b);
  656. mxLog.show();
  657. mxLog.debug(mxUtils.getXml(root));
  658. mxLog.debug('stateCounter', stateCounter);
  659. }));
  660. this.addMenuItems(menu, ['testXmlImageExport'], parent);
  661. mxResources.parse('testShowRtModel=Show RT model');
  662. mxResources.parse('testDebugRtModel=Debug RT model');
  663. mxResources.parse('testDownloadRtModel=Download RT model');
  664. this.editorUi.actions.addAction('testShowRtModel', mxUtils.bind(this, function()
  665. {
  666. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  667. {
  668. console.log('bytesUsed', this.editorUi.getCurrentFile().realtime.rtModel.bytesUsed);
  669. console.log('root', this.editorUi.getCurrentFile().realtime.dumpRoot());
  670. this.editorUi.getCurrentFile().realtime.check();
  671. }
  672. }));
  673. this.editorUi.actions.addAction('testDebugRtModel', mxUtils.bind(this, function()
  674. {
  675. gapi.drive.realtime.debug();
  676. }));
  677. this.editorUi.actions.addAction('testDownloadRtModel', mxUtils.bind(this, function()
  678. {
  679. var file = this.editorUi.getCurrentFile();
  680. if (file != null && file.realtime != null &&
  681. editorUi.spinner.spin(document.body, mxResources.get('export')))
  682. {
  683. // LATER: Download full model dump with history
  684. var req = new mxXmlRequest('https://www.googleapis.com/drive/v2/files/' +
  685. file.getHash().substring(1) + '/realtime', null, 'GET');
  686. // Adds auth token
  687. req.setRequestHeaders = function(request)
  688. {
  689. mxXmlRequest.prototype.setRequestHeaders.apply(this, arguments);
  690. var token = gapi.auth.getToken().access_token;
  691. request.setRequestHeader('authorization', 'Bearer ' + token);
  692. };
  693. req.send(function(req)
  694. {
  695. editorUi.spinner.stop();
  696. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  697. {
  698. editorUi.saveLocalFile(req.getText(), 'realtime.txt', 'text/plain');
  699. }
  700. });
  701. }
  702. }));
  703. if (this.editorUi.getCurrentFile() != null && this.editorUi.getCurrentFile().realtime != null)
  704. {
  705. this.addMenuItems(menu, ['-', 'testShowRtModel', 'testDebugRtModel', 'testDownloadRtModel'], parent);
  706. }
  707. mxResources.parse('testShowConsole=Show Console');
  708. this.editorUi.actions.addAction('testShowConsole', function()
  709. {
  710. if (!mxLog.isVisible())
  711. {
  712. mxLog.show();
  713. }
  714. else
  715. {
  716. mxLog.window.fit();
  717. }
  718. mxLog.window.div.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  719. });
  720. this.addMenuItems(menu, ['-', 'testShowConsole']);
  721. }
  722. })));
  723. editorUi.actions.addAction('shapes...', function()
  724. {
  725. if (mxClient.IS_CHROMEAPP || !editorUi.isOffline())
  726. {
  727. editorUi.showDialog(new MoreShapesDialog(editorUi, true).container, 640, (isLocalStorage) ?
  728. ((mxClient.IS_IOS) ? 480 : 460) : 440, true, true);
  729. }
  730. else
  731. {
  732. editorUi.showDialog(new MoreShapesDialog(editorUi, false).container, 360, (isLocalStorage) ?
  733. ((mxClient.IS_IOS) ? 300 : 280) : 260, true, true);
  734. }
  735. });
  736. editorUi.actions.addAction('createShape...', function()
  737. {
  738. var file = editorUi.getCurrentFile();
  739. if (urlParams['embed'] == '1' || (file != null && file.isEditable()))
  740. {
  741. var cell = new mxCell('', new mxGeometry(0, 0, 120, 120), editorUi.defaultCustomShapeStyle);
  742. cell.vertex = true;
  743. var dlg = new EditShapeDialog(editorUi, cell, mxResources.get('editShape') + ':', 630, 400);
  744. editorUi.showDialog(dlg.container, 640, 480, true, false);
  745. dlg.init();
  746. }
  747. });
  748. editorUi.actions.put('embedHtml', new Action(mxResources.get('html') + '...', function()
  749. {
  750. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  751. {
  752. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  753. {
  754. editorUi.spinner.stop();
  755. editorUi.showHtmlDialog(mxResources.get('create'), 'https://desk.draw.io/support/solutions/articles/16000042542',
  756. url, function(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  757. {
  758. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  759. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  760. {
  761. var dlg = new EmbedDialog(editorUi, html + '\n' + scriptTag, null, null, function()
  762. {
  763. var wnd = window.open();
  764. var doc = wnd.document;
  765. if (document.compatMode === 'CSS1Compat')
  766. {
  767. doc.writeln('<!DOCTYPE html>');
  768. }
  769. doc.writeln('<html>');
  770. doc.writeln('<head><title>' + encodeURIComponent(mxResources.get('preview')) +
  771. '</title><meta charset="utf-8"></head>');
  772. doc.writeln('<body>');
  773. doc.writeln(html);
  774. var direct = mxClient.IS_IE || mxClient.IS_EDGE || document.documentMode != null;
  775. if (direct)
  776. {
  777. doc.writeln(scriptTag);
  778. }
  779. doc.writeln('</body>');
  780. doc.writeln('</html>');
  781. doc.close();
  782. // Adds script tag after closing page and delay to fix timing issues
  783. if (!direct)
  784. {
  785. var info = wnd.document.createElement('div');
  786. info.marginLeft = '26px';
  787. info.marginTop = '26px';
  788. mxUtils.write(info, mxResources.get('updatingDocument'));
  789. var img = wnd.document.createElement('img');
  790. img.setAttribute('src', window.location.protocol + '//' + window.location.hostname +
  791. '/' + IMAGE_PATH + '/spin.gif');
  792. img.style.marginLeft = '6px';
  793. info.appendChild(img);
  794. wnd.document.body.insertBefore(info, wnd.document.body.firstChild);
  795. window.setTimeout(function()
  796. {
  797. var script = document.createElement('script');
  798. script.type = 'text/javascript';
  799. script.src = /<script.*?src="(.*?)"/.exec(scriptTag)[1];
  800. doc.body.appendChild(script);
  801. info.parentNode.removeChild(info);
  802. }, 20);
  803. }
  804. });
  805. editorUi.showDialog(dlg.container, 440, 240, true, true);
  806. dlg.init();
  807. }));
  808. });
  809. });
  810. }
  811. }));
  812. editorUi.actions.put('liveImage', new Action('Live image...', function()
  813. {
  814. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  815. {
  816. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  817. {
  818. editorUi.spinner.stop();
  819. if (url != null)
  820. {
  821. var encUrl = encodeURIComponent(url);
  822. var dlg = new EmbedDialog(editorUi, EXPORT_URL + '?format=png&url=' + encUrl, 0);
  823. editorUi.showDialog(dlg.container, 440, 240, true, true);
  824. dlg.init();
  825. }
  826. else
  827. {
  828. editorUi.handleError({message: mxResources.get('invalidPublicUrl')});
  829. }
  830. });
  831. }
  832. }));
  833. editorUi.actions.put('embedImage', new Action(mxResources.get('image') + '...', function()
  834. {
  835. editorUi.showEmbedImageDialog(function(fit, shadow, retina, lightbox, editLink, layers)
  836. {
  837. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  838. {
  839. editorUi.createEmbedImage(fit, shadow, retina, lightbox, editLink, layers, function(result)
  840. {
  841. editorUi.spinner.stop();
  842. var dlg = new EmbedDialog(editorUi, result);
  843. editorUi.showDialog(dlg.container, 440, 240, true, true);
  844. dlg.init();
  845. }, function(err)
  846. {
  847. editorUi.spinner.stop();
  848. editorUi.handleError(err);
  849. });
  850. }
  851. }, mxResources.get('image'), mxResources.get('retina'), editorUi.isExportToCanvas());
  852. }));
  853. editorUi.actions.put('embedSvg', new Action(mxResources.get('formatSvg') + '...', function()
  854. {
  855. editorUi.showEmbedImageDialog(function(fit, shadow, image, lightbox, editLink, layers)
  856. {
  857. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  858. {
  859. editorUi.createEmbedSvg(fit, shadow, image, lightbox, editLink, layers, function(result)
  860. {
  861. editorUi.spinner.stop();
  862. var dlg = new EmbedDialog(editorUi, result);
  863. editorUi.showDialog(dlg.container, 440, 240, true, true);
  864. dlg.init();
  865. }, function(err)
  866. {
  867. editorUi.spinner.stop();
  868. editorUi.handleError(err);
  869. });
  870. }
  871. }, mxResources.get('formatSvg'), mxResources.get('image'),
  872. true, 'https://desk.draw.io/support/solutions/articles/16000042548');
  873. }));
  874. editorUi.actions.put('embedIframe', new Action(mxResources.get('iframe') + '...', function()
  875. {
  876. var bounds = graph.getGraphBounds();
  877. editorUi.showPublishLinkDialog(mxResources.get('iframe'), null, '100%',
  878. (Math.ceil((bounds.y + bounds.height - graph.view.translate.y) / graph.view.scale) + 2),
  879. function(linkTarget, linkColor, allPages, lightbox, editLink, layers, width, height)
  880. {
  881. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  882. {
  883. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  884. {
  885. editorUi.spinner.stop();
  886. var dlg = new EmbedDialog(editorUi, '<iframe frameborder="0" style="width:' + width +
  887. ';height:' + height + ';" src="' + editorUi.createLink(linkTarget, linkColor,
  888. allPages, lightbox, editLink, layers, url) + '"></iframe>');
  889. editorUi.showDialog(dlg.container, 440, 240, true, true);
  890. dlg.init();
  891. });
  892. }
  893. }, true);
  894. }));
  895. editorUi.actions.put('publishLink', new Action(mxResources.get('link') + '...', function()
  896. {
  897. editorUi.showPublishLinkDialog(null, null, null, null,
  898. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  899. {
  900. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  901. {
  902. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  903. {
  904. editorUi.spinner.stop();
  905. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  906. linkColor, allPages, lightbox, editLink, layers, url));
  907. editorUi.showDialog(dlg.container, 440, 240, true, true);
  908. dlg.init();
  909. });
  910. }
  911. });
  912. }));
  913. editorUi.actions.addAction('googleDocs...', function()
  914. {
  915. window.open('http://docsaddon.draw.io');
  916. });
  917. editorUi.actions.addAction('googleSites...', function()
  918. {
  919. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  920. {
  921. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  922. {
  923. editorUi.spinner.stop();
  924. var dlg = new GoogleSitesDialog(editorUi, url);
  925. editorUi.showDialog(dlg.container, 420, 256, true, true);
  926. dlg.init();
  927. });
  928. }
  929. });
  930. // Adds plugins menu item in file menu only if localStorage is available for
  931. // storing the plugins.
  932. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  933. {
  934. var action = editorUi.actions.addAction('scratchpad', function()
  935. {
  936. editorUi.toggleScratchpad();
  937. });
  938. action.setToggleAction(true);
  939. action.setSelectedCallback(function() { return editorUi.scratchpad != null; });
  940. editorUi.actions.addAction('plugins...', function()
  941. {
  942. editorUi.showDialog(new PluginsDialog(editorUi).container, 360, 156, true, false);
  943. });
  944. }
  945. var action = editorUi.actions.addAction('search', function()
  946. {
  947. var visible = editorUi.sidebar.isEntryVisible('search');
  948. editorUi.sidebar.showPalette('search', !visible);
  949. if (isLocalStorage)
  950. {
  951. mxSettings.settings.search = !visible;
  952. mxSettings.save();
  953. }
  954. });
  955. action.setToggleAction(true);
  956. action.setSelectedCallback(function() { return editorUi.sidebar.isEntryVisible('search'); });
  957. if (urlParams['embed'] == '1')
  958. {
  959. editorUi.actions.get('save').funct = function(exit)
  960. {
  961. if (graph.isEditing())
  962. {
  963. graph.stopEditing();
  964. }
  965. var data = (urlParams['pages'] != '0' || (editorUi.pages != null && editorUi.pages.length > 1)) ?
  966. editorUi.getFileData(true) : mxUtils.getXml(editorUi.editor.getGraphXml());
  967. if (urlParams['proto'] == 'json')
  968. {
  969. var msg = editorUi.createLoadMessage('save');
  970. msg.xml = data;
  971. if (exit)
  972. {
  973. msg.exit = true;
  974. }
  975. data = JSON.stringify(msg);
  976. }
  977. var parent = window.opener || window.parent;
  978. parent.postMessage(data, '*');
  979. if (urlParams['modified'] != '0' && urlParams['keepmodified'] != '1')
  980. {
  981. editorUi.editor.modified = false;
  982. editorUi.editor.setStatus('');
  983. }
  984. };
  985. editorUi.actions.addAction('saveAndExit', function()
  986. {
  987. editorUi.actions.get('save').funct(true);
  988. });
  989. editorUi.actions.addAction('exit', function()
  990. {
  991. var fn = function()
  992. {
  993. var msg = (urlParams['proto'] == 'json') ? JSON.stringify({event: 'exit',
  994. modified: editorUi.editor.modified}) : '';
  995. var parent = window.opener || window.parent;
  996. parent.postMessage(msg, '*');
  997. }
  998. if (!editorUi.editor.modified)
  999. {
  1000. fn();
  1001. }
  1002. else
  1003. {
  1004. editorUi.confirm(mxResources.get('allChangesLost'), null, fn,
  1005. mxResources.get('cancel'), mxResources.get('discardChanges'));
  1006. }
  1007. });
  1008. }
  1009. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  1010. {
  1011. if (editorUi.isExportToCanvas())
  1012. {
  1013. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1014. {
  1015. // TODO: Enable include option if CRC is fixed
  1016. editorUi.showExportDialog(mxResources.get('image'), false, mxResources.get('export'),
  1017. 'https://support.draw.io/display/DO/Exporting+Files',
  1018. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1019. addShadow, editable, embedImages, border, cropImage, currentPage)
  1020. {
  1021. var val = parseInt(scale);
  1022. if (!isNaN(val) && val > 0)
  1023. {
  1024. this.editorUi.exportImage(val / 100, transparentBackground, ignoreSelection,
  1025. addShadow, editable, border, !cropImage, currentPage);
  1026. }
  1027. }), true, false);
  1028. }), parent);
  1029. if (editorUi.jpgSupported)
  1030. {
  1031. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1032. {
  1033. editorUi.showExportJpgDialog('https://support.draw.io/display/DO/Exporting+Files',
  1034. mxUtils.bind(this, function(scale, ignoreSelection, addShadow, border, cropImage)
  1035. {
  1036. var val = parseInt(scale);
  1037. if (!isNaN(val) && val > 0)
  1038. {
  1039. this.editorUi.exportImage(val / 100, false, ignoreSelection,
  1040. addShadow, false, border, !cropImage, false, 'jpeg');
  1041. }
  1042. }), true);
  1043. }), parent);
  1044. }
  1045. }
  1046. // Disabled for standalone mode in iOS because new tab cannot be closed
  1047. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1048. {
  1049. menu.addItem(mxResources.get('formatPng') + '...', null, mxUtils.bind(this, function()
  1050. {
  1051. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1052. {
  1053. this.editorUi.downloadFile((editable) ? 'xmlpng' : 'png', null, null, ignoreSelection);
  1054. }));
  1055. }), parent);
  1056. menu.addItem(mxResources.get('formatJpg') + '...', null, mxUtils.bind(this, function()
  1057. {
  1058. editorUi.showRemoteExportDialog(mxResources.get('export'), null, mxUtils.bind(this, function(ignoreSelection, editable)
  1059. {
  1060. this.editorUi.downloadFile('jpeg', null, null, ignoreSelection);
  1061. }), true);
  1062. }), parent);
  1063. }
  1064. menu.addItem(mxResources.get('formatSvg') + '...', null, mxUtils.bind(this, function()
  1065. {
  1066. editorUi.showExportDialog(mxResources.get('formatSvg'), true, mxResources.get('export'),
  1067. 'https://support.draw.io/display/DO/Exporting+Files',
  1068. mxUtils.bind(this, function(scale, transparentBackground, ignoreSelection,
  1069. addShadow, editable, embedImages, border, cropImage, currentPage)
  1070. {
  1071. var val = parseInt(scale);
  1072. if (!isNaN(val) && val > 0)
  1073. {
  1074. this.editorUi.exportSvg(val / 100, transparentBackground, ignoreSelection,
  1075. addShadow, editable, embedImages, border, !cropImage, currentPage);
  1076. }
  1077. }), true);
  1078. }), parent);
  1079. menu.addSeparator(parent);
  1080. // Redirects export to PDF to print in Chrome App
  1081. if (editorUi.isOffline() || editorUi.printPdfExport)
  1082. {
  1083. menu.addItem(mxResources.get('formatPdf') + '...', null, this.editorUi.actions.get('exportPdf').funct, parent);
  1084. }
  1085. // Disabled for standalone mode in iOS because new tab cannot be closed
  1086. else if (!editorUi.isOffline() && (!mxClient.IS_IOS || !navigator.standalone))
  1087. {
  1088. menu.addItem(mxResources.get('formatPdf') + '...', null, mxUtils.bind(this, function()
  1089. {
  1090. var div = document.createElement('div');
  1091. div.style.whiteSpace = 'nowrap';
  1092. var hd = document.createElement('h3');
  1093. mxUtils.write(hd, mxResources.get('formatPdf'));
  1094. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1095. div.appendChild(hd);
  1096. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1097. false, graph.isSelectionEmpty());
  1098. var crop = editorUi.addCheckbox(div, mxResources.get('crop'),
  1099. !graph.pageVisible || !editorUi.pdfPageExport,
  1100. !editorUi.pdfPageExport);
  1101. crop.style.marginBottom = '16px';
  1102. // Crop is only enabled if selection only is selected
  1103. if (!editorUi.pdfPageExport)
  1104. {
  1105. mxEvent.addListener(selection, 'change', function()
  1106. {
  1107. if (selection.checked)
  1108. {
  1109. crop.removeAttribute('disabled');
  1110. }
  1111. else
  1112. {
  1113. crop.setAttribute('disabled', 'disabled');
  1114. }
  1115. });
  1116. }
  1117. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1118. {
  1119. this.editorUi.downloadFile('pdf', null, null, !selection.checked, null, !crop.checked);
  1120. }), null, mxResources.get('export'));
  1121. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1122. }), parent);
  1123. }
  1124. menu.addItem(mxResources.get('formatHtmlEmbedded') + '...', null, mxUtils.bind(this, function()
  1125. {
  1126. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1127. {
  1128. editorUi.getPublicUrl(editorUi.getCurrentFile(), function(url)
  1129. {
  1130. editorUi.spinner.stop();
  1131. editorUi.showHtmlDialog(mxResources.get('export'), null, url, function(publicUrl, zoomEnabled,
  1132. initialZoom, linkTarget, linkColor, fit, allPages, layers, lightbox, editLink)
  1133. {
  1134. editorUi.createHtml(publicUrl, zoomEnabled, initialZoom, linkTarget, linkColor,
  1135. fit, allPages, layers, lightbox, editLink, mxUtils.bind(this, function(html, scriptTag)
  1136. {
  1137. var basename = editorUi.getBaseFilename();
  1138. var result = '<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=5,IE=9" ><![endif]-->\n' +
  1139. '<!DOCTYPE html>\n<html>\n<head>\n<title>' + mxUtils.htmlEntities(basename) + '</title>\n' +
  1140. '<meta charset="utf-8"/>\n</head>\n<body>' + html + '\n' + scriptTag + '\n</body>\n</html>';
  1141. editorUi.saveData(basename + '.html', 'html', result, 'text/html');
  1142. }));
  1143. });
  1144. });
  1145. }
  1146. //this.editorUi.downloadFile('html');
  1147. }), parent);
  1148. if (!editorUi.isOfflineApp() && (typeof(VsdxExport) !== 'undefined' || !editorUi.isOffline()))
  1149. {
  1150. this.addMenuItems(menu, ['exportVsdx'], parent);
  1151. }
  1152. menu.addSeparator(parent);
  1153. menu.addItem(mxResources.get('formatXml') + '...', null, mxUtils.bind(this, function()
  1154. {
  1155. var div = document.createElement('div');
  1156. div.style.whiteSpace = 'nowrap';
  1157. var noPages = editorUi.pages == null || editorUi.pages.length <= 1;
  1158. var hd = document.createElement('h3');
  1159. mxUtils.write(hd, mxResources.get('formatXml'));
  1160. hd.style.cssText = 'width:100%;text-align:center;margin-top:0px;margin-bottom:4px';
  1161. div.appendChild(hd);
  1162. var selection = editorUi.addCheckbox(div, mxResources.get('selectionOnly'),
  1163. false, graph.isSelectionEmpty());
  1164. var pages = editorUi.addCheckbox(div, mxResources.get((noPages) ? 'compressed' : 'allPages'), true);
  1165. pages.style.marginBottom = '16px';
  1166. mxEvent.addListener(selection, 'change', function()
  1167. {
  1168. if (selection.checked)
  1169. {
  1170. pages.setAttribute('disabled', 'disabled');
  1171. }
  1172. else
  1173. {
  1174. pages.removeAttribute('disabled');
  1175. }
  1176. });
  1177. var dlg = new CustomDialog(editorUi, div, mxUtils.bind(this, function()
  1178. {
  1179. editorUi.downloadFile('xml', (noPages) ? !pages.checked : null, null,
  1180. !selection.checked, (!noPages) ? !pages.checked : null);
  1181. }), null, mxResources.get('export'));
  1182. this.editorUi.showDialog(dlg.container, 300, 146, true, true);
  1183. }), parent);
  1184. // Disables menu item for all external hosted integrations
  1185. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp ||/.*\.draw\.io$/.test(window.location.hostname))
  1186. {
  1187. menu.addItem(mxResources.get('url') + '...', null, mxUtils.bind(this, function()
  1188. {
  1189. editorUi.showPublishLinkDialog(mxResources.get('url'), true, null, null,
  1190. function(linkTarget, linkColor, allPages, lightbox, editLink, layers)
  1191. {
  1192. var dlg = new EmbedDialog(editorUi, editorUi.createLink(linkTarget,
  1193. linkColor, allPages, lightbox, editLink, layers, null, true));
  1194. editorUi.showDialog(dlg.container, 440, 240, true, true);
  1195. dlg.init();
  1196. });
  1197. }), parent);
  1198. }
  1199. if (!editorUi.isOffline())
  1200. {
  1201. menu.addSeparator(parent);
  1202. this.addMenuItem(menu, 'export', parent).firstChild.nextSibling.innerHTML = mxResources.get('advanced') + '...';
  1203. }
  1204. })));
  1205. this.editorUi.actions.addAction('chatWindowTitle...', mxUtils.bind(this.editorUi, this.editorUi.toggleChat));
  1206. this.put('importFrom', new Menu(function(menu, parent)
  1207. {
  1208. function importFile(device)
  1209. {
  1210. if (device && Graph.fileSupport && !mxClient.IS_IE && !mxClient.IS_IE11)
  1211. {
  1212. var input = document.createElement('input');
  1213. input.setAttribute('type', 'file');
  1214. mxEvent.addListener(input, 'change', function()
  1215. {
  1216. if (input.files != null)
  1217. {
  1218. // Using null for position will disable crop of input file
  1219. editorUi.importFiles(input.files, null, null, editorUi.maxImageSize);
  1220. }
  1221. });
  1222. input.click();
  1223. }
  1224. else
  1225. {
  1226. window.openNew = false;
  1227. window.openKey = 'import';
  1228. var prevValue = Editor.useLocalStorage;
  1229. Editor.useLocalStorage = !device;
  1230. // Closes dialog after open
  1231. window.openFile = new OpenFile(function(cancel)
  1232. {
  1233. editorUi.hideDialog(cancel);
  1234. });
  1235. window.openFile.setConsumer(function(xml, filename)
  1236. {
  1237. graph.setSelectionCells(editorUi.importXml(xml));
  1238. });
  1239. // Removes openFile if dialog is closed
  1240. editorUi.showDialog(new OpenDialog(editorUi).container, 360, 220, true, true, function()
  1241. {
  1242. window.openFile = null;
  1243. });
  1244. // Extends dialog close to show splash screen
  1245. var dlg = editorUi.dialog;
  1246. var dlgClose = dlg.close;
  1247. editorUi.dialog.close = function(cancel)
  1248. {
  1249. Editor.useLocalStorage = prevValue;
  1250. dlgClose.apply(dlg, arguments);
  1251. if (cancel && editorUi.getCurrentFile() == null && urlParams['embed'] != '1')
  1252. {
  1253. editorUi.showSplash();
  1254. }
  1255. };
  1256. }
  1257. };
  1258. var doImportFile = mxUtils.bind(this, function(data, mime, filename)
  1259. {
  1260. // Gets insert location
  1261. var view = graph.view;
  1262. var bds = graph.getGraphBounds();
  1263. var x = graph.snap(Math.ceil(Math.max(0, bds.x / view.scale - view.translate.x) + 4 * graph.gridSize));
  1264. var y = graph.snap(Math.ceil(Math.max(0, (bds.y + bds.height) / view.scale - view.translate.y) + 4 * graph.gridSize));
  1265. if (data.substring(0, 11) == 'data:image/')
  1266. {
  1267. editorUi.loadImage(data, mxUtils.bind(this, function(img)
  1268. {
  1269. editorUi.resizeImage(img, data, mxUtils.bind(this, function(data2, w2, h2)
  1270. {
  1271. var s = Math.min(1, Math.min(editorUi.maxImageSize / w2, editorUi.maxImageSize / h2));
  1272. editorUi.importFile(data, mime, x, y, Math.round(w2 * s), Math.round(h2 * s), filename, function(cells)
  1273. {
  1274. editorUi.spinner.stop();
  1275. graph.setSelectionCells(cells);
  1276. graph.scrollCellToVisible(graph.getSelectionCell());
  1277. });
  1278. }), true);
  1279. }), mxUtils.bind(this, function()
  1280. {
  1281. editorUi.handleError({message: mxResources.get('cannotOpenFile')});
  1282. }));
  1283. }
  1284. else
  1285. {
  1286. editorUi.importFile(data, mime, x, y, 0, 0, filename, function(cells)
  1287. {
  1288. editorUi.spinner.stop();
  1289. graph.setSelectionCells(cells);
  1290. graph.scrollCellToVisible(graph.getSelectionCell());
  1291. });
  1292. }
  1293. });
  1294. var getMimeType = mxUtils.bind(this, function(filename)
  1295. {
  1296. var mime = 'text/xml';
  1297. if (/\.png$/i.test(filename))
  1298. {
  1299. mime = 'image/png';
  1300. }
  1301. else if (/\.jpe?g$/i.test(filename))
  1302. {
  1303. mime = 'image/jpg';
  1304. }
  1305. else if (/\.gif$/i.test(filename))
  1306. {
  1307. mime = 'image/gif';
  1308. }
  1309. return mime;
  1310. });
  1311. function pickFileFromService(service)
  1312. {
  1313. // Drive requires special arguments for libraries and bypassing realtime
  1314. service.pickFile(function(id)
  1315. {
  1316. if (editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1317. {
  1318. // NOTE The third argument in getFile says denyConvert to match
  1319. // the existing signature in the original DriveClient which has
  1320. // as slightly different semantic, but works the same way.
  1321. service.getFile(id, function(file)
  1322. {
  1323. var mime = getMimeType(file.getTitle());
  1324. // Imports SVG as images
  1325. if (/\.svg$/i.test(file.getTitle()) && !editorUi.editor.isDataSvg(file.getData()))
  1326. {
  1327. file.setData(editorUi.createSvgDataUri(file.getData()));
  1328. mime = 'image/svg+xml';
  1329. }
  1330. doImportFile(file.getData(), mime, file.getTitle());
  1331. },
  1332. function(resp)
  1333. {
  1334. editorUi.handleError(resp, (resp != null) ? mxResources.get('errorLoadingFile') : null);
  1335. }, service == editorUi.drive);
  1336. }
  1337. }, true);
  1338. };
  1339. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1340. {
  1341. if (editorUi.drive != null)
  1342. {
  1343. // Requires special arguments for libraries and realtime
  1344. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1345. {
  1346. pickFileFromService(editorUi.drive);
  1347. }, parent);
  1348. }
  1349. else if (googleEnabled)
  1350. {
  1351. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1352. {
  1353. // do nothing
  1354. }, parent, null, false);
  1355. }
  1356. }
  1357. if (editorUi.gitHub != null)
  1358. {
  1359. menu.addItem(mxResources.get('github') + '...', null, function()
  1360. {
  1361. pickFileFromService(editorUi.gitHub);
  1362. }, parent);
  1363. }
  1364. if (editorUi.dropbox != null)
  1365. {
  1366. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1367. {
  1368. pickFileFromService(editorUi.dropbox);
  1369. }, parent);
  1370. }
  1371. else if (dropboxEnabled)
  1372. {
  1373. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1374. {
  1375. // do nothing
  1376. }, parent, null, false);
  1377. }
  1378. if (editorUi.oneDrive != null)
  1379. {
  1380. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1381. {
  1382. pickFileFromService(editorUi.oneDrive);
  1383. }, parent);
  1384. }
  1385. else if (oneDriveEnabled)
  1386. {
  1387. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1388. {
  1389. // do nothing
  1390. }, parent, null, false);
  1391. }
  1392. menu.addSeparator(parent);
  1393. if (isLocalStorage && urlParams['browser'] != '0')
  1394. {
  1395. menu.addItem(mxResources.get('browser') + '...', null, function()
  1396. {
  1397. importFile(false);
  1398. }, parent);
  1399. }
  1400. if (!mxClient.IS_IOS)
  1401. {
  1402. menu.addItem(mxResources.get('device') + '...', null, function()
  1403. {
  1404. importFile(true);
  1405. }, parent);
  1406. }
  1407. if (!editorUi.isOffline())
  1408. {
  1409. menu.addSeparator(parent);
  1410. menu.addItem(mxResources.get('url') + '...', null, function()
  1411. {
  1412. var dlg = new FilenameDialog(editorUi, '', mxResources.get('import'), function(fileUrl)
  1413. {
  1414. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1415. {
  1416. var mime = (/(\.png)($|\?)/i.test(fileUrl)) ? 'image/png' : 'text/xml';
  1417. // Uses proxy to avoid CORS issues
  1418. editorUi.loadUrl(PROXY_URL + '?url=' + encodeURIComponent(fileUrl), function(data)
  1419. {
  1420. doImportFile(data, mime, fileUrl);
  1421. },
  1422. function ()
  1423. {
  1424. editorUi.spinner.stop();
  1425. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1426. }, mime == 'image/png');
  1427. }
  1428. }, mxResources.get('url'));
  1429. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1430. dlg.init();
  1431. }, parent);
  1432. }
  1433. menu.addItem(mxResources.get('csv') + '...', null, function()
  1434. {
  1435. editorUi.showImportCsvDialog();
  1436. }, parent);
  1437. })).isEnabled = isGraphEnabled;
  1438. this.put('theme', new Menu(mxUtils.bind(this, function(menu, parent)
  1439. {
  1440. var item = menu.addItem(mxResources.get('kennedy'), null, function()
  1441. {
  1442. mxSettings.setUi('');
  1443. mxSettings.save();
  1444. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1445. }, parent);
  1446. if (uiTheme != 'atlas')
  1447. {
  1448. menu.addCheckmark(item, Editor.checkmarkImage);
  1449. }
  1450. item = menu.addItem(mxResources.get('atlas'), null, function()
  1451. {
  1452. mxSettings.setUi('atlas');
  1453. mxSettings.save();
  1454. editorUi.alert(mxResources.get('restartForChangeRequired'));
  1455. }, parent);
  1456. if (uiTheme == 'atlas')
  1457. {
  1458. menu.addCheckmark(item, Editor.checkmarkImage);
  1459. }
  1460. })));
  1461. this.editorUi.actions.addAction('rename...', mxUtils.bind(this, function()
  1462. {
  1463. var file = this.editorUi.getCurrentFile();
  1464. if (file != null)
  1465. {
  1466. var filename = (file.getTitle() != null) ? file.getTitle() : this.editorUi.defaultFilename;
  1467. var dlg = new FilenameDialog(this.editorUi, filename, mxResources.get('rename'), mxUtils.bind(this, function(title)
  1468. {
  1469. if (title != null && title.length > 0 && file != null && this.editorUi.spinner.spin(document.body, mxResources.get('renaming')))
  1470. {
  1471. // Delete old file, save new file in dropbox if autosize is enabled
  1472. file.rename(title, mxUtils.bind(this, function(resp)
  1473. {
  1474. this.editorUi.spinner.stop();
  1475. }),
  1476. mxUtils.bind(this, function(resp)
  1477. {
  1478. this.editorUi.handleError(resp, (resp != null) ? mxResources.get('errorRenamingFile') : null);
  1479. }));
  1480. }
  1481. }), (file.constructor == DriveFile || file.constructor == StorageFile) ?
  1482. mxResources.get('diagramName') : null, function(name)
  1483. {
  1484. if (name != null && name.length > 0)
  1485. {
  1486. return true;
  1487. }
  1488. editorUi.showError(mxResources.get('error'), mxResources.get('invalidName'), mxResources.get('ok'));
  1489. return false;
  1490. });
  1491. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  1492. dlg.init();
  1493. }
  1494. })).isEnabled = isGraphEnabled;
  1495. editorUi.actions.addAction('makeCopy...', mxUtils.bind(this, function()
  1496. {
  1497. var file = editorUi.getCurrentFile();
  1498. if (file != null)
  1499. {
  1500. var title = (file.getTitle() != null) ? file.getTitle() : editorUi.defaultFilename;
  1501. // Handles extension
  1502. var extension = '';
  1503. var dot = title.lastIndexOf('.');
  1504. if (dot >= 0)
  1505. {
  1506. extension = title.substring(dot);
  1507. title = title.substring(0, dot);
  1508. }
  1509. title = mxResources.get('copyOf', [title]) + extension;
  1510. if (file.constructor == DriveFile)
  1511. {
  1512. var dlg = new CreateDialog(editorUi, title, mxUtils.bind(this, function(newTitle, mode)
  1513. {
  1514. // Mode is "download" if Create button is pressed, means use Google Drive
  1515. if (mode == 'download')
  1516. {
  1517. mode = App.MODE_GOOGLE;
  1518. }
  1519. if (newTitle != null && newTitle.length > 0)
  1520. {
  1521. if (mode == App.MODE_GOOGLE)
  1522. {
  1523. if (editorUi.spinner.spin(document.body, mxResources.get('saving')))
  1524. {
  1525. // Makes sure the latest XML is in the file
  1526. file.save(false, mxUtils.bind(this, function()
  1527. {
  1528. // Saveas does not update the file descriptor in Google Drive
  1529. file.saveAs(newTitle, mxUtils.bind(this, function(resp)
  1530. {
  1531. editorUi.spinner.stop();
  1532. var url = editorUi.getUrl();
  1533. window.openWindow(url + '#G' + resp.id, null, mxUtils.bind(this, function()
  1534. {
  1535. window.location.hash = 'G' + resp.id;
  1536. }));
  1537. }), mxUtils.bind(this, function(resp)
  1538. {
  1539. editorUi.handleError(resp);
  1540. }));
  1541. }), mxUtils.bind(this, function(resp)
  1542. {
  1543. editorUi.handleError(resp);
  1544. }));
  1545. }
  1546. }
  1547. else
  1548. {
  1549. this.editorUi.createFile(newTitle, this.editorUi.getFileData(true), null, mode);
  1550. }
  1551. }
  1552. }), mxUtils.bind(this, function()
  1553. {
  1554. editorUi.hideDialog();
  1555. }), mxResources.get('makeCopy'), mxResources.get('create'), null,
  1556. null, null, null, true);
  1557. editorUi.showDialog(dlg.container, 420, 380, true, true);
  1558. dlg.init();
  1559. }
  1560. else
  1561. {
  1562. // Creates a copy with no predefined storage
  1563. editorUi.editor.editAsNew(editorUi.getEditBlankXml(), title);
  1564. }
  1565. }
  1566. }));
  1567. editorUi.actions.addAction('moveToFolder...', mxUtils.bind(this, function()
  1568. {
  1569. var file = editorUi.getCurrentFile();
  1570. if (file.getMode() == App.MODE_GOOGLE || file.getMode() == App.MODE_ONEDRIVE)
  1571. {
  1572. editorUi.pickFolder(file.getMode(), mxUtils.bind(this, function(folderId)
  1573. {
  1574. if (editorUi.spinner.spin(document.body, mxResources.get('moving')))
  1575. {
  1576. file.move(folderId, mxUtils.bind(this, function(resp)
  1577. {
  1578. editorUi.spinner.stop();
  1579. }), mxUtils.bind(this, function(resp)
  1580. {
  1581. editorUi.handleError(resp);
  1582. }));
  1583. }
  1584. }));
  1585. }
  1586. }));
  1587. this.put('publish', new Menu(mxUtils.bind(this, function(menu, parent)
  1588. {
  1589. this.addMenuItems(menu, ['publishLink'], parent);
  1590. })));
  1591. editorUi.actions.put('offline', new Action(mxResources.get('offline') + '...', function()
  1592. {
  1593. window.open('http://www.draw.io/app')
  1594. }));
  1595. editorUi.actions.put('chromeApp', new Action(mxResources.get('chromeApp') + '...', function()
  1596. {
  1597. window.open('https://chrome.google.com/webstore/detail/drawio-desktop/pebppomjfocnoigkeepgbmcifnnlndla')
  1598. }));
  1599. this.editorUi.actions.addAction('share...', mxUtils.bind(this, function()
  1600. {
  1601. var file = this.editorUi.getCurrentFile();
  1602. if (file != null)
  1603. {
  1604. this.editorUi.drive.showPermissions(file.getId());
  1605. }
  1606. }));
  1607. this.put('embed', new Menu(mxUtils.bind(this, function(menu, parent)
  1608. {
  1609. if (urlParams['test'] == '1')
  1610. {
  1611. this.addMenuItems(menu, ['liveImage', '-'], parent);
  1612. }
  1613. this.addMenuItems(menu, ['embedImage', 'embedSvg', '-', 'embedHtml'], parent);
  1614. if (!navigator.standalone && !editorUi.isOffline())
  1615. {
  1616. this.addMenuItems(menu, ['embedIframe'], parent);
  1617. }
  1618. if (!editorUi.isOffline())
  1619. {
  1620. this.addMenuItems(menu, ['-', 'googleSites', 'googleDocs'], parent);
  1621. }
  1622. })));
  1623. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree', '-', 'organic', 'circle', '-', 'fromText'];
  1624. var addInsertItem = function(menu, parent, title, method)
  1625. {
  1626. menu.addItem(title, null, mxUtils.bind(this, function()
  1627. {
  1628. if (method == 'fromText')
  1629. {
  1630. var dlg = new ParseDialog(editorUi, title);
  1631. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1632. editorUi.dialog.container.style.overflow = 'auto';
  1633. dlg.init();
  1634. }
  1635. else
  1636. {
  1637. var dlg = new CreateGraphDialog(editorUi, title, method);
  1638. editorUi.showDialog(dlg.container, 620, 420, true, false);
  1639. // Executed after dialog is added to dom
  1640. dlg.init();
  1641. }
  1642. }), parent);
  1643. };
  1644. editorUi.actions.addAction('insertText', function()
  1645. {
  1646. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1647. {
  1648. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1649. var cell = new mxCell('Text', new mxGeometry(pt.x, pt.y, 40, 20),
  1650. 'text;html=1;resizable=0;autosize=1;align=left;verticalAlign=top;spacingTop=-4;points=[];');
  1651. cell.vertex = true;
  1652. graph.startEditingAtCell(graph.addCell(cell));
  1653. }
  1654. }, null, null, 'Ctrl+Shift+X').isEnabled = isGraphEnabled;
  1655. editorUi.actions.addAction('insertRectangle', function()
  1656. {
  1657. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1658. {
  1659. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1660. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 120, 60), 'whiteSpace=wrap;html=1;');
  1661. cell.vertex = true;
  1662. graph.setSelectionCell(graph.addCell(cell));
  1663. graph.scrollCellToVisible(graph.getSelectionCell());
  1664. }
  1665. }, null, null, 'Ctrl+K').isEnabled = isGraphEnabled;
  1666. editorUi.actions.addAction('insertEllipse', function()
  1667. {
  1668. if (graph.isEnabled() && !graph.isCellLocked(graph.getDefaultParent()))
  1669. {
  1670. var pt = (graph.isMouseInsertPoint()) ? graph.getInsertPoint() : graph.getFreeInsertPoint();
  1671. var cell = new mxCell('', new mxGeometry(pt.x, pt.y, 80, 80), 'ellipse;whiteSpace=wrap;html=1;');
  1672. cell.vertex = true;
  1673. graph.setSelectionCell(graph.addCell(cell));
  1674. graph.scrollCellToVisible(graph.getSelectionCell());
  1675. }
  1676. }, null, null, 'Ctrl+Shift+K').isEnabled = isGraphEnabled;
  1677. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  1678. {
  1679. this.addMenuItems(menu, ['insertText', 'insertRectangle', 'insertEllipse', '-', 'insertLink', 'insertImage'], parent);
  1680. menu.addSeparator(parent);
  1681. for (var i = 0; i < methods.length; i++)
  1682. {
  1683. if (methods[i] == '-')
  1684. {
  1685. menu.addSeparator(parent);
  1686. }
  1687. else
  1688. {
  1689. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  1690. }
  1691. }
  1692. })));
  1693. this.put('openRecent', new Menu(function(menu, parent)
  1694. {
  1695. var recent = editorUi.getRecent();
  1696. if (recent != null)
  1697. {
  1698. for (var i = 0; i < recent.length; i++)
  1699. {
  1700. (function(entry)
  1701. {
  1702. var modeKey = entry.mode;
  1703. // Google and oneDrive use different keys
  1704. if (modeKey == App.MODE_GOOGLE)
  1705. {
  1706. modeKey = 'googleDrive';
  1707. }
  1708. else if (modeKey == App.MODE_ONEDRIVE)
  1709. {
  1710. modeKey = 'oneDrive';
  1711. }
  1712. menu.addItem(entry.title + ' (' + mxResources.get(modeKey) + ')', null, function()
  1713. {
  1714. editorUi.loadFile(entry.id);
  1715. }, parent);
  1716. })(recent[i]);
  1717. }
  1718. menu.addSeparator(parent);
  1719. }
  1720. menu.addItem(mxResources.get('reset'), null, function()
  1721. {
  1722. editorUi.resetRecent();
  1723. }, parent);
  1724. }));
  1725. this.put('openFrom', new Menu(function(menu, parent)
  1726. {
  1727. if (editorUi.drive != null)
  1728. {
  1729. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1730. {
  1731. editorUi.pickFile(App.MODE_GOOGLE);
  1732. }, parent);
  1733. }
  1734. else if (googleEnabled)
  1735. {
  1736. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1737. {
  1738. // do nothing
  1739. }, parent, null, false);
  1740. }
  1741. if (editorUi.gitHub != null)
  1742. {
  1743. menu.addItem(mxResources.get('github') + '...', null, function()
  1744. {
  1745. editorUi.pickFile(App.MODE_GITHUB);
  1746. }, parent);
  1747. }
  1748. if (editorUi.dropbox != null)
  1749. {
  1750. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1751. {
  1752. editorUi.pickFile(App.MODE_DROPBOX);
  1753. }, parent);
  1754. }
  1755. else if (dropboxEnabled)
  1756. {
  1757. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1758. {
  1759. // do nothing
  1760. }, parent, null, false);
  1761. }
  1762. if (editorUi.oneDrive != null)
  1763. {
  1764. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1765. {
  1766. editorUi.pickFile(App.MODE_ONEDRIVE);
  1767. }, parent);
  1768. }
  1769. else if (oneDriveEnabled)
  1770. {
  1771. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1772. {
  1773. // do nothing
  1774. }, parent, null, false);
  1775. }
  1776. menu.addSeparator(parent);
  1777. if (isLocalStorage && urlParams['browser'] != '0')
  1778. {
  1779. menu.addItem(mxResources.get('browser') + '...', null, function()
  1780. {
  1781. editorUi.pickFile(App.MODE_BROWSER);
  1782. }, parent);
  1783. }
  1784. if (!mxClient.IS_IOS)
  1785. {
  1786. menu.addItem(mxResources.get('device') + '...', null, function()
  1787. {
  1788. editorUi.pickFile(App.MODE_DEVICE);
  1789. }, parent);
  1790. }
  1791. if (!editorUi.isOffline())
  1792. {
  1793. menu.addSeparator(parent);
  1794. menu.addItem(mxResources.get('url') + '...', null, function()
  1795. {
  1796. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1797. {
  1798. if (fileUrl != null && fileUrl.length > 0)
  1799. {
  1800. if (editorUi.getCurrentFile() == null)
  1801. {
  1802. window.location.hash = '#U' + encodeURIComponent(fileUrl);
  1803. }
  1804. else
  1805. {
  1806. window.openWindow(((mxClient.IS_CHROMEAPP) ?
  1807. 'https://www.draw.io/' : 'https://' + location.host + '/') +
  1808. window.location.search + '#U' + encodeURIComponent(fileUrl));
  1809. }
  1810. }
  1811. }, mxResources.get('url'));
  1812. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1813. dlg.init();
  1814. }, parent);
  1815. }
  1816. }));
  1817. this.put('newLibrary', new Menu(function(menu, parent)
  1818. {
  1819. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1820. {
  1821. if (editorUi.drive != null)
  1822. {
  1823. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1824. {
  1825. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GOOGLE);
  1826. }, parent);
  1827. }
  1828. else if (googleEnabled)
  1829. {
  1830. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1831. {
  1832. // do nothing
  1833. }, parent, null, false);
  1834. }
  1835. }
  1836. if (editorUi.gitHub != null)
  1837. {
  1838. menu.addItem(mxResources.get('github') + '...', null, function()
  1839. {
  1840. editorUi.showLibraryDialog(null, null, null, null, App.MODE_GITHUB);
  1841. }, parent);
  1842. }
  1843. if (editorUi.dropbox != null)
  1844. {
  1845. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1846. {
  1847. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DROPBOX);
  1848. }, parent);
  1849. }
  1850. else if (dropboxEnabled)
  1851. {
  1852. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1853. {
  1854. // do nothing
  1855. }, parent, null, false);
  1856. }
  1857. if (editorUi.oneDrive != null)
  1858. {
  1859. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1860. {
  1861. editorUi.showLibraryDialog(null, null, null, null, App.MODE_ONEDRIVE);
  1862. }, parent);
  1863. }
  1864. else if (oneDriveEnabled)
  1865. {
  1866. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1867. {
  1868. // do nothing
  1869. }, parent, null, false);
  1870. }
  1871. menu.addSeparator(parent);
  1872. if (isLocalStorage && urlParams['browser'] != '0')
  1873. {
  1874. menu.addItem(mxResources.get('browser') + '...', null, function()
  1875. {
  1876. editorUi.showLibraryDialog(null, null, null, null, App.MODE_BROWSER);
  1877. }, parent);
  1878. }
  1879. if (!mxClient.IS_IOS)
  1880. {
  1881. menu.addItem(mxResources.get('device') + '...', null, function()
  1882. {
  1883. editorUi.showLibraryDialog(null, null, null, null, App.MODE_DEVICE);
  1884. }, parent);
  1885. }
  1886. }));
  1887. this.put('openLibraryFrom', new Menu(function(menu, parent)
  1888. {
  1889. if (typeof(google) != 'undefined' && typeof(google.picker) != 'undefined')
  1890. {
  1891. if (editorUi.drive != null)
  1892. {
  1893. menu.addItem(mxResources.get('googleDrive') + '...', null, function()
  1894. {
  1895. editorUi.pickLibrary(App.MODE_GOOGLE);
  1896. }, parent);
  1897. }
  1898. else if (googleEnabled)
  1899. {
  1900. menu.addItem(mxResources.get('googleDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1901. {
  1902. // do nothing
  1903. }, parent, null, false);
  1904. }
  1905. }
  1906. if (editorUi.gitHub != null)
  1907. {
  1908. menu.addItem(mxResources.get('github') + '...', null, function()
  1909. {
  1910. editorUi.pickLibrary(App.MODE_GITHUB);
  1911. }, parent);
  1912. }
  1913. if (editorUi.dropbox != null)
  1914. {
  1915. menu.addItem(mxResources.get('dropbox') + '...', null, function()
  1916. {
  1917. editorUi.pickLibrary(App.MODE_DROPBOX);
  1918. }, parent);
  1919. }
  1920. else if (dropboxEnabled)
  1921. {
  1922. menu.addItem(mxResources.get('dropbox') + ' (' + mxResources.get('loading') + '...)', null, function()
  1923. {
  1924. // do nothing
  1925. }, parent, null, false);
  1926. }
  1927. if (editorUi.oneDrive != null)
  1928. {
  1929. menu.addItem(mxResources.get('oneDrive') + '...', null, function()
  1930. {
  1931. editorUi.pickLibrary(App.MODE_ONEDRIVE);
  1932. }, parent);
  1933. }
  1934. else if (oneDriveEnabled)
  1935. {
  1936. menu.addItem(mxResources.get('oneDrive') + ' (' + mxResources.get('loading') + '...)', null, function()
  1937. {
  1938. // do nothing
  1939. }, parent, null, false);
  1940. }
  1941. menu.addSeparator(parent);
  1942. if (isLocalStorage && urlParams['browser'] != '0')
  1943. {
  1944. menu.addItem(mxResources.get('browser') + '...', null, function()
  1945. {
  1946. editorUi.pickLibrary(App.MODE_BROWSER);
  1947. }, parent);
  1948. }
  1949. if (!mxClient.IS_IOS)
  1950. {
  1951. menu.addItem(mxResources.get('device') + '...', null, function()
  1952. {
  1953. editorUi.pickLibrary(App.MODE_DEVICE);
  1954. }, parent);
  1955. }
  1956. if (!editorUi.isOffline())
  1957. {
  1958. menu.addSeparator(parent);
  1959. menu.addItem(mxResources.get('url') + '...', null, function()
  1960. {
  1961. var dlg = new FilenameDialog(editorUi, '', mxResources.get('open'), function(fileUrl)
  1962. {
  1963. if (fileUrl != null && fileUrl.length > 0 && editorUi.spinner.spin(document.body, mxResources.get('loading')))
  1964. {
  1965. var realUrl = fileUrl;
  1966. if (!editorUi.isCorsEnabledForUrl(fileUrl))
  1967. {
  1968. realUrl = PROXY_URL + '?url=' + encodeURIComponent(fileUrl);
  1969. }
  1970. // Uses proxy to avoid CORS issues
  1971. mxUtils.get(realUrl, function(req)
  1972. {
  1973. if (req.getStatus() >= 200 && req.getStatus() <= 299)
  1974. {
  1975. editorUi.spinner.stop();
  1976. try
  1977. {
  1978. editorUi.loadLibrary(new UrlLibrary(this, req.getText(), fileUrl));
  1979. }
  1980. catch (e)
  1981. {
  1982. editorUi.handleError(e, mxResources.get('errorLoadingFile'));
  1983. }
  1984. }
  1985. else
  1986. {
  1987. editorUi.spinner.stop();
  1988. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1989. }
  1990. }, function()
  1991. {
  1992. editorUi.spinner.stop();
  1993. editorUi.handleError(null, mxResources.get('errorLoadingFile'));
  1994. });
  1995. }
  1996. }, mxResources.get('url'));
  1997. editorUi.showDialog(dlg.container, 300, 80, true, true);
  1998. dlg.init();
  1999. }, parent);
  2000. }
  2001. }));
  2002. // Overrides edit menu to add find
  2003. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  2004. {
  2005. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
  2006. 'find', '-',
  2007. 'editData', 'editTooltip', 'editStyle', '-', 'edit', '-', 'editLink', 'openLink', '-',
  2008. 'selectVertices', 'selectEdges', 'selectAll', 'selectNone', '-', 'lockUnlock']);
  2009. })));
  2010. // Overrides view menu to add search and scratchpad
  2011. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  2012. {
  2013. this.addMenuItems(menu, ((this.editorUi.format != null) ? ['formatPanel'] : []).
  2014. concat(['outline', 'layers', '-']));
  2015. this.addMenuItems(menu, ['-', 'search'], parent);
  2016. if (isLocalStorage || mxClient.IS_CHROMEAPP)
  2017. {
  2018. var item = this.addMenuItem(menu, 'scratchpad', parent);
  2019. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2020. {
  2021. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000042367');
  2022. }
  2023. }
  2024. this.addMenuItems(menu, ['shapes', '-', 'pageView', 'pageScale', '-',
  2025. 'scrollbars', 'tooltips', '-',
  2026. 'grid', 'guides'], parent);
  2027. if (mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))
  2028. {
  2029. this.addMenuItem(menu, 'shadowVisible', parent);
  2030. }
  2031. this.addMenuItems(menu, ['-', 'connectionArrows', 'connectionPoints', '-',
  2032. 'resetView', 'zoomIn', 'zoomOut'], parent);
  2033. })));
  2034. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  2035. {
  2036. if (urlParams['embed'] != '1')
  2037. {
  2038. this.addSubmenu('theme', menu, parent);
  2039. menu.addSeparator(parent);
  2040. }
  2041. this.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-'], parent);
  2042. if (typeof(MathJax) !== 'undefined')
  2043. {
  2044. var item = this.addMenuItem(menu, 'mathematicalTypesetting', parent);
  2045. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  2046. }
  2047. this.addMenuItems(menu, ['autosave', '-', 'createShape', 'editDiagram'], parent);
  2048. menu.addSeparator(parent);
  2049. if (urlParams['embed'] != '1' && isLocalStorage)
  2050. {
  2051. this.addMenuItems(menu, ['showStartScreen'], parent);
  2052. }
  2053. if (!editorUi.isOfflineApp() && urlParams['embed'] != '1')
  2054. {
  2055. this.addMenuItems(menu, ['plugins', '-'], parent);
  2056. var item = this.addMenuItem(menu, 'tags', parent);
  2057. if (!editorUi.isOffline() || mxClient.IS_CHROMEAPP)
  2058. {
  2059. this.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000046966');
  2060. }
  2061. this.addMenuItems(menu, ['-', 'offline'], parent);
  2062. }
  2063. else
  2064. {
  2065. menu.addSeparator(parent);
  2066. this.addMenuItem(menu, 'tags', parent);
  2067. menu.addSeparator(parent);
  2068. }
  2069. if (!editorUi.isOffline() && !navigator.standalone && urlParams['embed'] != '1')
  2070. {
  2071. this.addMenuItems(menu, ['chromeApp'], parent);
  2072. }
  2073. })));
  2074. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  2075. {
  2076. if (urlParams['embed'] == '1')
  2077. {
  2078. this.addSubmenu('importFrom', menu, parent);
  2079. this.addSubmenu('exportAs', menu, parent);
  2080. this.addSubmenu('embed', menu, parent);
  2081. if (urlParams['libraries'] == '1')
  2082. {
  2083. this.addMenuItems(menu, ['-'], parent);
  2084. this.addSubmenu('newLibrary', menu, parent);
  2085. this.addSubmenu('openLibraryFrom', menu, parent);
  2086. }
  2087. this.addMenuItems(menu, ['-', 'pageSetup', 'print', '-', 'save'], parent);
  2088. if (urlParams['saveAndExit'] == '1')
  2089. {
  2090. this.addMenuItems(menu, ['saveAndExit'], parent);
  2091. }
  2092. this.addMenuItems(menu, ['exit'], parent);
  2093. }
  2094. else
  2095. {
  2096. var file = this.editorUi.getCurrentFile();
  2097. if (file != null && file.constructor == DriveFile)
  2098. {
  2099. if (file.isRestricted())
  2100. {
  2101. this.addMenuItems(menu, ['exportOptionsDisabled'], parent);
  2102. }
  2103. if (file.realtime == null)
  2104. {
  2105. this.addMenuItems(menu, ['save', 'share', '-'], parent);
  2106. }
  2107. else
  2108. {
  2109. if (!file.isAutosave())
  2110. {
  2111. this.addMenuItems(menu, ['save'], parent);
  2112. }
  2113. this.addMenuItems(menu, ['share', 'chatWindowTitle', '-'], parent);
  2114. }
  2115. }
  2116. else
  2117. {
  2118. this.addMenuItems(menu, ['new'], parent);
  2119. }
  2120. this.addSubmenu('openFrom', menu, parent);
  2121. if (isLocalStorage)
  2122. {
  2123. this.addSubmenu('openRecent', menu, parent);
  2124. }
  2125. if (file != null && file.constructor == DriveFile)
  2126. {
  2127. this.addMenuItems(menu, ['new', '-', 'rename', 'makeCopy', 'moveToFolder'], parent);
  2128. }
  2129. else
  2130. {
  2131. this.addMenuItems(menu, ['-', 'save', 'saveAs', '-', 'rename'], parent);
  2132. if (editorUi.isOfflineApp())
  2133. {
  2134. if (!editorUi.isOffline())
  2135. {
  2136. this.addMenuItems(menu, ['upload'], parent);
  2137. }
  2138. }
  2139. else
  2140. {
  2141. this.addMenuItems(menu, ['makeCopy'], parent);
  2142. if (file != null && file.constructor == OneDriveFile)
  2143. {
  2144. this.addMenuItems(menu, ['moveToFolder'], parent);
  2145. }
  2146. }
  2147. }
  2148. menu.addSeparator(parent);
  2149. this.addSubmenu('importFrom', menu, parent);
  2150. this.addSubmenu('exportAs', menu, parent);
  2151. menu.addSeparator(parent);
  2152. this.addSubmenu('embed', menu, parent);
  2153. this.addSubmenu('publish', menu, parent);
  2154. menu.addSeparator(parent);
  2155. this.addSubmenu('newLibrary', menu, parent);
  2156. this.addSubmenu('openLibraryFrom', menu, parent);
  2157. if (file != null && (file.constructor == DriveFile || file.constructor == DropboxFile))
  2158. {
  2159. this.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  2160. }
  2161. if (file != null && file.constructor == DriveFile)
  2162. {
  2163. this.addMenuItems(menu, ['createRevision'], parent);
  2164. }
  2165. this.addMenuItems(menu, ['-', 'pageSetup'], parent);
  2166. // Cannot use print in standalone mode on iOS as we cannot open new windows
  2167. if (!mxClient.IS_IOS || !navigator.standalone)
  2168. {
  2169. this.addMenuItems(menu, ['print'], parent);
  2170. }
  2171. this.addMenuItems(menu, ['-', 'close']);
  2172. }
  2173. })));
  2174. };
  2175. /**
  2176. * Replaces help menu label with icon on small screen
  2177. */
  2178. var menuCreated = Menus.prototype.menuCreated;
  2179. Menus.prototype.menuCreated = function(menu, elt)
  2180. {
  2181. if (screen.width <= 480 && menu == this.get('help'))
  2182. {
  2183. elt.style.paddingRight = '0px';
  2184. elt.style.paddingLeft = '0px';
  2185. elt.innerHTML = '';
  2186. var icon = document.createElement('img');
  2187. icon.setAttribute('border', '0');
  2188. icon.setAttribute('valign', 'bottom');
  2189. icon.setAttribute('src', Editor.helpImage);
  2190. elt.appendChild(icon);
  2191. }
  2192. menuCreated.apply(this, arguments);
  2193. };
  2194. })();