Menus.js 75 KB

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