Minimal.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. /**
  2. * Code for the minimal UI theme.
  3. */
  4. EditorUi.initMinimalTheme = function()
  5. {
  6. // Disabled in lightbox and chromeless mode
  7. if (urlParams['lightbox'] == '1' || urlParams['chrome'] == '0' || typeof window.Format === 'undefined' || typeof window.Menus === 'undefined')
  8. {
  9. window.uiTheme = null;
  10. return;
  11. }
  12. var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  13. try
  14. {
  15. var style = document.createElement('style')
  16. style.type = 'text/css';
  17. style.innerHTML = '* { -webkit-font-smoothing: antialiased; }' +
  18. 'html body .mxWindow button.geBtn { font-size:12px !important; margin-left: 0; }' +
  19. 'html body table.mxWindow td.mxWindowPane div.mxWindowPane *:not(svg *) { font-size:9pt; }' +
  20. 'html body div.diagramContainer button, html body button.geBtn { font-size:14px; font-weight:700;border-radius: 5px; }' +
  21. 'html body button.geBtn:active { opacity: 0.6; }' +
  22. 'html body a.geMenuItem { opacity: 0.75; }' +
  23. 'html body a.geMenuItem[disabled] { opacity: 0.2; }' +
  24. 'html body a.geMenuItem[disabled]:active { opacity: 0.2; }' +
  25. 'html body div.geActivePage { opacity: 0.7; }' +
  26. 'html body a.geMenuItem:active { opacity: 0.2; }' +
  27. 'html body .geToolbarButton { opacity: 0.3; }' +
  28. 'html body .geToolbarButton:active { opacity: 0.15; }' +
  29. 'html body .geStatus:active { opacity: 0.5; }' +
  30. 'html table.mxPopupMenu tr.mxPopupMenuItemHover:active { opacity:0.7; }' +
  31. 'html body .geDialog input, html body .geToolbarContainer input, html body .mxWindow input {padding:2px;display:inline-block; }' +
  32. 'div.geDialog { border-radius: 5px; }' +
  33. 'html body div.geDialog button.geBigButton { color: #fff !important; }' +
  34. '.mxWindow button, .geDialog select, .mxWindow select { display:inline-block; }' +
  35. 'html body .mxWindow .geColorBtn, html body .geDialog .geColorBtn { background: none; }' +
  36. 'html body div.diagramContainer button, html body .mxWindow button, html body .geDialog button { min-width: 0px; border-radius: 5px; color: #353535 !important; border-style: solid; border-width: 1px; border-color: rgb(216, 216, 216); }' +
  37. 'html body div.diagramContainer button:hover, html body .mxWindow button:hover, html body .geDialog button:hover { border-color: rgb(177, 177, 177); }' +
  38. 'html body div.diagramContainer button:active, html body .mxWindow button:active, html body .geDialog button:active { opacity: 0.6; }' +
  39. 'div.diagramContainer button.geBtn, .mxWindow button.geBtn, .geDialog button.geBtn { min-width:72px; font-weight: 600; background: none; }' +
  40. 'div.diagramContainer button.gePrimaryBtn, .mxWindow button.gePrimaryBtn, .geDialog button.gePrimaryBtn, html body .gePrimaryBtn { background: #29b6f2; color: #fff !important; border: none; box-shadow: none; }' +
  41. 'html body .gePrimaryBtn:hover { background: #29b6f2; border: none; box-shadow: inherit; }' +
  42. 'html body button.gePrimaryBtn:hover { background: #29b6f2; border: none; }' +
  43. '.geBtn button { min-width:72px !important; }' +
  44. 'div.geToolbarContainer a.geButton { margin:2px; padding: 0 2px 4px 2px; } ' +
  45. '.geDialog, .mxWindow td.mxWindowPane *, div.geSprite, td.mxWindowTitle, .geDiagramContainer { box-sizing:content-box; }' +
  46. '.mxWindow div button.geStyleButton { box-sizing: border-box; }' +
  47. 'table.mxWindow td.mxWindowPane button.geColorBtn { padding:0px; box-sizing: border-box; }' +
  48. 'td.mxWindowPane .geSidebarContainer button { padding:2px 0 2px 0; box-sizing: border-box; }' +
  49. 'html body .geMenuItem { font-size:14px; text-decoration: none; font-weight: normal; padding: 6px 10px 6px 10px; border: none; border-radius: 5px; color: #353535; box-shadow: inset 0 0 0 1px rgba(0,0,0,.11), inset 0 -1px 0 0 rgba(0,0,0,.08), 0 1px 2px 0 rgba(0,0,0,.04); }' +
  50. // Styling for Minimal
  51. '.geToolbarContainer { background:#fff !important; }' +
  52. 'div.mxWindow .geSidebarContainer .geTitle { background-color:#fdfdfd; }' +
  53. 'div.mxWindow .geSidebarContainer .geTitle:hover { background-color:#fafafa; }' +
  54. 'div.geSidebar { background-color: #fff !important;}' +
  55. 'div.mxWindow td.mxWindowPane button { background-image: none; float: none; }' +
  56. 'td.mxWindowTitle { height: 22px !important; background: none !important; font-size: 13px !important; text-align:center !important; border-bottom:1px solid lightgray; }' +
  57. 'div.mxWindow, div.mxWindowTitle { background-image: none !important; background-color:#fff !important; }' +
  58. 'div.mxWindow { border-radius:5px; box-shadow: 0px 0px 2px #C0C0C0 !important;}' +
  59. 'div.mxWindow * { font-family: inherit !important; }' +
  60. // Minimal Style UI
  61. 'html div.geVerticalHandle { position:absolute;bottom:0px;left:50%;cursor:row-resize;width:11px;height:11px;background:white;margin-bottom:-6px; margin-left:-6px; border: none; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.11), inset 0 -1px 0 0 rgba(0,0,0,.08), 0 1px 2px 0 rgba(0,0,0,.04); }' +
  62. 'html div.geInactivePage { background: rgb(249, 249, 249) !important; color:lightgray !important; } ' +
  63. 'html div.geActivePage { background: white !important;color: #353535 !important; } ' +
  64. 'html div.mxRubberband { border:1px solid; border-color: #29b6f2 !important; background:rgba(41,182,242,0.5) !important; } ' +
  65. 'html body div.mxPopupMenu { border-radius:5px; border:1px solid #c0c0c0; padding:5px 0 5px 0; box-shadow: 0px 4px 17px -4px rgba(96,96,96,1); } ' +
  66. 'html table.mxPopupMenu td.mxPopupMenuItem { color: #353535; font-size: 14px; padding-top: 4px; padding-bottom: 4px; }' +
  67. 'html table.mxPopupMenu tr.mxPopupMenuItemHover { background-color: #29b6f2; }' +
  68. 'html tr.mxPopupMenuItemHover td.mxPopupMenuItem, html tr.mxPopupMenuItemHover td.mxPopupMenuItem span { color: #fff !important; }' +
  69. 'html tr.mxPopupMenuItem, html td.mxPopupMenuItem { transition-property: none !important; }' +
  70. 'html table.mxPopupMenu hr { height: 2px; background-color: rgba(0,0,0,.07); margin: 5px 0; }' +
  71. // Fixes checkbox and radio size on iOS
  72. ((mxClient.IS_IOS) ? 'html input[type=checkbox], html input[type=radio] { height:12px; }' : '');
  73. document.getElementsByTagName('head')[0].appendChild(style);
  74. }
  75. catch (e)
  76. {
  77. // ignore
  78. }
  79. /**
  80. *
  81. */
  82. var WrapperWindow = function(editorUi, title, x, y, w, h, fn)
  83. {
  84. var graph = editorUi.editor.graph;
  85. var div = document.createElement('div');
  86. div.className = 'geSidebarContainer';
  87. div.style.position = 'absolute';
  88. div.style.width = '100%';
  89. div.style.height = '100%';
  90. div.style.border = '1px solid whiteSmoke';
  91. div.style.overflowX = 'hidden';
  92. div.style.overflowY = 'auto';
  93. fn(div);
  94. this.window = new mxWindow(title, div, x, y, w, h, true, true);
  95. this.window.destroyOnClose = false;
  96. this.window.setMaximizable(false);
  97. this.window.setResizable(true);
  98. this.window.setClosable(true);
  99. this.window.setVisible(true);
  100. this.window.setLocation = function(x, y)
  101. {
  102. var iiw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  103. var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  104. x = Math.max(0, Math.min(x, iiw - this.table.clientWidth));
  105. y = Math.max(0, Math.min(y, ih - this.table.clientHeight - 48));
  106. if (this.getX() != x || this.getY() != y)
  107. {
  108. mxWindow.prototype.setLocation.apply(this, arguments);
  109. }
  110. };
  111. // Workaround for text selection starting in Safari
  112. // when dragging shapes outside of window
  113. if (mxClient.IS_SF)
  114. {
  115. this.window.div.onselectstart = mxUtils.bind(this, function(evt)
  116. {
  117. if (evt == null)
  118. {
  119. evt = window.event;
  120. }
  121. return (evt != null && editorUi.isSelectionAllowed(evt));
  122. });
  123. }
  124. };
  125. function toggleFormat(ui)
  126. {
  127. var graph = ui.editor.graph;
  128. graph.popupMenuHandler.hideMenu();
  129. if (ui.formatWindow == null)
  130. {
  131. ui.formatWindow = new WrapperWindow(ui, mxResources.get('format'),
  132. Math.max(20, ui.diagramContainer.clientWidth - 240 - 12), 56,
  133. 240, Math.min(566, graph.container.clientHeight - 10), function(container)
  134. {
  135. var format = ui.createFormat(container);
  136. format.init();
  137. return format;
  138. });
  139. ui.formatWindow.window.minimumSize = new mxRectangle(0, 0, 240, 80);
  140. ui.formatWindow.window.setVisible(true);
  141. }
  142. else
  143. {
  144. ui.formatWindow.window.setVisible(!ui.formatWindow.window.isVisible());
  145. }
  146. if (ui.formatWindow.window.isVisible())
  147. {
  148. ui.formatWindow.window.fit();
  149. }
  150. };
  151. function toggleShapes(ui)
  152. {
  153. var graph = ui.editor.graph;
  154. graph.popupMenuHandler.hideMenu();
  155. var rect = new mxRectangle();
  156. if (ui.sidebarWindow == null)
  157. {
  158. var w = Math.min(graph.container.clientWidth - 10, 266);
  159. ui.sidebarWindow = new WrapperWindow(ui, mxResources.get('shapes'), 10, 56,
  160. w - 6, Math.min(650, graph.container.clientHeight - 30),
  161. function(container)
  162. {
  163. var div = document.createElement('div');
  164. div.style.cssText = 'position:absolute;left:0;right:0;border-top:1px solid lightgray;' +
  165. 'height:24px;bottom:31px;text-align:center;cursor:pointer;padding:6px 0 0 0;';
  166. div.className = 'geTitle';
  167. div.innerHTML = '<span style="font-size:18px;margin-right:5px;">+</span>';
  168. mxUtils.write(div, mxResources.get('moreShapes'));
  169. container.appendChild(div);
  170. mxEvent.addListener(div, 'click', function()
  171. {
  172. ui.actions.get('shapes').funct();
  173. });
  174. var menuObj = new Menubar(ui, container);
  175. function addMenu(id, label)
  176. {
  177. var menu = ui.menus.get(id);
  178. var elt = menuObj.addMenu(label, mxUtils.bind(this, function()
  179. {
  180. // Allows extensions of menu.functid
  181. menu.funct.apply(this, arguments);
  182. }));
  183. elt.style.cssText = 'position:absolute;border-top:1px solid lightgray;width:50%;' +
  184. 'height:24px;bottom:0px;text-align:center;cursor:pointer;padding:6px 0 0 0;cusor:pointer;';
  185. elt.className = 'geTitle';
  186. container.appendChild(elt);
  187. return elt;
  188. }
  189. if (Editor.enableCustomLibraries && (urlParams['embed'] != '1' || urlParams['libraries'] == '1'))
  190. {
  191. // Defined in native apps together with openLibrary
  192. if (ui.actions.get('newLibrary') != null)
  193. {
  194. var div = document.createElement('div');
  195. div.style.cssText = 'position:absolute;left:0px;width:50%;border-top:1px solid lightgray;' +
  196. 'height:30px;bottom:0px;text-align:center;cursor:pointer;padding:0px;';
  197. div.className = 'geTitle';
  198. var span = document.createElement('span');
  199. span.style.cssText = 'position:relative;top:6px;';
  200. mxUtils.write(span, mxResources.get('newLibrary'));
  201. div.appendChild(span);
  202. container.appendChild(div);
  203. mxEvent.addListener(div, 'click', ui.actions.get('newLibrary').funct);
  204. var div = document.createElement('div');
  205. div.style.cssText = 'position:absolute;left:50%;width:50%;border-top:1px solid lightgray;' +
  206. 'height:30px;bottom:0px;text-align:center;cursor:pointer;padding:0px;border-left: 1px solid lightgray;';
  207. div.className = 'geTitle';
  208. var span = document.createElement('span');
  209. span.style.cssText = 'position:relative;top:6px;';
  210. mxUtils.write(span, mxResources.get('openLibrary'));
  211. div.appendChild(span);
  212. container.appendChild(div);
  213. mxEvent.addListener(div, 'click', ui.actions.get('openLibrary').funct);
  214. }
  215. else
  216. {
  217. var elt = addMenu('newLibrary', mxResources.get('newLibrary'));
  218. elt.style.left = '0';
  219. var elt = addMenu('openLibraryFrom', mxResources.get('openLibraryFrom'));
  220. elt.style.borderLeft = '1px solid lightgray';
  221. elt.style.left = '50%';
  222. }
  223. }
  224. else
  225. {
  226. div.style.bottom = '0';
  227. }
  228. container.appendChild(ui.sidebar.container);
  229. container.style.overflow = 'hidden';
  230. return container;
  231. });
  232. ui.sidebarWindow.window.minimumSize = new mxRectangle(0, 0, 90, 90);
  233. ui.sidebarWindow.window.setVisible(true);
  234. ui.getLocalData('sidebar', function(value)
  235. {
  236. ui.sidebar.showEntries(value, null, true);
  237. });
  238. ui.restoreLibraries();
  239. }
  240. else
  241. {
  242. ui.sidebarWindow.window.setVisible(!ui.sidebarWindow.window.isVisible());
  243. }
  244. if (ui.sidebarWindow.window.isVisible())
  245. {
  246. ui.sidebarWindow.window.fit();
  247. }
  248. };
  249. // Changes colors for some UI elements
  250. var fill = '#29b6f2';
  251. var stroke = '#ffffff';
  252. Editor.checkmarkImage = Graph.createSvgImage(22, 18, '<path transform="translate(4 0)" d="M7.181,15.007a1,1,0,0,1-.793-0.391L3.222,10.5A1,1,0,1,1,4.808,9.274L7.132,12.3l6.044-8.86A1,1,0,1,1,14.83,4.569l-6.823,10a1,1,0,0,1-.8.437H7.181Z" fill="' + fill + '"/>').src;
  253. mxWindow.prototype.closeImage = Graph.createSvgImage(18, 10, '<path d="M 5 1 L 13 9 M 13 1 L 5 9" stroke="#C0C0C0" stroke-width="2"/>').src;
  254. mxWindow.prototype.minimizeImage = Graph.createSvgImage(14, 10, '<path d="M 3 7 L 7 3 L 11 7" stroke="#C0C0C0" stroke-width="2" fill="#ffffff"/>').src;
  255. mxWindow.prototype.normalizeImage = Graph.createSvgImage(14, 10, '<path d="M 3 3 L 7 7 L 11 3" stroke="#C0C0C0" stroke-width="2" fill="#ffffff"/>').src;
  256. mxConstraintHandler.prototype.pointImage = Graph.createSvgImage(5, 5, '<path d="m 0 0 L 5 5 M 0 5 L 5 0" stroke="' + fill + '"/>');
  257. mxOutline.prototype.sizerImage = null;
  258. mxConstants.VERTEX_SELECTION_COLOR = '#C0C0C0';
  259. mxConstants.EDGE_SELECTION_COLOR = '#C0C0C0';
  260. mxConstants.CONNECT_HANDLE_FILLCOLOR = '#cee7ff';
  261. mxConstants.DEFAULT_VALID_COLOR = fill;
  262. mxConstants.GUIDE_COLOR = '#C0C0C0';
  263. mxConstants.HIGHLIGHT_STROKEWIDTH = 5;
  264. mxConstants.HIGHLIGHT_OPACITY = 35;
  265. mxConstants.OUTLINE_COLOR = '#29b6f2';
  266. mxConstants.OUTLINE_HANDLE_FILLCOLOR = '#29b6f2';
  267. mxConstants.OUTLINE_HANDLE_STROKECOLOR = '#fff';
  268. Graph.prototype.svgShadowColor = '#3D4574';
  269. Graph.prototype.svgShadowOpacity = '0.4';
  270. Graph.prototype.svgShadowSize = '0.6';
  271. Graph.prototype.svgShadowBlur = '1.2';
  272. Format.prototype.inactiveTabBackgroundColor = '#f0f0f0';
  273. mxGraphHandler.prototype.previewColor = '#C0C0C0';
  274. mxRubberband.prototype.defaultOpacity = 50;
  275. HoverIcons.prototype.inactiveOpacity = 25;
  276. Format.prototype.showCloseButton = false;
  277. EditorUi.prototype.closableScratchpad = false;
  278. EditorUi.prototype.toolbarHeight = 46;
  279. EditorUi.prototype.footerHeight = 0;
  280. Graph.prototype.editAfterInsert = true;
  281. /**
  282. * Sets the XML node for the current diagram.
  283. */
  284. Editor.prototype.isChromelessView = function()
  285. {
  286. return false;
  287. };
  288. /**
  289. * Sets the XML node for the current diagram.
  290. */
  291. Graph.prototype.isLightboxView = function()
  292. {
  293. return false;
  294. };
  295. // Overridden to ignore tabContainer height for diagramContainer
  296. var editorUiUpdateTabContainer = EditorUi.prototype.updateTabContainer;
  297. EditorUi.prototype.updateTabContainer = function()
  298. {
  299. if (this.tabContainer != null)
  300. {
  301. // Makes room for view zoom menu
  302. this.tabContainer.style.right = '70px';
  303. this.diagramContainer.style.bottom = '30px';
  304. }
  305. editorUiUpdateTabContainer.apply(this, arguments);
  306. };
  307. // Overridden to update save menu state
  308. /**
  309. * Updates action states depending on the selection.
  310. */
  311. var editorUiUpdateActionStates = EditorUi.prototype.updateActionStates;
  312. EditorUi.prototype.updateActionStates = function()
  313. {
  314. editorUiUpdateActionStates.apply(this, arguments);
  315. this.menus.get('save').setEnabled(this.getCurrentFile() != null || urlParams['embed'] == '1');
  316. };
  317. // Hides keyboard shortcuts in menus
  318. var menusAddShortcut = Menus.prototype.addShortcut;
  319. Menus.prototype.addShortcut = function(item, action)
  320. {
  321. if (action.shortcut != null && iw < 900 && !mxClient.IS_IOS)
  322. {
  323. var td = item.firstChild.nextSibling;
  324. td.setAttribute('title', action.shortcut);
  325. }
  326. else
  327. {
  328. menusAddShortcut.apply(this, arguments);
  329. }
  330. };
  331. var appUpdateUserElement = App.prototype.updateUserElement;
  332. App.prototype.updateUserElement = function()
  333. {
  334. appUpdateUserElement.apply(this, arguments);
  335. if (this.userElement != null)
  336. {
  337. var elt = this.userElement;
  338. elt.style.cssText = 'display:inline-block;position:relative;margin-right:4px;cursor:pointer;';
  339. elt.className = 'geToolbarButton';
  340. elt.innerHTML = '';
  341. elt.style.backgroundImage = 'url(' + Editor.userImage + ')';
  342. elt.style.backgroundPosition = 'center center';
  343. elt.style.backgroundRepeat = 'no-repeat';
  344. elt.style.backgroundSize = '24px 24px';
  345. elt.style.height = '24px';
  346. elt.style.width = '24px';
  347. elt.style.cssFloat = 'right';
  348. elt.setAttribute('title', mxResources.get('changeUser'));
  349. }
  350. };
  351. var appUpdateButtonContainer = App.prototype.updateButtonContainer;
  352. App.prototype.updateButtonContainer = function()
  353. {
  354. appUpdateButtonContainer.apply(this, arguments);
  355. if (this.shareButton != null)
  356. {
  357. var elt = this.shareButton;
  358. elt.style.cssText = 'display:inline-block;position:relative;box-sizing:border-box;margin-right:4px;cursor:pointer;';
  359. elt.className = 'geToolbarButton';
  360. elt.innerHTML = '';
  361. elt.style.backgroundImage = 'url(' + Editor.shareImage + ')';
  362. elt.style.backgroundPosition = 'center center';
  363. elt.style.backgroundRepeat = 'no-repeat';
  364. elt.style.backgroundSize = '24px 24px';
  365. elt.style.height = '24px';
  366. elt.style.width = '24px';
  367. }
  368. };
  369. EditorUi.prototype.addEmbedButtons = function()
  370. {
  371. if (this.buttonContainer != null)
  372. {
  373. var div = document.createElement('div');
  374. div.style.display = 'inline-block';
  375. div.style.position = 'relative';
  376. div.style.marginTop = '2px';
  377. var button = document.createElement('button');
  378. mxUtils.write(button, mxResources.get('save'));
  379. button.setAttribute('title', mxResources.get('save') + ' (' + Editor.ctrlKey + '+S)');
  380. button.className = (urlParams['saveAndExit'] == '1') ? 'geMenuItem' : 'geMenuItem gePrimaryBtn';
  381. button.style.fontSize = '14px';
  382. button.style.padding = '6px';
  383. button.style.borderRadius = '3px';
  384. button.style.marginLeft = '8px';
  385. button.style.cursor = 'pointer';
  386. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  387. {
  388. this.actions.get('save').funct();
  389. }));
  390. div.appendChild(button);
  391. if (urlParams['saveAndExit'] == '1')
  392. {
  393. button = document.createElement('a');
  394. mxUtils.write(button, mxResources.get('saveAndExit'));
  395. button.setAttribute('title', mxResources.get('saveAndExit'));
  396. button.className = 'geMenuItem gePrimaryBtn';
  397. button.style.fontSize = '14px';
  398. button.style.marginLeft = '6px';
  399. button.style.padding = '6px';
  400. button.style.cursor = 'pointer';
  401. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  402. {
  403. this.actions.get('saveAndExit').funct();
  404. }));
  405. div.appendChild(button);
  406. }
  407. button = document.createElement('a');
  408. mxUtils.write(button, mxResources.get('exit'));
  409. button.setAttribute('title', mxResources.get('exit'));
  410. button.className = 'geMenuItem';
  411. button.style.fontSize = '14px';
  412. button.style.marginLeft = '6px';
  413. button.style.padding = '6px';
  414. button.style.cursor = 'pointer';
  415. mxEvent.addListener(button, 'click', mxUtils.bind(this, function()
  416. {
  417. this.actions.get('exit').funct();
  418. }));
  419. div.appendChild(button);
  420. this.buttonContainer.appendChild(div);
  421. this.buttonContainer.style.top = '6px';
  422. }
  423. };
  424. // Fixes sidebar tooltips (previews)
  425. Sidebar.prototype.getTooltipOffset = function()
  426. {
  427. var off = mxUtils.getOffset(this.editorUi.sidebarWindow.window.div);
  428. off.y += 40;
  429. return off;
  430. };
  431. // Adds context menu items
  432. var menuCreatePopupMenu = Menus.prototype.createPopupMenu;
  433. Menus.prototype.createPopupMenu = function(menu, cell, evt)
  434. {
  435. var graph = this.editorUi.editor.graph;
  436. menu.smartSeparators = true;
  437. menuCreatePopupMenu.apply(this, arguments);
  438. var promptSpacing = mxUtils.bind(this, function(defaultValue, fn)
  439. {
  440. var dlg = new FilenameDialog(this.editorUi, defaultValue, mxResources.get('apply'), function(newValue)
  441. {
  442. fn(parseFloat(newValue));
  443. }, mxResources.get('spacing'));
  444. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  445. dlg.init();
  446. });
  447. if (graph.getSelectionCount() == 1)
  448. {
  449. this.addMenuItems(menu, ['editTooltip', '-', 'editStyle', 'editGeometry', '-'], null, evt);
  450. if (graph.isCellFoldable(graph.getSelectionCell()))
  451. {
  452. this.addMenuItems(menu, (graph.isCellCollapsed(cell)) ? ['expand'] : ['collapse'], null, evt);
  453. }
  454. this.addMenuItems(menu, ['collapsible', '-', 'lockUnlock', 'enterGroup'], null, evt);
  455. menu.addSeparator();
  456. this.addSubmenu('layout', menu);
  457. }
  458. else if (graph.isSelectionEmpty() && graph.isEnabled())
  459. {
  460. menu.addSeparator();
  461. this.addMenuItems(menu, ['editData'], null, evt);
  462. menu.addSeparator();
  463. this.addSubmenu('layout', menu);
  464. this.addSubmenu('view', menu, null, mxResources.get('options'));
  465. this.addMenuItems(menu, ['-', 'exitGroup'], null, evt);
  466. }
  467. else if (graph.isEnabled())
  468. {
  469. this.addMenuItems(menu, ['-', 'lockUnlock'], null, evt);
  470. }
  471. };
  472. // Overridden to toggle window instead
  473. EditorUi.prototype.toggleFormatPanel = function(forceHide)
  474. {
  475. if (this.formatWindow != null)
  476. {
  477. this.formatWindow.window.setVisible((forceHide) ?
  478. false : !this.formatWindow.window.isVisible());
  479. }
  480. else
  481. {
  482. toggleFormat(this);
  483. }
  484. };
  485. DiagramFormatPanel.prototype.isMathOptionVisible = function()
  486. {
  487. return true;
  488. };
  489. // Initializes the user interface
  490. var editorUiDestroy = EditorUi.prototype.destroy;
  491. EditorUi.prototype.destroy = function()
  492. {
  493. if (this.sidebarWindow != null)
  494. {
  495. this.sidebarWindow.window.setVisible(false);
  496. this.sidebarWindow.window.destroy();
  497. this.sidebarWindow = null;
  498. }
  499. if (this.formatWindow != null)
  500. {
  501. this.formatWindow.window.setVisible(false);
  502. this.formatWindow.window.destroy();
  503. this.formatWindow = null;
  504. }
  505. if (this.actions.outlineWindow != null)
  506. {
  507. this.actions.outlineWindow.window.setVisible(false);
  508. this.actions.outlineWindow.window.destroy();
  509. this.actions.outlineWindow = null;
  510. }
  511. if (this.actions.layersWindow != null)
  512. {
  513. this.actions.layersWindow.window.setVisible(false);
  514. this.actions.layersWindow.window.destroy();
  515. this.actions.layersWindow = null;
  516. }
  517. if (this.menus.tagsWindow != null)
  518. {
  519. this.menus.tagsWindow.window.setVisible(false);
  520. this.menus.tagsWindow.window.destroy();
  521. this.menus.tagsWindow = null;
  522. }
  523. if (this.menus.findWindow != null)
  524. {
  525. this.menus.findWindow.window.setVisible(false);
  526. this.menus.findWindow.window.destroy();
  527. this.menus.findWindow = null;
  528. }
  529. editorUiDestroy.apply(this, arguments);
  530. };
  531. // Hides windows when a file is closed
  532. var editorUiSetGraphEnabled = EditorUi.prototype.setGraphEnabled;
  533. EditorUi.prototype.setGraphEnabled = function(enabled)
  534. {
  535. editorUiSetGraphEnabled.apply(this, arguments);
  536. if (!enabled)
  537. {
  538. if (this.sidebarWindow != null)
  539. {
  540. this.sidebarWindow.window.setVisible(false);
  541. }
  542. if (this.formatWindow != null)
  543. {
  544. this.formatWindow.window.setVisible(false);
  545. }
  546. }
  547. };
  548. // Disables centering of graph after iframe resize
  549. EditorUi.prototype.chromelessWindowResize = function() {};
  550. // Adds actions and menus
  551. var menusInit = Menus.prototype.init;
  552. Menus.prototype.init = function()
  553. {
  554. menusInit.apply(this, arguments);
  555. var ui = this.editorUi;
  556. var graph = ui.editor.graph;
  557. ui.actions.get('editDiagram').label = mxResources.get('formatXml') + '...';
  558. ui.actions.get('createShape').label = mxResources.get('shape') + '...';
  559. ui.actions.get('outline').label = mxResources.get('outline') + '...';
  560. ui.actions.get('layers').label = mxResources.get('layers') + '...';
  561. ui.actions.put('importFile', new Action('File...', function()
  562. {
  563. graph.popupMenuHandler.hideMenu();
  564. var input = document.createElement('input');
  565. input.setAttribute('type', 'file');
  566. mxEvent.addListener(input, 'change', function()
  567. {
  568. if (input.files != null)
  569. {
  570. // Using null for position will disable crop of input file
  571. ui.importFiles(input.files, null, null, ui.maxImageSize);
  572. }
  573. });
  574. input.click();
  575. }));
  576. ui.actions.put('importCsv', new Action(mxResources.get('csv') + '...', function()
  577. {
  578. graph.popupMenuHandler.hideMenu();
  579. ui.showImportCsvDialog();
  580. }));
  581. ui.actions.put('importText', new Action(mxResources.get('text') + '...', function()
  582. {
  583. var dlg = new ParseDialog(ui, 'Insert from Text');
  584. ui.showDialog(dlg.container, 620, 420, true, false);
  585. dlg.init();
  586. }));
  587. ui.actions.put('formatSql', new Action(mxResources.get('formatSql') + '...', function()
  588. {
  589. var dlg = new ParseDialog(ui, 'Insert from Text', 'formatSql');
  590. ui.showDialog(dlg.container, 620, 420, true, false);
  591. dlg.init();
  592. }));
  593. ui.actions.put('toggleShapes', new Action(mxResources.get('shapes') + '...', function()
  594. {
  595. toggleShapes(ui);
  596. }));
  597. ui.actions.put('toggleFormat', new Action(mxResources.get('format') + '...', function()
  598. {
  599. toggleFormat(ui);
  600. }));
  601. if (EditorUi.enablePlantUml && !ui.isOffline())
  602. {
  603. ui.actions.put('plantUml', new Action(mxResources.get('plantUml') + '...', function()
  604. {
  605. var dlg = new ParseDialog(ui, 'Insert from Text', 'plantUml');
  606. ui.showDialog(dlg.container, 620, 420, true, false);
  607. dlg.init();
  608. }));
  609. }
  610. this.put('diagram', new Menu(mxUtils.bind(this, function(menu, parent)
  611. {
  612. var file = ui.getCurrentFile();
  613. ui.menus.addSubmenu('extras', menu, parent, mxResources.get('preferences'));
  614. menu.addSeparator(parent);
  615. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  616. {
  617. ui.menus.addMenuItems(menu, ['new', 'open', '-'], parent);
  618. if (EditorUi.isElectronApp)
  619. {
  620. ui.menus.addMenuItems(menu, ['synchronize', '-'], parent);
  621. }
  622. ui.menus.addMenuItems(menu, ['save', 'saveAs', '-'], parent);
  623. }
  624. else if (urlParams['embed'] == '1')
  625. {
  626. ui.menus.addMenuItems(menu, ['-', 'save'], parent);
  627. if (urlParams['saveAndExit'] == '1')
  628. {
  629. ui.menus.addMenuItems(menu, ['saveAndExit'], parent);
  630. }
  631. menu.addSeparator(parent);
  632. }
  633. else
  634. {
  635. ui.menus.addMenuItems(menu, ['new'], parent);
  636. ui.menus.addSubmenu('openFrom', menu, parent);
  637. if (isLocalStorage)
  638. {
  639. this.addSubmenu('openRecent', menu, parent);
  640. }
  641. menu.addSeparator(parent);
  642. if (file != null && file.constructor == DriveFile)
  643. {
  644. ui.menus.addMenuItems(menu, ['share'], parent);
  645. }
  646. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  647. file != null && file.constructor != LocalFile)
  648. {
  649. ui.menus.addMenuItems(menu, ['synchronize'], parent);
  650. }
  651. menu.addSeparator(parent);
  652. ui.menus.addSubmenu('save', menu, parent);
  653. }
  654. ui.menus.addSubmenu('exportAs', menu, parent);
  655. ui.menus.addMenuItems(menu, ['-', 'outline', 'layers', '-', 'find', 'tags'], parent);
  656. // Cannot use print in standalone mode on iOS as we cannot open new windows
  657. if (!mxClient.IS_IOS || !navigator.standalone)
  658. {
  659. ui.menus.addMenuItems(menu, ['-', 'print', '-'], parent);
  660. }
  661. ui.menus.addSubmenu('help', menu, parent);
  662. if (urlParams['embed'] == '1')
  663. {
  664. ui.menus.addMenuItems(menu, ['-', 'exit'], parent);
  665. }
  666. else
  667. {
  668. ui.menus.addMenuItems(menu, ['-', 'close']);
  669. }
  670. })));
  671. this.put('save', new Menu(mxUtils.bind(this, function(menu, parent)
  672. {
  673. var file = ui.getCurrentFile();
  674. if (file != null && file.constructor == DriveFile)
  675. {
  676. ui.menus.addMenuItems(menu, ['save', 'makeCopy', '-', 'rename', 'moveToFolder'], parent);
  677. }
  678. else
  679. {
  680. ui.menus.addMenuItems(menu, ['save', 'saveAs', '-', 'rename'], parent);
  681. if (ui.isOfflineApp())
  682. {
  683. if (navigator.onLine && urlParams['stealth'] != '1')
  684. {
  685. this.addMenuItems(menu, ['upload'], parent);
  686. }
  687. }
  688. else
  689. {
  690. ui.menus.addMenuItems(menu, ['makeCopy'], parent);
  691. }
  692. }
  693. ui.menus.addMenuItems(menu, ['-', 'autosave'], parent);
  694. if (file != null && file.isRevisionHistorySupported())
  695. {
  696. ui.menus.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  697. }
  698. })));
  699. // Augments the existing export menu
  700. var exportAsMenu = this.get('exportAs');
  701. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  702. {
  703. exportAsMenu.funct(menu, parent);
  704. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  705. {
  706. // Publish menu contains only one element by default...
  707. //ui.menus.addSubmenu('publish', menu, parent);
  708. ui.menus.addMenuItems(menu, ['publishLink'], parent);
  709. }
  710. menu.addSeparator(parent);
  711. ui.menus.addSubmenu('embed', menu, parent);
  712. })));
  713. var langMenu = this.get('language');
  714. // Extras menu is labelled preferences but keeps ID for extensions
  715. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  716. {
  717. if (urlParams['embed'] != '1')
  718. {
  719. ui.menus.addSubmenu('theme', menu, parent);
  720. }
  721. if (langMenu != null)
  722. {
  723. ui.menus.addSubmenu('language', menu, parent);
  724. }
  725. menu.addSeparator(parent);
  726. ui.menus.addMenuItems(menu, ['scrollbars', 'tooltips'], parent);
  727. if (urlParams['embed'] != '1' && (isLocalStorage || mxClient.IS_CHROMEAPP))
  728. {
  729. ui.menus.addMenuItems(menu, ['-', 'search', 'scratchpad', '-', 'showStartScreen'], parent);
  730. }
  731. if (!ui.isOfflineApp() && isLocalStorage)
  732. {
  733. menu.addSeparator(parent);
  734. ui.menus.addMenuItem(menu, 'plugins', parent);
  735. }
  736. // Adds trailing separator in case new plugin entries are added
  737. menu.addSeparator(parent);
  738. })));
  739. this.put('insertAdvanced', new Menu(mxUtils.bind(this, function(menu, parent)
  740. {
  741. ui.menus.addMenuItems(menu, ['importText', 'plantUml', '-', 'formatSql', 'importCsv', '-', 'createShape', 'editDiagram'], parent);
  742. })));
  743. mxResources.parse('insertLayout=' + mxResources.get('layout'));
  744. mxResources.parse('insertAdvanced=' + mxResources.get('advanced'));
  745. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  746. {
  747. ui.menus.addMenuItems(menu, ['insertRectangle', 'insertEllipse', 'insertRhombus', '-',
  748. 'insertText', 'insertLink', '-', 'insertImage'], parent);
  749. if (ui.insertTemplateEnabled && !ui.isOffline())
  750. {
  751. ui.menus.addMenuItems(menu, ['insertTemplate'], parent);
  752. }
  753. menu.addSeparator(parent);
  754. ui.menus.addSubmenu('insertLayout', menu, parent);
  755. ui.menus.addSubmenu('insertAdvanced', menu, parent);
  756. menu.addSeparator(parent);
  757. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  758. {
  759. ui.menus.addMenuItems(menu, ['import'], parent);
  760. }
  761. else
  762. {
  763. ui.menus.addSubmenu('importFrom', menu, parent);
  764. }
  765. })));
  766. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree',
  767. 'radialTree', '-', 'organic', 'circle'];
  768. var addInsertItem = function(menu, parent, title, method)
  769. {
  770. menu.addItem(title, null, mxUtils.bind(this, function()
  771. {
  772. var dlg = new CreateGraphDialog(ui, title, method);
  773. ui.showDialog(dlg.container, 620, 420, true, false);
  774. // Executed after dialog is added to dom
  775. dlg.init();
  776. }), parent);
  777. };
  778. this.put('insertLayout', new Menu(mxUtils.bind(this, function(menu, parent)
  779. {
  780. for (var i = 0; i < methods.length; i++)
  781. {
  782. if (methods[i] == '-')
  783. {
  784. menu.addSeparator(parent);
  785. }
  786. else
  787. {
  788. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  789. }
  790. }
  791. })));
  792. // Overrides view for plugins but label it options
  793. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  794. {
  795. ui.menus.addMenuItems(menu, ['grid', 'guides', '-', 'connectionArrows', 'connectionPoints', '-'], parent);
  796. if (typeof(MathJax) !== 'undefined')
  797. {
  798. var item = ui.menus.addMenuItem(menu, 'mathematicalTypesetting', parent);
  799. ui.menus.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  800. }
  801. ui.menus.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-', 'pageScale'], parent);
  802. })));
  803. };
  804. // Initializes the user interface
  805. var editorUiInit = EditorUi.prototype.init;
  806. EditorUi.prototype.init = function()
  807. {
  808. editorUiInit.apply(this, arguments);
  809. var div = document.createElement('div');
  810. div.style.cssText = 'position:absolute;left:0px;right:0px;top:0px;overflow-y:auto;overflow-x:hidden;';
  811. div.style.bottom = (urlParams['embed'] != '1' || urlParams['libraries'] == '1') ? '63px' : '32px';
  812. this.sidebar = this.createSidebar(div);
  813. if (urlParams['clibs'] != null || urlParams['libs'] != null)
  814. {
  815. toggleShapes(this);
  816. }
  817. // Needed for creating elements in Format panel
  818. var ui = this;
  819. var graph = ui.editor.graph;
  820. ui.toolbar = this.createToolbar(ui.createDiv('geToolbar'));
  821. ui.defaultLibraryName = mxResources.get('untitledLibrary');
  822. var menubar = document.createElement('div');
  823. menubar.style.cssText = 'position:absolute;left:0px;right:0px;top:0px;height:30px;padding:8px;border-bottom:1px solid lightgray;background-color:#ffffff;text-align:left;white-space:nowrap;';
  824. var before = null;
  825. var menuObj = new Menubar(ui, menubar);
  826. function addMenu(id, small, img)
  827. {
  828. var menu = ui.menus.get(id);
  829. var elt = menuObj.addMenu(mxResources.get(id), mxUtils.bind(this, function()
  830. {
  831. // Allows extensions of menu.functid
  832. menu.funct.apply(this, arguments);
  833. }), before);
  834. elt.className = 'geMenuItem';
  835. elt.style.display = 'inline-block';
  836. elt.style.boxSizing = 'border-box';
  837. elt.style.top = '6px';
  838. elt.style.marginRight = '6px';
  839. elt.style.height = '30px';
  840. elt.style.paddingTop = '6px';
  841. elt.style.paddingBottom = '6px';
  842. elt.style.cursor = 'pointer';
  843. elt.setAttribute('title', mxResources.get(id));
  844. ui.menus.menuCreated(menu, elt, 'geMenuItem');
  845. if (img != null)
  846. {
  847. elt.style.backgroundImage = 'url(' + img + ')';
  848. elt.style.backgroundPosition = 'center center';
  849. elt.style.backgroundRepeat = 'no-repeat';
  850. elt.style.backgroundSize = '24px 24px';
  851. elt.style.width = '34px';
  852. elt.innerHTML = '';
  853. }
  854. else if (!small)
  855. {
  856. elt.style.backgroundImage = 'url(' + mxWindow.prototype.normalizeImage + ')';
  857. elt.style.backgroundPosition = 'right 6px center';
  858. elt.style.backgroundRepeat = 'no-repeat';
  859. elt.style.paddingRight = '22px';
  860. }
  861. return elt;
  862. };
  863. function addMenuItem(label, fn, small, tooltip, action, img)
  864. {
  865. var btn = document.createElement('a');
  866. btn.className = 'geMenuItem';
  867. btn.style.display = 'inline-block';
  868. btn.style.boxSizing = 'border-box';
  869. btn.style.height = '30px';
  870. btn.style.padding = '6px';
  871. btn.style.position = 'relative';
  872. btn.style.verticalAlign = 'top';
  873. btn.style.top = '0px';
  874. if (ui.statusContainer != null)
  875. {
  876. menubar.insertBefore(btn, ui.statusContainer);
  877. }
  878. else
  879. {
  880. menubar.appendChild(btn);
  881. }
  882. if (img != null)
  883. {
  884. btn.style.backgroundImage = 'url(' + img + ')';
  885. btn.style.backgroundPosition = 'center center';
  886. btn.style.backgroundRepeat = 'no-repeat';
  887. btn.style.backgroundSize = '24px 24px';
  888. btn.style.width = '34px';
  889. }
  890. else
  891. {
  892. mxUtils.write(btn, label);
  893. }
  894. // Prevents focus
  895. mxEvent.addListener(btn, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  896. mxUtils.bind(this, function(evt)
  897. {
  898. evt.preventDefault();
  899. }));
  900. mxEvent.addListener(btn, 'click', function(evt)
  901. {
  902. if (btn.getAttribute('disabled') != 'disabled')
  903. {
  904. fn(evt);
  905. }
  906. mxEvent.consume(evt);
  907. });
  908. if (small == null)
  909. {
  910. btn.style.marginRight = '4px';
  911. }
  912. if (tooltip != null)
  913. {
  914. btn.setAttribute('title', tooltip);
  915. }
  916. if (action != null)
  917. {
  918. function updateState()
  919. {
  920. if (action.isEnabled())
  921. {
  922. btn.removeAttribute('disabled');
  923. btn.style.cursor = 'pointer';
  924. }
  925. else
  926. {
  927. btn.setAttribute('disabled', 'disabled');
  928. btn.style.cursor = 'default';
  929. }
  930. };
  931. action.addListener('stateChanged', updateState);
  932. updateState();
  933. }
  934. return btn;
  935. };
  936. function createGroup(btns, op)
  937. {
  938. var btnGroup = document.createElement('div');
  939. btnGroup.className = 'geMenuItem';
  940. btnGroup.style.display = 'inline-block';
  941. btnGroup.style.verticalAlign = 'top';
  942. btnGroup.style.marginRight = '6px';
  943. btnGroup.style.padding = '0 4px 0 4px';
  944. btnGroup.style.height = '30px';
  945. btnGroup.style.position = 'relative';
  946. btnGroup.style.top = '0px';
  947. for (var i = 0; i < btns.length; i++)
  948. {
  949. if (btns[i] != null)
  950. {
  951. btns[i].style.margin = '0px';
  952. btns[i].style.boxShadow = 'none';
  953. btnGroup.appendChild(btns[i]);
  954. }
  955. }
  956. if (op != null)
  957. {
  958. mxUtils.setOpacity(btnGroup, op);
  959. }
  960. if (ui.statusContainer != null)
  961. {
  962. menubar.insertBefore(btnGroup, ui.statusContainer);
  963. }
  964. else
  965. {
  966. menubar.appendChild(btnGroup);
  967. }
  968. return btnGroup;
  969. };
  970. ui.statusContainer = ui.createStatusContainer();
  971. ui.statusContainer.style.position = 'relative';
  972. ui.statusContainer.style.maxWidth = '';
  973. ui.statusContainer.style.marginTop = '7px';
  974. ui.statusContainer.style.marginLeft = '6px';
  975. ui.statusContainer.style.color = 'gray';
  976. ui.statusContainer.style.cursor = 'default';
  977. function updateTitle()
  978. {
  979. var file = ui.getCurrentFile();
  980. if (file != null && file.getTitle() != null)
  981. {
  982. var mode = file.getMode();
  983. if (mode == 'google')
  984. {
  985. mode = 'googleDrive';
  986. }
  987. else if (mode == 'github')
  988. {
  989. mode = 'gitHub';
  990. }
  991. else if (mode == 'onedrive')
  992. {
  993. mode = 'oneDrive';
  994. }
  995. mode = mxResources.get(mode);
  996. menubar.setAttribute('title', file.getTitle() + ((mode != null) ? ' (' + mode + ')' : ''));
  997. }
  998. else
  999. {
  1000. menubar.removeAttribute('title');
  1001. }
  1002. };
  1003. // Connects the status bar to the editor status
  1004. ui.editor.addListener('statusChanged', mxUtils.bind(this, function()
  1005. {
  1006. ui.setStatusText(ui.editor.getStatus());
  1007. }));
  1008. // Connects the status bar to the editor status
  1009. var uiDescriptorChanged = ui.descriptorChanged;
  1010. ui.descriptorChanged = function()
  1011. {
  1012. uiDescriptorChanged.apply(this, arguments);
  1013. updateTitle();
  1014. };
  1015. ui.setStatusText(ui.editor.getStatus());
  1016. menubar.appendChild(ui.statusContainer);
  1017. ui.buttonContainer = document.createElement('div');
  1018. ui.buttonContainer.style.cssText = 'position:absolute;right:0px;padding-right:34px;top:10px;' +
  1019. 'white-space:nowrap;padding-top:2px;background-color:inherit;';
  1020. menubar.appendChild(ui.buttonContainer);
  1021. // Container for the user element
  1022. ui.menubarContainer = ui.buttonContainer;
  1023. ui.tabContainer = document.createElement('div');
  1024. ui.tabContainer.style.cssText = 'position:absolute;left:0px;right:0px;bottom:0px;height:30px;white-space:nowrap;' +
  1025. 'border-bottom:1px solid lightgray;background-color:#ffffff;border-top:1px solid lightgray;margin-bottom:-2px;' +
  1026. 'visibility:hidden;';
  1027. var previousParent = ui.diagramContainer.parentNode;
  1028. var wrapper = document.createElement('div');
  1029. wrapper.style.cssText = 'position:absolute;top:0px;left:0px;right:0px;bottom:0px;overflow:hidden;';
  1030. ui.diagramContainer.style.top = '47px';
  1031. var viewZoomMenu = ui.menus.get('viewZoom');
  1032. var viewZoomMenuElt = null;
  1033. if (viewZoomMenu != null)
  1034. {
  1035. this.tabContainer.style.right = '70px';
  1036. var elt = menuObj.addMenu('100%', viewZoomMenu.funct);
  1037. elt.setAttribute('title', mxResources.get('zoom') + ' (Alt+Mousewheel)');
  1038. elt.style.whiteSpace = 'nowrap';
  1039. elt.style.backgroundImage = 'url(' + mxWindow.prototype.minimizeImage + ')';
  1040. elt.style.backgroundPosition = 'right 6px center';
  1041. elt.style.backgroundRepeat = 'no-repeat';
  1042. elt.style.backgroundColor = '#ffffff';
  1043. elt.style.paddingRight = '10px';
  1044. elt.style.display = 'block';
  1045. elt.style.position = 'absolute';
  1046. elt.style.textDecoration = 'none';
  1047. elt.style.textDecoration = 'none';
  1048. elt.style.right = '0px';
  1049. elt.style.bottom = '0px';
  1050. elt.style.overflow = 'hidden';
  1051. elt.style.visibility = 'hidden';
  1052. elt.style.textAlign = 'center';
  1053. elt.style.color = '#000';
  1054. elt.style.fontSize = '12px';
  1055. elt.style.color = '#707070';
  1056. elt.style.width = '59px';
  1057. elt.style.borderTop = '1px solid lightgray';
  1058. elt.style.borderLeft = '1px solid lightgray';
  1059. elt.style.height = (parseInt(ui.tabContainer.style.height) - 1) + 'px';
  1060. elt.style.lineHeight = (parseInt(ui.tabContainer.style.height) + 1) + 'px';
  1061. wrapper.appendChild(elt);
  1062. // Updates the label if the scale changes
  1063. var updateZoom = mxUtils.bind(this, function()
  1064. {
  1065. elt.innerHTML = Math.round(ui.editor.graph.view.scale * 100) + '%';
  1066. });
  1067. ui.editor.graph.view.addListener(mxEvent.EVENT_SCALE, updateZoom);
  1068. ui.editor.addListener('resetGraphView', updateZoom);
  1069. ui.editor.addListener('pageSelected', updateZoom);
  1070. // Augments setGraphEnabled to update visible state
  1071. var uiSetGraphEnabled = ui.setGraphEnabled;
  1072. ui.setGraphEnabled = function()
  1073. {
  1074. uiSetGraphEnabled.apply(this, arguments);
  1075. if (this.tabContainer != null)
  1076. {
  1077. elt.style.visibility = this.tabContainer.style.visibility;
  1078. this.diagramContainer.style.bottom = (this.tabContainer.style.visibility != 'hidden') ? '30px' : '0px';
  1079. }
  1080. };
  1081. }
  1082. wrapper.appendChild(ui.tabContainer);
  1083. wrapper.appendChild(menubar);
  1084. wrapper.appendChild(ui.diagramContainer);
  1085. previousParent.appendChild(wrapper);
  1086. ui.updateTabContainer();
  1087. var langMenuElt = null;
  1088. function refreshMenu()
  1089. {
  1090. // Removes all existing menu items
  1091. var node = menubar.firstChild;
  1092. while (node != null)
  1093. {
  1094. var temp = node.nextSibling;
  1095. if (node.className == 'geMenuItem' || node.className == 'geItem')
  1096. {
  1097. node.parentNode.removeChild(node);
  1098. }
  1099. node = temp;
  1100. }
  1101. before = menubar.firstChild;
  1102. iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1103. var small = iw < 1000;
  1104. if (!small)
  1105. {
  1106. addMenu('diagram');
  1107. }
  1108. createGroup([((small) ? addMenu('diagram', null, IMAGE_PATH + '/drawlogo.svg') : null),
  1109. addMenuItem(mxResources.get('shapes'), ui.actions.get('toggleShapes').funct, null, mxResources.get('shapes'), ui.actions.get('image'),
  1110. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTMgMTN2OGg4di04aC04ek0zIDIxaDh2LThIM3Y4ek0zIDN2OGg4VjNIM3ptMTMuNjYtMS4zMUwxMSA3LjM0IDE2LjY2IDEzbDUuNjYtNS42Ni01LjY2LTUuNjV6Ii8+PC9zdmc+' : null),
  1111. addMenuItem(mxResources.get('format'), ui.actions.get('toggleFormat').funct, null,
  1112. mxResources.get('format') + ' (' + ui.actions.get('formatPanel').shortcut + ')', ui.actions.get('image'),
  1113. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgM2MtNC45NyAwLTkgNC4wMy05IDlzNC4wMyA5IDkgOWMuODMgMCAxLjUtLjY3IDEuNS0xLjUgMC0uMzktLjE1LS43NC0uMzktMS4wMS0uMjMtLjI2LS4zOC0uNjEtLjM4LS45OSAwLS44My42Ny0xLjUgMS41LTEuNUgxNmMyLjc2IDAgNS0yLjI0IDUtNSAwLTQuNDItNC4wMy04LTktOHptLTUuNSA5Yy0uODMgMC0xLjUtLjY3LTEuNS0xLjVTNS42NyA5IDYuNSA5IDggOS42NyA4IDEwLjUgNy4zMyAxMiA2LjUgMTJ6bTMtNEM4LjY3IDggOCA3LjMzIDggNi41UzguNjcgNSA5LjUgNXMxLjUuNjcgMS41IDEuNVMxMC4zMyA4IDkuNSA4em01IDBjLS44MyAwLTEuNS0uNjctMS41LTEuNVMxMy42NyA1IDE0LjUgNXMxLjUuNjcgMS41IDEuNVMxNS4zMyA4IDE0LjUgOHptMyA0Yy0uODMgMC0xLjUtLjY3LTEuNS0xLjVTMTYuNjcgOSAxNy41IDlzMS41LjY3IDEuNSAxLjUtLjY3IDEuNS0xLjUgMS41eiIvPjwvc3ZnPg==' : null)],
  1114. (small) ? 60 : null);
  1115. var elt = addMenu('insert', true, (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTkgMTNoLTZ2NmgtMnYtNkg1di0yaDZWNWgydjZoNnYyeiIvPjwvc3ZnPg==' : null);
  1116. createGroup([elt, addMenuItem(mxResources.get('delete'), ui.actions.get('delete').funct, null, mxResources.get('delete'), ui.actions.get('delete'),
  1117. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNNiAxOWMwIDEuMS45IDIgMiAyaDhjMS4xIDAgMi0uOSAyLTJWN0g2djEyek0xOSA0aC0zLjVsLTEtMWgtNWwtMSAxSDV2MmgxNFY0eiIvPjwvc3ZnPg==' : null)],
  1118. (small) ? 60 : null);
  1119. if (iw >= 411)
  1120. {
  1121. var undoAction = ui.actions.get('undo');
  1122. var redoAction = ui.actions.get('redo');
  1123. var undoElt = addMenuItem('', undoAction.funct, null, mxResources.get('undo') + ' (' + undoAction.shortcut + ')', undoAction,
  1124. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIuNSA4Yy0yLjY1IDAtNS4wNS45OS02LjkgMi42TDIgN3Y5aDlsLTMuNjItMy42MmMxLjM5LTEuMTYgMy4xNi0xLjg4IDUuMTItMS44OCAzLjU0IDAgNi41NSAyLjMxIDcuNiA1LjVsMi4zNy0uNzhDMjEuMDggMTEuMDMgMTcuMTUgOCAxMi41IDh6Ii8+PC9zdmc+');
  1125. var redoElt = addMenuItem('', redoAction.funct, null, mxResources.get('redo') + ' (' + redoAction.shortcut + ')', redoAction,
  1126. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTguNCAxMC42QzE2LjU1IDguOTkgMTQuMTUgOCAxMS41IDhjLTQuNjUgMC04LjU4IDMuMDMtOS45NiA3LjIyTDMuOSAxNmMxLjA1LTMuMTkgNC4wNS01LjUgNy42LTUuNSAxLjk1IDAgMy43My43MiA1LjEyIDEuODhMMTMgMTZoOVY3bC0zLjYgMy42eiIvPjwvc3ZnPg==');
  1127. createGroup([undoElt, redoElt], 60);
  1128. if (iw >= 480)
  1129. {
  1130. var zoomInAction = ui.actions.get('zoomIn');
  1131. var zoomOutAction = ui.actions.get('zoomOut');
  1132. var resetViewAction = ui.actions.get('resetView');
  1133. createGroup([addMenuItem('', function()
  1134. {
  1135. graph.popupMenuHandler.hideMenu();
  1136. var scale = graph.view.scale;
  1137. var tx = graph.view.translate.x;
  1138. var ty = graph.view.translate.y;
  1139. ui.actions.get('resetView').funct();
  1140. // Toggle scale if nothing has changed
  1141. if (Math.abs(scale - graph.view.scale) < 0.00001 && tx == graph.view.translate.x && ty == graph.view.translate.y)
  1142. {
  1143. ui.actions.get((graph.pageVisible) ? 'fitPage' : 'fitWindow').funct();
  1144. }
  1145. }, true, mxResources.get('fit') + ' (' + Editor.ctrlKey + '+H)', resetViewAction,
  1146. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMyA1djRoMlY1aDRWM0g1Yy0xLjEgMC0yIC45LTIgMnptMiAxMEgzdjRjMCAxLjEuOSAyIDIgMmg0di0ySDV2LTR6bTE0IDRoLTR2Mmg0YzEuMSAwIDItLjkgMi0ydi00aC0ydjR6bTAtMTZoLTR2Mmg0djRoMlY1YzAtMS4xLS45LTItMi0yeiIvPjwvc3ZnPg=='),
  1147. (iw >= 640) ? addMenuItem('', zoomInAction.funct, true, mxResources.get('zoomIn') + ' (' + Editor.ctrlKey + ' +)', zoomInAction,
  1148. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTUuNSAxNGgtLjc5bC0uMjgtLjI3QzE1LjQxIDEyLjU5IDE2IDExLjExIDE2IDkuNSAxNiA1LjkxIDEzLjA5IDMgOS41IDNTMyA1LjkxIDMgOS41IDUuOTEgMTYgOS41IDE2YzEuNjEgMCAzLjA5LS41OSA0LjIzLTEuNTdsLjI3LjI4di43OWw1IDQuOTlMMjAuNDkgMTlsLTQuOTktNXptLTYgMEM3LjAxIDE0IDUgMTEuOTkgNSA5LjVTNy4wMSA1IDkuNSA1IDE0IDcuMDEgMTQgOS41IDExLjk5IDE0IDkuNSAxNHptMi41LTRoLTJ2Mkg5di0ySDdWOWgyVjdoMXYyaDJ2MXoiLz48L3N2Zz4=') : null,
  1149. (iw >= 640) ? addMenuItem('', zoomOutAction.funct, true, mxResources.get('zoomOut') + ' (' + Editor.ctrlKey + ' -)', zoomOutAction,
  1150. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTUuNSAxNGgtLjc5bC0uMjgtLjI3QzE1LjQxIDEyLjU5IDE2IDExLjExIDE2IDkuNSAxNiA1LjkxIDEzLjA5IDMgOS41IDNTMyA1LjkxIDMgOS41IDUuOTEgMTYgOS41IDE2YzEuNjEgMCAzLjA5LS41OSA0LjIzLTEuNTdsLjI3LjI4di43OWw1IDQuOTlMMjAuNDkgMTlsLTQuOTktNXptLTYgMEM3LjAxIDE0IDUgMTEuOTkgNSA5LjVTNy4wMSA1IDkuNSA1IDE0IDcuMDEgMTQgOS41IDExLjk5IDE0IDkuNSAxNHpNNyA5aDV2MUg3eiIvPjwvc3ZnPg==') : null], 60);
  1151. }
  1152. }
  1153. var langMenu = ui.menus.get('language');
  1154. if (langMenu != null && !mxClient.IS_CHROMEAPP &&
  1155. !EditorUi.isElectronApp && iw >= 600)
  1156. {
  1157. if (langMenuElt == null)
  1158. {
  1159. var elt = menuObj.addMenu('', langMenu.funct);
  1160. elt.setAttribute('title', mxResources.get('language'));
  1161. elt.className = 'geToolbarButton';
  1162. elt.style.backgroundImage = 'url(' + Editor.globeImage + ')';
  1163. elt.style.backgroundPosition = 'center center';
  1164. elt.style.backgroundRepeat = 'no-repeat';
  1165. elt.style.backgroundSize = '24px 24px';
  1166. elt.style.position = 'absolute';
  1167. elt.style.height = '24px';
  1168. elt.style.width = '24px';
  1169. elt.style.zIndex = '1';
  1170. elt.style.top = '11px';
  1171. elt.style.right = '8px';
  1172. elt.style.cursor = 'pointer';
  1173. menubar.appendChild(elt);
  1174. langMenuElt = elt;
  1175. }
  1176. ui.buttonContainer.style.paddingRight = '34px';
  1177. }
  1178. else
  1179. {
  1180. ui.buttonContainer.style.paddingRight = '4px';
  1181. if (langMenuElt != null)
  1182. {
  1183. langMenuElt.parentNode.removeChild(langMenuElt);
  1184. langMenuElt = null;
  1185. }
  1186. }
  1187. };
  1188. refreshMenu();
  1189. mxEvent.addListener(window, 'resize', function()
  1190. {
  1191. refreshMenu();
  1192. if (ui.sidebarWindow != null)
  1193. {
  1194. ui.sidebarWindow.window.fit();
  1195. }
  1196. if (ui.formatWindow != null)
  1197. {
  1198. ui.formatWindow.window.fit();
  1199. }
  1200. if (ui.actions.outlineWindow != null)
  1201. {
  1202. ui.actions.outlineWindow.window.fit();
  1203. }
  1204. if (ui.actions.layersWindow != null)
  1205. {
  1206. ui.actions.layersWindow.window.fit();
  1207. }
  1208. if (ui.menus.tagsWindow != null)
  1209. {
  1210. ui.menus.tagsWindow.window.fit();
  1211. }
  1212. if (ui.menus.findWindow != null)
  1213. {
  1214. ui.menus.findWindow.window.fit();
  1215. }
  1216. });
  1217. };
  1218. };
  1219. (function()
  1220. {
  1221. var initialized = false;
  1222. // ChromeApp has async local storage
  1223. if (uiTheme == 'min' && !initialized && !mxClient.IS_CHROMEAPP)
  1224. {
  1225. EditorUi.initMinimalTheme();
  1226. initialized = true;
  1227. }
  1228. var uiInitTheme = EditorUi.initTheme;
  1229. // For async startup like chromeos
  1230. EditorUi.initTheme = function()
  1231. {
  1232. uiInitTheme.apply(this, arguments);
  1233. if (uiTheme == 'min' && !initialized)
  1234. {
  1235. this.initMinimalTheme();
  1236. initialized = true;
  1237. }
  1238. };
  1239. })();