Minimal.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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 = this.tabContainerHeight + 'px';
  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. if (ui.minImpFileInputElt == null)
  565. {
  566. var input = document.createElement('input');
  567. input.setAttribute('type', 'file');
  568. mxEvent.addListener(input, 'change', function()
  569. {
  570. if (input.files != null)
  571. {
  572. // Using null for position will disable crop of input file
  573. ui.importFiles(input.files, null, null, ui.maxImageSize);
  574. }
  575. input.value = '';
  576. });
  577. input.style.display = 'none';
  578. document.body.appendChild(input);
  579. ui.minImpFileInputElt = input;
  580. }
  581. ui.minImpFileInputElt.click();
  582. }));
  583. ui.actions.put('importCsv', new Action(mxResources.get('csv') + '...', function()
  584. {
  585. graph.popupMenuHandler.hideMenu();
  586. ui.showImportCsvDialog();
  587. }));
  588. ui.actions.put('importText', new Action(mxResources.get('text') + '...', function()
  589. {
  590. var dlg = new ParseDialog(ui, 'Insert from Text');
  591. ui.showDialog(dlg.container, 620, 420, true, false);
  592. dlg.init();
  593. }));
  594. ui.actions.put('formatSql', new Action(mxResources.get('formatSql') + '...', function()
  595. {
  596. var dlg = new ParseDialog(ui, 'Insert from Text', 'formatSql');
  597. ui.showDialog(dlg.container, 620, 420, true, false);
  598. dlg.init();
  599. }));
  600. ui.actions.put('toggleShapes', new Action(mxResources.get('shapes') + '...', function()
  601. {
  602. toggleShapes(ui);
  603. }));
  604. ui.actions.put('toggleFormat', new Action(mxResources.get('format') + '...', function()
  605. {
  606. toggleFormat(ui);
  607. }));
  608. if (EditorUi.enablePlantUml && !ui.isOffline())
  609. {
  610. ui.actions.put('plantUml', new Action(mxResources.get('plantUml') + '...', function()
  611. {
  612. var dlg = new ParseDialog(ui, 'Insert from Text', 'plantUml');
  613. ui.showDialog(dlg.container, 620, 420, true, false);
  614. dlg.init();
  615. }));
  616. }
  617. this.put('diagram', new Menu(mxUtils.bind(this, function(menu, parent)
  618. {
  619. var file = ui.getCurrentFile();
  620. ui.menus.addSubmenu('extras', menu, parent, mxResources.get('preferences'));
  621. menu.addSeparator(parent);
  622. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  623. {
  624. ui.menus.addMenuItems(menu, ['new', 'open', '-'], parent);
  625. if (EditorUi.isElectronApp)
  626. {
  627. ui.menus.addMenuItems(menu, ['synchronize', '-'], parent);
  628. }
  629. ui.menus.addMenuItems(menu, ['save', 'saveAs', '-'], parent);
  630. }
  631. else if (urlParams['embed'] == '1')
  632. {
  633. ui.menus.addMenuItems(menu, ['-', 'save'], parent);
  634. if (urlParams['saveAndExit'] == '1')
  635. {
  636. ui.menus.addMenuItems(menu, ['saveAndExit'], parent);
  637. }
  638. menu.addSeparator(parent);
  639. }
  640. else
  641. {
  642. ui.menus.addMenuItems(menu, ['new'], parent);
  643. ui.menus.addSubmenu('openFrom', menu, parent);
  644. if (isLocalStorage)
  645. {
  646. this.addSubmenu('openRecent', menu, parent);
  647. }
  648. menu.addSeparator(parent);
  649. if (file != null && file.constructor == DriveFile)
  650. {
  651. ui.menus.addMenuItems(menu, ['share'], parent);
  652. }
  653. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp &&
  654. file != null && file.constructor != LocalFile)
  655. {
  656. ui.menus.addMenuItems(menu, ['synchronize'], parent);
  657. }
  658. menu.addSeparator(parent);
  659. ui.menus.addSubmenu('save', menu, parent);
  660. }
  661. ui.menus.addSubmenu('exportAs', menu, parent);
  662. ui.menus.addMenuItems(menu, ['-', 'outline', 'layers'], parent);
  663. if (ui.commentsSupported())
  664. {
  665. ui.menus.addMenuItems(menu, ['comments'], parent);
  666. }
  667. ui.menus.addMenuItems(menu, ['-', 'find', 'tags'], parent);
  668. // Cannot use print in standalone mode on iOS as we cannot open new windows
  669. if (!mxClient.IS_IOS || !navigator.standalone)
  670. {
  671. ui.menus.addMenuItems(menu, ['-', 'print', '-'], parent);
  672. }
  673. ui.menus.addSubmenu('help', menu, parent);
  674. if (urlParams['embed'] == '1')
  675. {
  676. ui.menus.addMenuItems(menu, ['-', 'exit'], parent);
  677. }
  678. else
  679. {
  680. ui.menus.addMenuItems(menu, ['-', 'close']);
  681. }
  682. })));
  683. this.put('save', new Menu(mxUtils.bind(this, function(menu, parent)
  684. {
  685. var file = ui.getCurrentFile();
  686. if (file != null && file.constructor == DriveFile)
  687. {
  688. ui.menus.addMenuItems(menu, ['save', 'makeCopy', '-', 'rename', 'moveToFolder'], parent);
  689. }
  690. else
  691. {
  692. ui.menus.addMenuItems(menu, ['save', 'saveAs', '-', 'rename'], parent);
  693. if (ui.isOfflineApp())
  694. {
  695. if (navigator.onLine && urlParams['stealth'] != '1')
  696. {
  697. this.addMenuItems(menu, ['upload'], parent);
  698. }
  699. }
  700. else
  701. {
  702. ui.menus.addMenuItems(menu, ['makeCopy'], parent);
  703. }
  704. }
  705. ui.menus.addMenuItems(menu, ['-', 'autosave'], parent);
  706. if (file != null && file.isRevisionHistorySupported())
  707. {
  708. ui.menus.addMenuItems(menu, ['-', 'revisionHistory'], parent);
  709. }
  710. })));
  711. // Augments the existing export menu
  712. var exportAsMenu = this.get('exportAs');
  713. this.put('exportAs', new Menu(mxUtils.bind(this, function(menu, parent)
  714. {
  715. exportAsMenu.funct(menu, parent);
  716. if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
  717. {
  718. // Publish menu contains only one element by default...
  719. //ui.menus.addSubmenu('publish', menu, parent);
  720. ui.menus.addMenuItems(menu, ['publishLink'], parent);
  721. }
  722. menu.addSeparator(parent);
  723. ui.menus.addSubmenu('embed', menu, parent);
  724. })));
  725. var langMenu = this.get('language');
  726. // Extras menu is labelled preferences but keeps ID for extensions
  727. this.put('extras', new Menu(mxUtils.bind(this, function(menu, parent)
  728. {
  729. if (urlParams['embed'] != '1')
  730. {
  731. ui.menus.addSubmenu('theme', menu, parent);
  732. }
  733. if (langMenu != null)
  734. {
  735. ui.menus.addSubmenu('language', menu, parent);
  736. }
  737. menu.addSeparator(parent);
  738. ui.menus.addMenuItems(menu, ['scrollbars', 'tooltips'], parent);
  739. if (urlParams['embed'] != '1' && (isLocalStorage || mxClient.IS_CHROMEAPP))
  740. {
  741. ui.menus.addMenuItems(menu, ['-', 'search', 'scratchpad', '-', 'showStartScreen'], parent);
  742. }
  743. if (!ui.isOfflineApp() && isLocalStorage)
  744. {
  745. menu.addSeparator(parent);
  746. ui.menus.addMenuItem(menu, 'plugins', parent);
  747. }
  748. // Adds trailing separator in case new plugin entries are added
  749. menu.addSeparator(parent);
  750. })));
  751. this.put('insertAdvanced', new Menu(mxUtils.bind(this, function(menu, parent)
  752. {
  753. ui.menus.addMenuItems(menu, ['importText', 'plantUml', '-', 'formatSql', 'importCsv', '-', 'createShape', 'editDiagram'], parent);
  754. })));
  755. mxResources.parse('insertLayout=' + mxResources.get('layout'));
  756. mxResources.parse('insertAdvanced=' + mxResources.get('advanced'));
  757. this.put('insert', new Menu(mxUtils.bind(this, function(menu, parent)
  758. {
  759. ui.menus.addMenuItems(menu, ['insertRectangle', 'insertEllipse', 'insertRhombus', '-',
  760. 'insertText', 'insertLink', '-', 'insertImage'], parent);
  761. if (ui.insertTemplateEnabled && !ui.isOffline())
  762. {
  763. ui.menus.addMenuItems(menu, ['insertTemplate'], parent);
  764. }
  765. menu.addSeparator(parent);
  766. ui.menus.addSubmenu('insertLayout', menu, parent);
  767. ui.menus.addSubmenu('insertAdvanced', menu, parent);
  768. menu.addSeparator(parent);
  769. if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
  770. {
  771. ui.menus.addMenuItems(menu, ['import'], parent);
  772. }
  773. else
  774. {
  775. ui.menus.addSubmenu('importFrom', menu, parent);
  776. }
  777. })));
  778. var methods = ['horizontalFlow', 'verticalFlow', '-', 'horizontalTree', 'verticalTree',
  779. 'radialTree', '-', 'organic', 'circle'];
  780. var addInsertItem = function(menu, parent, title, method)
  781. {
  782. menu.addItem(title, null, mxUtils.bind(this, function()
  783. {
  784. var dlg = new CreateGraphDialog(ui, title, method);
  785. ui.showDialog(dlg.container, 620, 420, true, false);
  786. // Executed after dialog is added to dom
  787. dlg.init();
  788. }), parent);
  789. };
  790. this.put('insertLayout', new Menu(mxUtils.bind(this, function(menu, parent)
  791. {
  792. for (var i = 0; i < methods.length; i++)
  793. {
  794. if (methods[i] == '-')
  795. {
  796. menu.addSeparator(parent);
  797. }
  798. else
  799. {
  800. addInsertItem(menu, parent, mxResources.get(methods[i]) + '...', methods[i]);
  801. }
  802. }
  803. })));
  804. // Overrides view for plugins but label it options
  805. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  806. {
  807. ui.menus.addMenuItems(menu, ['grid', 'guides', '-', 'connectionArrows', 'connectionPoints', '-'], parent);
  808. if (typeof(MathJax) !== 'undefined')
  809. {
  810. var item = ui.menus.addMenuItem(menu, 'mathematicalTypesetting', parent);
  811. ui.menus.addLinkToItem(item, 'https://desk.draw.io/support/solutions/articles/16000032875');
  812. }
  813. ui.menus.addMenuItems(menu, ['copyConnect', 'collapseExpand', '-', 'pageScale'], parent);
  814. })));
  815. };
  816. // Initializes the user interface
  817. var editorUiInit = EditorUi.prototype.init;
  818. EditorUi.prototype.init = function()
  819. {
  820. editorUiInit.apply(this, arguments);
  821. var div = document.createElement('div');
  822. div.style.cssText = 'position:absolute;left:0px;right:0px;top:0px;overflow-y:auto;overflow-x:hidden;';
  823. div.style.bottom = (urlParams['embed'] != '1' || urlParams['libraries'] == '1') ? '63px' : '32px';
  824. this.sidebar = this.createSidebar(div);
  825. if (urlParams['clibs'] != null || urlParams['libs'] != null)
  826. {
  827. toggleShapes(this);
  828. }
  829. // Needed for creating elements in Format panel
  830. var ui = this;
  831. var graph = ui.editor.graph;
  832. ui.toolbar = this.createToolbar(ui.createDiv('geToolbar'));
  833. ui.defaultLibraryName = mxResources.get('untitledLibrary');
  834. var menubar = document.createElement('div');
  835. 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;';
  836. var before = null;
  837. var menuObj = new Menubar(ui, menubar);
  838. function addMenu(id, small, img)
  839. {
  840. var menu = ui.menus.get(id);
  841. var elt = menuObj.addMenu(mxResources.get(id), mxUtils.bind(this, function()
  842. {
  843. // Allows extensions of menu.functid
  844. menu.funct.apply(this, arguments);
  845. }), before);
  846. elt.className = 'geMenuItem';
  847. elt.style.display = 'inline-block';
  848. elt.style.boxSizing = 'border-box';
  849. elt.style.top = '6px';
  850. elt.style.marginRight = '6px';
  851. elt.style.height = '30px';
  852. elt.style.paddingTop = '6px';
  853. elt.style.paddingBottom = '6px';
  854. elt.style.cursor = 'pointer';
  855. elt.setAttribute('title', mxResources.get(id));
  856. ui.menus.menuCreated(menu, elt, 'geMenuItem');
  857. if (img != null)
  858. {
  859. elt.style.backgroundImage = 'url(' + img + ')';
  860. elt.style.backgroundPosition = 'center center';
  861. elt.style.backgroundRepeat = 'no-repeat';
  862. elt.style.backgroundSize = '24px 24px';
  863. elt.style.width = '34px';
  864. elt.innerHTML = '';
  865. }
  866. else if (!small)
  867. {
  868. elt.style.backgroundImage = 'url(' + mxWindow.prototype.normalizeImage + ')';
  869. elt.style.backgroundPosition = 'right 6px center';
  870. elt.style.backgroundRepeat = 'no-repeat';
  871. elt.style.paddingRight = '22px';
  872. }
  873. return elt;
  874. };
  875. function addMenuItem(label, fn, small, tooltip, action, img)
  876. {
  877. var btn = document.createElement('a');
  878. btn.className = 'geMenuItem';
  879. btn.style.display = 'inline-block';
  880. btn.style.boxSizing = 'border-box';
  881. btn.style.height = '30px';
  882. btn.style.padding = '6px';
  883. btn.style.position = 'relative';
  884. btn.style.verticalAlign = 'top';
  885. btn.style.top = '0px';
  886. if (ui.statusContainer != null)
  887. {
  888. menubar.insertBefore(btn, ui.statusContainer);
  889. }
  890. else
  891. {
  892. menubar.appendChild(btn);
  893. }
  894. if (img != null)
  895. {
  896. btn.style.backgroundImage = 'url(' + img + ')';
  897. btn.style.backgroundPosition = 'center center';
  898. btn.style.backgroundRepeat = 'no-repeat';
  899. btn.style.backgroundSize = '24px 24px';
  900. btn.style.width = '34px';
  901. }
  902. else
  903. {
  904. mxUtils.write(btn, label);
  905. }
  906. // Prevents focus
  907. mxEvent.addListener(btn, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  908. mxUtils.bind(this, function(evt)
  909. {
  910. evt.preventDefault();
  911. }));
  912. mxEvent.addListener(btn, 'click', function(evt)
  913. {
  914. if (btn.getAttribute('disabled') != 'disabled')
  915. {
  916. fn(evt);
  917. }
  918. mxEvent.consume(evt);
  919. });
  920. if (small == null)
  921. {
  922. btn.style.marginRight = '4px';
  923. }
  924. if (tooltip != null)
  925. {
  926. btn.setAttribute('title', tooltip);
  927. }
  928. if (action != null)
  929. {
  930. function updateState()
  931. {
  932. if (action.isEnabled())
  933. {
  934. btn.removeAttribute('disabled');
  935. btn.style.cursor = 'pointer';
  936. }
  937. else
  938. {
  939. btn.setAttribute('disabled', 'disabled');
  940. btn.style.cursor = 'default';
  941. }
  942. };
  943. action.addListener('stateChanged', updateState);
  944. updateState();
  945. }
  946. return btn;
  947. };
  948. function createGroup(btns, op)
  949. {
  950. var btnGroup = document.createElement('div');
  951. btnGroup.className = 'geMenuItem';
  952. btnGroup.style.display = 'inline-block';
  953. btnGroup.style.verticalAlign = 'top';
  954. btnGroup.style.marginRight = '6px';
  955. btnGroup.style.padding = '0 4px 0 4px';
  956. btnGroup.style.height = '30px';
  957. btnGroup.style.position = 'relative';
  958. btnGroup.style.top = '0px';
  959. for (var i = 0; i < btns.length; i++)
  960. {
  961. if (btns[i] != null)
  962. {
  963. btns[i].style.margin = '0px';
  964. btns[i].style.boxShadow = 'none';
  965. btnGroup.appendChild(btns[i]);
  966. }
  967. }
  968. if (op != null)
  969. {
  970. mxUtils.setOpacity(btnGroup, op);
  971. }
  972. if (ui.statusContainer != null)
  973. {
  974. menubar.insertBefore(btnGroup, ui.statusContainer);
  975. }
  976. else
  977. {
  978. menubar.appendChild(btnGroup);
  979. }
  980. return btnGroup;
  981. };
  982. ui.statusContainer = ui.createStatusContainer();
  983. ui.statusContainer.style.position = 'relative';
  984. ui.statusContainer.style.maxWidth = '';
  985. ui.statusContainer.style.marginTop = '7px';
  986. ui.statusContainer.style.marginLeft = '6px';
  987. ui.statusContainer.style.color = 'gray';
  988. ui.statusContainer.style.cursor = 'default';
  989. function updateTitle()
  990. {
  991. var file = ui.getCurrentFile();
  992. if (file != null && file.getTitle() != null)
  993. {
  994. var mode = file.getMode();
  995. if (mode == 'google')
  996. {
  997. mode = 'googleDrive';
  998. }
  999. else if (mode == 'github')
  1000. {
  1001. mode = 'gitHub';
  1002. }
  1003. else if (mode == 'onedrive')
  1004. {
  1005. mode = 'oneDrive';
  1006. }
  1007. mode = mxResources.get(mode);
  1008. menubar.setAttribute('title', file.getTitle() + ((mode != null) ? ' (' + mode + ')' : ''));
  1009. }
  1010. else
  1011. {
  1012. menubar.removeAttribute('title');
  1013. }
  1014. };
  1015. // Connects the status bar to the editor status
  1016. ui.editor.addListener('statusChanged', mxUtils.bind(this, function()
  1017. {
  1018. ui.setStatusText(ui.editor.getStatus());
  1019. }));
  1020. // Connects the status bar to the editor status
  1021. var uiDescriptorChanged = ui.descriptorChanged;
  1022. ui.descriptorChanged = function()
  1023. {
  1024. uiDescriptorChanged.apply(this, arguments);
  1025. updateTitle();
  1026. };
  1027. ui.setStatusText(ui.editor.getStatus());
  1028. menubar.appendChild(ui.statusContainer);
  1029. ui.buttonContainer = document.createElement('div');
  1030. ui.buttonContainer.style.cssText = 'position:absolute;right:0px;padding-right:34px;top:10px;' +
  1031. 'white-space:nowrap;padding-top:2px;background-color:inherit;';
  1032. menubar.appendChild(ui.buttonContainer);
  1033. // Container for the user element
  1034. ui.menubarContainer = ui.buttonContainer;
  1035. ui.tabContainer = document.createElement('div');
  1036. ui.tabContainer.style.cssText = 'position:absolute;left:0px;right:0px;bottom:0px;height:30px;white-space:nowrap;' +
  1037. 'border-bottom:1px solid lightgray;background-color:#ffffff;border-top:1px solid lightgray;margin-bottom:-2px;' +
  1038. 'visibility:hidden;';
  1039. var previousParent = ui.diagramContainer.parentNode;
  1040. var wrapper = document.createElement('div');
  1041. wrapper.style.cssText = 'position:absolute;top:0px;left:0px;right:0px;bottom:0px;overflow:hidden;';
  1042. ui.diagramContainer.style.top = '47px';
  1043. var viewZoomMenu = ui.menus.get('viewZoom');
  1044. var viewZoomMenuElt = null;
  1045. if (viewZoomMenu != null)
  1046. {
  1047. this.tabContainer.style.right = '70px';
  1048. var elt = menuObj.addMenu('100%', viewZoomMenu.funct);
  1049. elt.setAttribute('title', mxResources.get('zoom') + ' (Alt+Mousewheel)');
  1050. elt.style.whiteSpace = 'nowrap';
  1051. elt.style.backgroundImage = 'url(' + mxWindow.prototype.minimizeImage + ')';
  1052. elt.style.backgroundPosition = 'right 6px center';
  1053. elt.style.backgroundRepeat = 'no-repeat';
  1054. elt.style.backgroundColor = '#ffffff';
  1055. elt.style.paddingRight = '10px';
  1056. elt.style.display = 'block';
  1057. elt.style.position = 'absolute';
  1058. elt.style.textDecoration = 'none';
  1059. elt.style.textDecoration = 'none';
  1060. elt.style.right = '0px';
  1061. elt.style.bottom = '0px';
  1062. elt.style.overflow = 'hidden';
  1063. elt.style.visibility = 'hidden';
  1064. elt.style.textAlign = 'center';
  1065. elt.style.color = '#000';
  1066. elt.style.fontSize = '12px';
  1067. elt.style.color = '#707070';
  1068. elt.style.width = '59px';
  1069. elt.style.cursor = 'pointer';
  1070. elt.style.borderTop = '1px solid lightgray';
  1071. elt.style.borderLeft = '1px solid lightgray';
  1072. elt.style.height = (parseInt(ui.tabContainerHeight) - 1) + 'px';
  1073. elt.style.lineHeight = (parseInt(ui.tabContainerHeight) + 1) + 'px';
  1074. wrapper.appendChild(elt);
  1075. // Updates the label if the scale changes
  1076. var updateZoom = mxUtils.bind(this, function()
  1077. {
  1078. elt.innerHTML = Math.round(ui.editor.graph.view.scale * 100) + '%';
  1079. });
  1080. ui.editor.graph.view.addListener(mxEvent.EVENT_SCALE, updateZoom);
  1081. ui.editor.addListener('resetGraphView', updateZoom);
  1082. ui.editor.addListener('pageSelected', updateZoom);
  1083. // Augments setGraphEnabled to update visible state
  1084. var uiSetGraphEnabled = ui.setGraphEnabled;
  1085. ui.setGraphEnabled = function()
  1086. {
  1087. uiSetGraphEnabled.apply(this, arguments);
  1088. if (this.tabContainer != null)
  1089. {
  1090. elt.style.visibility = this.tabContainer.style.visibility;
  1091. this.diagramContainer.style.bottom = (this.tabContainer.style.visibility != 'hidden') ?
  1092. this.tabContainerHeight + 'px' : '0px';
  1093. }
  1094. };
  1095. }
  1096. wrapper.appendChild(ui.tabContainer);
  1097. wrapper.appendChild(menubar);
  1098. wrapper.appendChild(ui.diagramContainer);
  1099. previousParent.appendChild(wrapper);
  1100. ui.updateTabContainer();
  1101. var langMenuElt = null;
  1102. function refreshMenu()
  1103. {
  1104. // Removes all existing menu items
  1105. var node = menubar.firstChild;
  1106. while (node != null)
  1107. {
  1108. var temp = node.nextSibling;
  1109. if (node.className == 'geMenuItem' || node.className == 'geItem')
  1110. {
  1111. node.parentNode.removeChild(node);
  1112. }
  1113. node = temp;
  1114. }
  1115. before = menubar.firstChild;
  1116. iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1117. var small = iw < 1000;
  1118. if (!small)
  1119. {
  1120. addMenu('diagram');
  1121. }
  1122. createGroup([((small) ? addMenu('diagram', null, IMAGE_PATH + '/drawlogo.svg') : null),
  1123. addMenuItem(mxResources.get('shapes'), ui.actions.get('toggleShapes').funct, null, mxResources.get('shapes'), ui.actions.get('image'),
  1124. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTMgMTN2OGg4di04aC04ek0zIDIxaDh2LThIM3Y4ek0zIDN2OGg4VjNIM3ptMTMuNjYtMS4zMUwxMSA3LjM0IDE2LjY2IDEzbDUuNjYtNS42Ni01LjY2LTUuNjV6Ii8+PC9zdmc+' : null),
  1125. addMenuItem(mxResources.get('format'), ui.actions.get('toggleFormat').funct, null,
  1126. mxResources.get('format') + ' (' + ui.actions.get('formatPanel').shortcut + ')', ui.actions.get('image'),
  1127. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIgM2MtNC45NyAwLTkgNC4wMy05IDlzNC4wMyA5IDkgOWMuODMgMCAxLjUtLjY3IDEuNS0xLjUgMC0uMzktLjE1LS43NC0uMzktMS4wMS0uMjMtLjI2LS4zOC0uNjEtLjM4LS45OSAwLS44My42Ny0xLjUgMS41LTEuNUgxNmMyLjc2IDAgNS0yLjI0IDUtNSAwLTQuNDItNC4wMy04LTktOHptLTUuNSA5Yy0uODMgMC0xLjUtLjY3LTEuNS0xLjVTNS42NyA5IDYuNSA5IDggOS42NyA4IDEwLjUgNy4zMyAxMiA2LjUgMTJ6bTMtNEM4LjY3IDggOCA3LjMzIDggNi41UzguNjcgNSA5LjUgNXMxLjUuNjcgMS41IDEuNVMxMC4zMyA4IDkuNSA4em01IDBjLS44MyAwLTEuNS0uNjctMS41LTEuNVMxMy42NyA1IDE0LjUgNXMxLjUuNjcgMS41IDEuNVMxNS4zMyA4IDE0LjUgOHptMyA0Yy0uODMgMC0xLjUtLjY3LTEuNS0xLjVTMTYuNjcgOSAxNy41IDlzMS41LjY3IDEuNSAxLjUtLjY3IDEuNS0xLjUgMS41eiIvPjwvc3ZnPg==' : null)],
  1128. (small) ? 60 : null);
  1129. var elt = addMenu('insert', true, (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTkgMTNoLTZ2NmgtMnYtNkg1di0yaDZWNWgydjZoNnYyeiIvPjwvc3ZnPg==' : null);
  1130. createGroup([elt, addMenuItem(mxResources.get('delete'), ui.actions.get('delete').funct, null, mxResources.get('delete'), ui.actions.get('delete'),
  1131. (small) ? 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNNiAxOWMwIDEuMS45IDIgMiAyaDhjMS4xIDAgMi0uOSAyLTJWN0g2djEyek0xOSA0aC0zLjVsLTEtMWgtNWwtMSAxSDV2MmgxNFY0eiIvPjwvc3ZnPg==' : null)],
  1132. (small) ? 60 : null);
  1133. if (iw >= 411)
  1134. {
  1135. var undoAction = ui.actions.get('undo');
  1136. var redoAction = ui.actions.get('redo');
  1137. var undoElt = addMenuItem('', undoAction.funct, null, mxResources.get('undo') + ' (' + undoAction.shortcut + ')', undoAction,
  1138. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTIuNSA4Yy0yLjY1IDAtNS4wNS45OS02LjkgMi42TDIgN3Y5aDlsLTMuNjItMy42MmMxLjM5LTEuMTYgMy4xNi0xLjg4IDUuMTItMS44OCAzLjU0IDAgNi41NSAyLjMxIDcuNiA1LjVsMi4zNy0uNzhDMjEuMDggMTEuMDMgMTcuMTUgOCAxMi41IDh6Ii8+PC9zdmc+');
  1139. var redoElt = addMenuItem('', redoAction.funct, null, mxResources.get('redo') + ' (' + redoAction.shortcut + ')', redoAction,
  1140. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTguNCAxMC42QzE2LjU1IDguOTkgMTQuMTUgOCAxMS41IDhjLTQuNjUgMC04LjU4IDMuMDMtOS45NiA3LjIyTDMuOSAxNmMxLjA1LTMuMTkgNC4wNS01LjUgNy42LTUuNSAxLjk1IDAgMy43My43MiA1LjEyIDEuODhMMTMgMTZoOVY3bC0zLjYgMy42eiIvPjwvc3ZnPg==');
  1141. createGroup([undoElt, redoElt], 60);
  1142. if (iw >= 480)
  1143. {
  1144. var zoomInAction = ui.actions.get('zoomIn');
  1145. var zoomOutAction = ui.actions.get('zoomOut');
  1146. var resetViewAction = ui.actions.get('resetView');
  1147. createGroup([addMenuItem('', function()
  1148. {
  1149. graph.popupMenuHandler.hideMenu();
  1150. var scale = graph.view.scale;
  1151. var tx = graph.view.translate.x;
  1152. var ty = graph.view.translate.y;
  1153. ui.actions.get('resetView').funct();
  1154. // Toggle scale if nothing has changed
  1155. if (Math.abs(scale - graph.view.scale) < 0.00001 && tx == graph.view.translate.x && ty == graph.view.translate.y)
  1156. {
  1157. ui.actions.get((graph.pageVisible) ? 'fitPage' : 'fitWindow').funct();
  1158. }
  1159. }, true, mxResources.get('fit') + ' (' + Editor.ctrlKey + '+H)', resetViewAction,
  1160. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMyA1djRoMlY1aDRWM0g1Yy0xLjEgMC0yIC45LTIgMnptMiAxMEgzdjRjMCAxLjEuOSAyIDIgMmg0di0ySDV2LTR6bTE0IDRoLTR2Mmg0YzEuMSAwIDItLjkgMi0ydi00aC0ydjR6bTAtMTZoLTR2Mmg0djRoMlY1YzAtMS4xLS45LTItMi0yeiIvPjwvc3ZnPg=='),
  1161. (iw >= 640) ? addMenuItem('', zoomInAction.funct, true, mxResources.get('zoomIn') + ' (' + Editor.ctrlKey + ' +)', zoomInAction,
  1162. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTUuNSAxNGgtLjc5bC0uMjgtLjI3QzE1LjQxIDEyLjU5IDE2IDExLjExIDE2IDkuNSAxNiA1LjkxIDEzLjA5IDMgOS41IDNTMyA1LjkxIDMgOS41IDUuOTEgMTYgOS41IDE2YzEuNjEgMCAzLjA5LS41OSA0LjIzLTEuNTdsLjI3LjI4di43OWw1IDQuOTlMMjAuNDkgMTlsLTQuOTktNXptLTYgMEM3LjAxIDE0IDUgMTEuOTkgNSA5LjVTNy4wMSA1IDkuNSA1IDE0IDcuMDEgMTQgOS41IDExLjk5IDE0IDkuNSAxNHptMi41LTRoLTJ2Mkg5di0ySDdWOWgyVjdoMXYyaDJ2MXoiLz48L3N2Zz4=') : null,
  1163. (iw >= 640) ? addMenuItem('', zoomOutAction.funct, true, mxResources.get('zoomOut') + ' (' + Editor.ctrlKey + ' -)', zoomOutAction,
  1164. 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBkPSJNMTUuNSAxNGgtLjc5bC0uMjgtLjI3QzE1LjQxIDEyLjU5IDE2IDExLjExIDE2IDkuNSAxNiA1LjkxIDEzLjA5IDMgOS41IDNTMyA1LjkxIDMgOS41IDUuOTEgMTYgOS41IDE2YzEuNjEgMCAzLjA5LS41OSA0LjIzLTEuNTdsLjI3LjI4di43OWw1IDQuOTlMMjAuNDkgMTlsLTQuOTktNXptLTYgMEM3LjAxIDE0IDUgMTEuOTkgNSA5LjVTNy4wMSA1IDkuNSA1IDE0IDcuMDEgMTQgOS41IDExLjk5IDE0IDkuNSAxNHpNNyA5aDV2MUg3eiIvPjwvc3ZnPg==') : null], 60);
  1165. }
  1166. }
  1167. var langMenu = ui.menus.get('language');
  1168. if (langMenu != null && !mxClient.IS_CHROMEAPP &&
  1169. !EditorUi.isElectronApp && iw >= 600)
  1170. {
  1171. if (langMenuElt == null)
  1172. {
  1173. var elt = menuObj.addMenu('', langMenu.funct);
  1174. elt.setAttribute('title', mxResources.get('language'));
  1175. elt.className = 'geToolbarButton';
  1176. elt.style.backgroundImage = 'url(' + Editor.globeImage + ')';
  1177. elt.style.backgroundPosition = 'center center';
  1178. elt.style.backgroundRepeat = 'no-repeat';
  1179. elt.style.backgroundSize = '24px 24px';
  1180. elt.style.position = 'absolute';
  1181. elt.style.height = '24px';
  1182. elt.style.width = '24px';
  1183. elt.style.zIndex = '1';
  1184. elt.style.right = '8px';
  1185. elt.style.cursor = 'pointer';
  1186. elt.style.top = (urlParams['embed'] == '1') ? '13px' : '11px';
  1187. menubar.appendChild(elt);
  1188. langMenuElt = elt;
  1189. }
  1190. ui.buttonContainer.style.paddingRight = '34px';
  1191. }
  1192. else
  1193. {
  1194. ui.buttonContainer.style.paddingRight = '4px';
  1195. if (langMenuElt != null)
  1196. {
  1197. langMenuElt.parentNode.removeChild(langMenuElt);
  1198. langMenuElt = null;
  1199. }
  1200. }
  1201. };
  1202. refreshMenu();
  1203. mxEvent.addListener(window, 'resize', function()
  1204. {
  1205. refreshMenu();
  1206. if (ui.sidebarWindow != null)
  1207. {
  1208. ui.sidebarWindow.window.fit();
  1209. }
  1210. if (ui.formatWindow != null)
  1211. {
  1212. ui.formatWindow.window.fit();
  1213. }
  1214. if (ui.actions.outlineWindow != null)
  1215. {
  1216. ui.actions.outlineWindow.window.fit();
  1217. }
  1218. if (ui.actions.layersWindow != null)
  1219. {
  1220. ui.actions.layersWindow.window.fit();
  1221. }
  1222. if (ui.menus.tagsWindow != null)
  1223. {
  1224. ui.menus.tagsWindow.window.fit();
  1225. }
  1226. if (ui.menus.findWindow != null)
  1227. {
  1228. ui.menus.findWindow.window.fit();
  1229. }
  1230. });
  1231. };
  1232. };
  1233. (function()
  1234. {
  1235. var initialized = false;
  1236. // ChromeApp has async local storage
  1237. if (uiTheme == 'min' && !initialized && !mxClient.IS_CHROMEAPP)
  1238. {
  1239. EditorUi.initMinimalTheme();
  1240. initialized = true;
  1241. }
  1242. var uiInitTheme = EditorUi.initTheme;
  1243. // For async startup like chromeos
  1244. EditorUi.initTheme = function()
  1245. {
  1246. uiInitTheme.apply(this, arguments);
  1247. if (uiTheme == 'min' && !initialized)
  1248. {
  1249. this.initMinimalTheme();
  1250. initialized = true;
  1251. }
  1252. };
  1253. })();