Menus.js 74 KB

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