Toolbar.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Construcs a new toolbar for the given editor.
  6. */
  7. function Toolbar(editorUi, container)
  8. {
  9. this.editorUi = editorUi;
  10. this.container = container;
  11. this.staticElements = [];
  12. this.init();
  13. // Global handler to hide the current menu
  14. this.gestureHandler = mxUtils.bind(this, function(evt)
  15. {
  16. if (this.editorUi.currentMenu != null && mxEvent.getSource(evt) != this.editorUi.currentMenu.div)
  17. {
  18. this.hideMenu();
  19. }
  20. });
  21. mxEvent.addGestureListeners(document, this.gestureHandler);
  22. };
  23. /**
  24. * Image for the dropdown arrow.
  25. */
  26. Toolbar.prototype.dropdownImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/dropdown.gif' : 'data:image/gif;base64,R0lGODlhDQANAIABAHt7e////yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCREM1NkJFMjE0NEMxMUU1ODk1Q0M5MjQ0MTA4QjNDMSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCREM1NkJFMzE0NEMxMUU1ODk1Q0M5MjQ0MTA4QjNDMSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkQzOUMzMjZCMTQ0QjExRTU4OTVDQzkyNDQxMDhCM0MxIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkQzOUMzMjZDMTQ0QjExRTU4OTVDQzkyNDQxMDhCM0MxIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAQAAAQAsAAAAAA0ADQAAAhGMj6nL3QAjVHIu6azbvPtWAAA7';
  27. /**
  28. * Image element for the dropdown arrow.
  29. */
  30. Toolbar.prototype.dropdownImageHtml = '<img border="0" style="position:absolute;right:4px;top:' +
  31. ((!EditorUi.compactUi) ? 8 : 6) + 'px;" src="' + Toolbar.prototype.dropdownImage + '" valign="middle"/>';
  32. /**
  33. * Defines the background for selected buttons.
  34. */
  35. Toolbar.prototype.selectedBackground = '#d0d0d0';
  36. /**
  37. * Defines the background for selected buttons.
  38. */
  39. Toolbar.prototype.unselectedBackground = 'none';
  40. /**
  41. * Array that contains the DOM nodes that should never be removed.
  42. */
  43. Toolbar.prototype.staticElements = null;
  44. /**
  45. * Adds the toolbar elements.
  46. */
  47. Toolbar.prototype.init = function()
  48. {
  49. var sw = screen.width;
  50. // Takes into account initial compact mode
  51. sw -= (screen.height > 740) ? 56 : 0;
  52. if (sw >= 700)
  53. {
  54. var formatMenu = this.addMenu('', mxResources.get('view') + ' (' + mxResources.get('panTooltip') + ')', true, 'viewPanels', null, true);
  55. this.addDropDownArrow(formatMenu, 'geSprite-formatpanel', 38, 50, -4, -3, 36, -8);
  56. this.addSeparator();
  57. }
  58. var viewMenu = this.addMenu('', mxResources.get('zoom') + ' (Alt+Mousewheel)', true, 'viewZoom', null, true);
  59. viewMenu.showDisabled = true;
  60. viewMenu.style.whiteSpace = 'nowrap';
  61. viewMenu.style.position = 'relative';
  62. viewMenu.style.overflow = 'hidden';
  63. if (EditorUi.compactUi)
  64. {
  65. viewMenu.style.width = (mxClient.IS_QUIRKS) ? '58px' : '50px';
  66. }
  67. else
  68. {
  69. viewMenu.style.width = (mxClient.IS_QUIRKS) ? '62px' : '36px';
  70. }
  71. if (sw >= 420)
  72. {
  73. this.addSeparator();
  74. var elts = this.addItems(['zoomIn', 'zoomOut']);
  75. elts[0].setAttribute('title', mxResources.get('zoomIn') + ' (' + this.editorUi.actions.get('zoomIn').shortcut + ')');
  76. elts[1].setAttribute('title', mxResources.get('zoomOut') + ' (' + this.editorUi.actions.get('zoomOut').shortcut + ')');
  77. }
  78. // Updates the label if the scale changes
  79. this.updateZoom = mxUtils.bind(this, function()
  80. {
  81. viewMenu.innerHTML = Math.round(this.editorUi.editor.graph.view.scale * 100) + '%' +
  82. this.dropdownImageHtml;
  83. if (EditorUi.compactUi)
  84. {
  85. viewMenu.getElementsByTagName('img')[0].style.right = '1px';
  86. viewMenu.getElementsByTagName('img')[0].style.top = '5px';
  87. }
  88. });
  89. this.editorUi.editor.graph.view.addListener(mxEvent.EVENT_SCALE, this.updateZoom);
  90. this.editorUi.editor.addListener('resetGraphView', this.updateZoom);
  91. var elts = this.addItems(['-', 'undo', 'redo']);
  92. elts[1].setAttribute('title', mxResources.get('undo') + ' (' + this.editorUi.actions.get('undo').shortcut + ')');
  93. elts[2].setAttribute('title', mxResources.get('redo') + ' (' + this.editorUi.actions.get('redo').shortcut + ')');
  94. if (sw >= 320)
  95. {
  96. var elts = this.addItems(['-', 'delete']);
  97. elts[1].setAttribute('title', mxResources.get('delete') + ' (' + this.editorUi.actions.get('delete').shortcut + ')');
  98. }
  99. if (sw >= 550)
  100. {
  101. this.addItems(['-', 'toFront', 'toBack']);
  102. }
  103. if (sw >= 740)
  104. {
  105. this.addItems(['-', 'fillColor']);
  106. if (sw >= 780)
  107. {
  108. this.addItems(['strokeColor']);
  109. if (sw >= 820)
  110. {
  111. this.addItems(['shadow']);
  112. }
  113. }
  114. }
  115. if (sw >= 400)
  116. {
  117. this.addSeparator();
  118. if (sw >= 440)
  119. {
  120. this.edgeShapeMenu = this.addMenuFunction('', mxResources.get('connection'), false, mxUtils.bind(this, function(menu)
  121. {
  122. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], [null, null], 'geIcon geSprite geSprite-connection', null, true).setAttribute('title', mxResources.get('line'));
  123. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['link', null], 'geIcon geSprite geSprite-linkedge', null, true).setAttribute('title', mxResources.get('link'));
  124. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['flexArrow', null], 'geIcon geSprite geSprite-arrow', null, true).setAttribute('title', mxResources.get('arrow'));
  125. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['arrow', null], 'geIcon geSprite geSprite-simplearrow', null, true).setAttribute('title', mxResources.get('simpleArrow'));
  126. }));
  127. this.addDropDownArrow(this.edgeShapeMenu, 'geSprite-connection', 44, 50, 0, 0, 22, -4);
  128. }
  129. this.edgeStyleMenu = this.addMenuFunction('geSprite-orthogonal', mxResources.get('waypoints'), false, mxUtils.bind(this, function(menu)
  130. {
  131. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], [null, null, null], 'geIcon geSprite geSprite-straight', null, true).setAttribute('title', mxResources.get('straight'));
  132. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', null, null], 'geIcon geSprite geSprite-orthogonal', null, true).setAttribute('title', mxResources.get('orthogonal'));
  133. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalelbow', null, true).setAttribute('title', mxResources.get('simple'));
  134. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalelbow', null, true).setAttribute('title', mxResources.get('simple'));
  135. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalisometric', null, true).setAttribute('title', mxResources.get('isometric'));
  136. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalisometric', null, true).setAttribute('title', mxResources.get('isometric'));
  137. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', '1', null], 'geIcon geSprite geSprite-curved', null, true).setAttribute('title', mxResources.get('curved'));
  138. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['entityRelationEdgeStyle', null, null], 'geIcon geSprite geSprite-entity', null, true).setAttribute('title', mxResources.get('entityRelation'));
  139. }));
  140. this.addDropDownArrow(this.edgeStyleMenu, 'geSprite-orthogonal', 44, 50, 0, 0, 22, -4);
  141. }
  142. this.addSeparator();
  143. var insertMenu = this.addMenu('', mxResources.get('insert') + ' (' + mxResources.get('doubleClickTooltip') + ')', true, 'insert', null, true);
  144. this.addDropDownArrow(insertMenu, 'geSprite-plus', 38, 48, -4, -3, 36, -8);
  145. this.addTableDropDown();
  146. };
  147. /**
  148. * Adds the toolbar elements.
  149. */
  150. Toolbar.prototype.addTableDropDown = function()
  151. {
  152. this.addSeparator();
  153. // KNOWN: All table stuff does not work with undo/redo
  154. // KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
  155. // to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
  156. var menuElt = this.addMenuFunction('geIcon geSprite geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
  157. {
  158. var graph = this.editorUi.editor.graph;
  159. var cell = graph.getSelectionCell();
  160. if (!graph.isTableCell(cell) && !graph.isTableRow(cell) && !graph.isTable(cell))
  161. {
  162. this.editorUi.menus.addInsertTableCellItem(menu);
  163. }
  164. else
  165. {
  166. var elt = menu.addItem('', null, mxUtils.bind(this, function()
  167. {
  168. try
  169. {
  170. graph.insertTableColumn(cell, true);
  171. }
  172. catch (e)
  173. {
  174. this.editorUi.handleError(e);
  175. }
  176. }), null, 'geIcon geSprite geSprite-insertcolumnbefore');
  177. elt.setAttribute('title', mxResources.get('insertColumnBefore'));
  178. elt = menu.addItem('', null, mxUtils.bind(this, function()
  179. {
  180. try
  181. {
  182. graph.insertTableColumn(cell, false);
  183. }
  184. catch (e)
  185. {
  186. this.editorUi.handleError(e);
  187. }
  188. }), null, 'geIcon geSprite geSprite-insertcolumnafter');
  189. elt.setAttribute('title', mxResources.get('insertColumnAfter'));
  190. elt = menu.addItem('Delete column', null, mxUtils.bind(this, function()
  191. {
  192. if (cell != null)
  193. {
  194. try
  195. {
  196. graph.deleteTableColumn(cell);
  197. }
  198. catch (e)
  199. {
  200. this.editorUi.handleError(e);
  201. }
  202. }
  203. }), null, 'geIcon geSprite geSprite-deletecolumn');
  204. elt.setAttribute('title', mxResources.get('deleteColumn'));
  205. elt = menu.addItem('', null, mxUtils.bind(this, function()
  206. {
  207. try
  208. {
  209. graph.insertTableRow(cell, true);
  210. }
  211. catch (e)
  212. {
  213. this.editorUi.handleError(e);
  214. }
  215. }), null, 'geIcon geSprite geSprite-insertrowbefore');
  216. elt.setAttribute('title', mxResources.get('insertRowBefore'));
  217. elt = menu.addItem('', null, mxUtils.bind(this, function()
  218. {
  219. try
  220. {
  221. graph.insertTableRow(cell, false);
  222. }
  223. catch (e)
  224. {
  225. this.editorUi.handleError(e);
  226. }
  227. }), null, 'geIcon geSprite geSprite-insertrowafter');
  228. elt.setAttribute('title', mxResources.get('insertRowAfter'));
  229. elt = menu.addItem('', null, mxUtils.bind(this, function()
  230. {
  231. try
  232. {
  233. graph.deleteTableRow(cell);
  234. }
  235. catch (e)
  236. {
  237. this.editorUi.handleError(e);
  238. }
  239. }), null, 'geIcon geSprite geSprite-deleterow');
  240. elt.setAttribute('title', mxResources.get('deleteRow'));
  241. }
  242. }));
  243. menuElt.style.position = 'relative';
  244. menuElt.style.whiteSpace = 'nowrap';
  245. menuElt.style.overflow = 'hidden';
  246. menuElt.innerHTML = '<div class="geSprite geSprite-table" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
  247. menuElt.style.width = (mxClient.IS_QUIRKS) ? '50px' : '30px';
  248. // Fix for item size in kennedy theme
  249. if (EditorUi.compactUi)
  250. {
  251. menuElt.getElementsByTagName('img')[0].style.left = '22px';
  252. menuElt.getElementsByTagName('img')[0].style.top = '5px';
  253. }
  254. // Connects to insert menu enabled state
  255. var menu = this.editorUi.menus.get('insert');
  256. // Workaround for possible not a function
  257. // when extending HTML objects
  258. if (menu != null && typeof menuElt.setEnabled === 'function')
  259. {
  260. menu.addListener('stateChanged', function()
  261. {
  262. menuElt.setEnabled(menu.enabled);
  263. });
  264. }
  265. return menuElt;
  266. };
  267. /**
  268. * Adds the toolbar elements.
  269. */
  270. Toolbar.prototype.addDropDownArrow = function(menu, sprite, width, atlasWidth, left, top, atlasDelta, atlasLeft)
  271. {
  272. atlasDelta = (atlasDelta != null) ? atlasDelta : 32;
  273. left = (EditorUi.compactUi) ? left : atlasLeft;
  274. menu.style.whiteSpace = 'nowrap';
  275. menu.style.overflow = 'hidden';
  276. menu.style.position = 'relative';
  277. menu.innerHTML = '<div class="geSprite ' + sprite + '" style="margin-left:' + left + 'px;margin-top:' + top + 'px;"></div>' +
  278. this.dropdownImageHtml;
  279. menu.style.width = (mxClient.IS_QUIRKS) ? atlasWidth + 'px' : (atlasWidth - atlasDelta) + 'px';
  280. if (mxClient.IS_QUIRKS)
  281. {
  282. menu.style.height = (EditorUi.compactUi) ? '24px' : '26px';
  283. }
  284. // Fix for item size in kennedy theme
  285. if (EditorUi.compactUi)
  286. {
  287. menu.getElementsByTagName('img')[0].style.left = '24px';
  288. menu.getElementsByTagName('img')[0].style.top = '5px';
  289. menu.style.width = (mxClient.IS_QUIRKS) ? width + 'px' : (width - 10) + 'px';
  290. }
  291. };
  292. /**
  293. * Sets the current font name.
  294. */
  295. Toolbar.prototype.setFontName = function(value)
  296. {
  297. if (this.fontMenu != null)
  298. {
  299. this.fontMenu.innerHTML = '<div style="width:60px;overflow:hidden;display:inline-block;">' +
  300. mxUtils.htmlEntities(value) + '</div>' + this.dropdownImageHtml;
  301. }
  302. };
  303. /**
  304. * Sets the current font name.
  305. */
  306. Toolbar.prototype.setFontSize = function(value)
  307. {
  308. if (this.sizeMenu != null)
  309. {
  310. this.sizeMenu.innerHTML = '<div style="width:24px;overflow:hidden;display:inline-block;">' +
  311. mxUtils.htmlEntities(value) + '</div>' + this.dropdownImageHtml;
  312. }
  313. };
  314. /**
  315. * Hides the current menu.
  316. */
  317. Toolbar.prototype.createTextToolbar = function()
  318. {
  319. var graph = this.editorUi.editor.graph;
  320. var styleElt = this.addMenu('', mxResources.get('style'), true, 'formatBlock');
  321. styleElt.style.position = 'relative';
  322. styleElt.style.whiteSpace = 'nowrap';
  323. styleElt.style.overflow = 'hidden';
  324. styleElt.innerHTML = mxResources.get('style') + this.dropdownImageHtml;
  325. if (EditorUi.compactUi)
  326. {
  327. styleElt.style.paddingRight = '18px';
  328. styleElt.getElementsByTagName('img')[0].style.right = '1px';
  329. styleElt.getElementsByTagName('img')[0].style.top = '5px';
  330. }
  331. this.addSeparator();
  332. this.fontMenu = this.addMenu('', mxResources.get('fontFamily'), true, 'fontFamily');
  333. this.fontMenu.style.position = 'relative';
  334. this.fontMenu.style.whiteSpace = 'nowrap';
  335. this.fontMenu.style.overflow = 'hidden';
  336. this.fontMenu.style.width = (mxClient.IS_QUIRKS) ? '80px' : '60px';
  337. this.setFontName(Menus.prototype.defaultFont);
  338. if (EditorUi.compactUi)
  339. {
  340. this.fontMenu.style.paddingRight = '18px';
  341. this.fontMenu.getElementsByTagName('img')[0].style.right = '1px';
  342. this.fontMenu.getElementsByTagName('img')[0].style.top = '5px';
  343. }
  344. this.addSeparator();
  345. this.sizeMenu = this.addMenu(Menus.prototype.defaultFontSize, mxResources.get('fontSize'), true, 'fontSize');
  346. this.sizeMenu.style.position = 'relative';
  347. this.sizeMenu.style.whiteSpace = 'nowrap';
  348. this.sizeMenu.style.overflow = 'hidden';
  349. this.sizeMenu.style.width = (mxClient.IS_QUIRKS) ? '44px' : '24px';
  350. this.setFontSize(Menus.prototype.defaultFontSize);
  351. if (EditorUi.compactUi)
  352. {
  353. this.sizeMenu.style.paddingRight = '18px';
  354. this.sizeMenu.getElementsByTagName('img')[0].style.right = '1px';
  355. this.sizeMenu.getElementsByTagName('img')[0].style.top = '5px';
  356. }
  357. var elts = this.addItems(['-', 'undo', 'redo','-', 'bold', 'italic', 'underline']);
  358. elts[1].setAttribute('title', mxResources.get('undo') + ' (' + this.editorUi.actions.get('undo').shortcut + ')');
  359. elts[2].setAttribute('title', mxResources.get('redo') + ' (' + this.editorUi.actions.get('redo').shortcut + ')');
  360. elts[4].setAttribute('title', mxResources.get('bold') + ' (' + this.editorUi.actions.get('bold').shortcut + ')');
  361. elts[5].setAttribute('title', mxResources.get('italic') + ' (' + this.editorUi.actions.get('italic').shortcut + ')');
  362. elts[6].setAttribute('title', mxResources.get('underline') + ' (' + this.editorUi.actions.get('underline').shortcut + ')');
  363. // KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
  364. // to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
  365. var alignMenu = this.addMenuFunction('', mxResources.get('align'), false, mxUtils.bind(this, function(menu)
  366. {
  367. elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
  368. {
  369. graph.cellEditor.alignText(mxConstants.ALIGN_LEFT, evt);
  370. }), null, 'geIcon geSprite geSprite-left');
  371. elt.setAttribute('title', mxResources.get('left'));
  372. elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
  373. {
  374. graph.cellEditor.alignText(mxConstants.ALIGN_CENTER, evt);
  375. }), null, 'geIcon geSprite geSprite-center');
  376. elt.setAttribute('title', mxResources.get('center'));
  377. elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
  378. {
  379. graph.cellEditor.alignText(mxConstants.ALIGN_RIGHT, evt);
  380. }), null, 'geIcon geSprite geSprite-right');
  381. elt.setAttribute('title', mxResources.get('right'));
  382. elt = menu.addItem('', null, mxUtils.bind(this, function()
  383. {
  384. document.execCommand('justifyfull', false, null);
  385. }), null, 'geIcon geSprite geSprite-justifyfull');
  386. elt.setAttribute('title', mxResources.get('justifyfull'));
  387. elt = menu.addItem('', null, mxUtils.bind(this, function()
  388. {
  389. document.execCommand('insertorderedlist', false, null);
  390. }), null, 'geIcon geSprite geSprite-orderedlist');
  391. elt.setAttribute('title', mxResources.get('numberedList'));
  392. elt = menu.addItem('', null, mxUtils.bind(this, function()
  393. {
  394. document.execCommand('insertunorderedlist', false, null);
  395. }), null, 'geIcon geSprite geSprite-unorderedlist');
  396. elt.setAttribute('title', mxResources.get('bulletedList'));
  397. elt = menu.addItem('', null, mxUtils.bind(this, function()
  398. {
  399. document.execCommand('outdent', false, null);
  400. }), null, 'geIcon geSprite geSprite-outdent');
  401. elt.setAttribute('title', mxResources.get('decreaseIndent'));
  402. elt = menu.addItem('', null, mxUtils.bind(this, function()
  403. {
  404. document.execCommand('indent', false, null);
  405. }), null, 'geIcon geSprite geSprite-indent');
  406. elt.setAttribute('title', mxResources.get('increaseIndent'));
  407. }));
  408. alignMenu.style.position = 'relative';
  409. alignMenu.style.whiteSpace = 'nowrap';
  410. alignMenu.style.overflow = 'hidden';
  411. alignMenu.innerHTML = '<div class="geSprite geSprite-left" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
  412. alignMenu.style.width = (mxClient.IS_QUIRKS) ? '50px' : '30px';
  413. if (EditorUi.compactUi)
  414. {
  415. alignMenu.getElementsByTagName('img')[0].style.left = '22px';
  416. alignMenu.getElementsByTagName('img')[0].style.top = '5px';
  417. }
  418. var formatMenu = this.addMenuFunction('', mxResources.get('format'), false, mxUtils.bind(this, function(menu)
  419. {
  420. elt = menu.addItem('', null, this.editorUi.actions.get('subscript').funct,
  421. null, 'geIcon geSprite geSprite-subscript');
  422. elt.setAttribute('title', mxResources.get('subscript') + ' (' + Editor.ctrlKey + '+,)');
  423. elt = menu.addItem('', null, this.editorUi.actions.get('superscript').funct,
  424. null, 'geIcon geSprite geSprite-superscript');
  425. elt.setAttribute('title', mxResources.get('superscript') + ' (' + Editor.ctrlKey + '+.)');
  426. // KNOWN: IE+FF don't return keyboard focus after color dialog (calling focus doesn't help)
  427. elt = menu.addItem('', null, this.editorUi.actions.get('fontColor').funct,
  428. null, 'geIcon geSprite geSprite-fontcolor');
  429. elt.setAttribute('title', mxResources.get('fontColor'));
  430. elt = menu.addItem('', null, this.editorUi.actions.get('backgroundColor').funct,
  431. null, 'geIcon geSprite geSprite-fontbackground');
  432. elt.setAttribute('title', mxResources.get('backgroundColor'));
  433. elt = menu.addItem('', null, mxUtils.bind(this, function()
  434. {
  435. document.execCommand('removeformat', false, null);
  436. }), null, 'geIcon geSprite geSprite-removeformat');
  437. elt.setAttribute('title', mxResources.get('removeFormat'));
  438. }));
  439. formatMenu.style.position = 'relative';
  440. formatMenu.style.whiteSpace = 'nowrap';
  441. formatMenu.style.overflow = 'hidden';
  442. formatMenu.innerHTML = '<div class="geSprite geSprite-dots" style="margin-left:-2px;"></div>' +
  443. this.dropdownImageHtml;
  444. formatMenu.style.width = (mxClient.IS_QUIRKS) ? '50px' : '30px';
  445. if (EditorUi.compactUi)
  446. {
  447. formatMenu.getElementsByTagName('img')[0].style.left = '22px';
  448. formatMenu.getElementsByTagName('img')[0].style.top = '5px';
  449. }
  450. this.addSeparator();
  451. this.addButton('geIcon geSprite geSprite-code', mxResources.get('html'), function()
  452. {
  453. graph.cellEditor.toggleViewMode();
  454. if (graph.cellEditor.textarea.innerHTML.length > 0 && (graph.cellEditor.textarea.innerHTML != '&nbsp;' || !graph.cellEditor.clearOnChange))
  455. {
  456. window.setTimeout(function()
  457. {
  458. document.execCommand('selectAll', false, null);
  459. });
  460. }
  461. });
  462. this.addSeparator();
  463. var insertMenu = this.addMenuFunction('', mxResources.get('insert'), true, mxUtils.bind(this, function(menu)
  464. {
  465. menu.addItem(mxResources.get('insertLink'), null, mxUtils.bind(this, function()
  466. {
  467. this.editorUi.actions.get('link').funct();
  468. }));
  469. menu.addItem(mxResources.get('insertImage'), null, mxUtils.bind(this, function()
  470. {
  471. this.editorUi.actions.get('image').funct();
  472. }));
  473. menu.addItem(mxResources.get('insertHorizontalRule'), null, mxUtils.bind(this, function()
  474. {
  475. document.execCommand('inserthorizontalrule', false, null);
  476. }));
  477. }));
  478. insertMenu.style.whiteSpace = 'nowrap';
  479. insertMenu.style.overflow = 'hidden';
  480. insertMenu.style.position = 'relative';
  481. insertMenu.innerHTML = '<div class="geSprite geSprite-plus" style="margin-left:-4px;margin-top:-3px;"></div>' +
  482. this.dropdownImageHtml;
  483. insertMenu.style.width = (mxClient.IS_QUIRKS) ? '36px' : '16px';
  484. // Fix for item size in kennedy theme
  485. if (EditorUi.compactUi)
  486. {
  487. insertMenu.getElementsByTagName('img')[0].style.left = '24px';
  488. insertMenu.getElementsByTagName('img')[0].style.top = '5px';
  489. insertMenu.style.width = (mxClient.IS_QUIRKS) ? '50px' : '30px';
  490. }
  491. this.addSeparator();
  492. // KNOWN: All table stuff does not work with undo/redo
  493. // KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
  494. // to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
  495. var elt = this.addMenuFunction('geIcon geSprite geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
  496. {
  497. var elt = graph.getSelectedElement();
  498. var cell = graph.getParentByNames(elt, ['TD', 'TH'], graph.cellEditor.text2);
  499. var row = graph.getParentByName(elt, 'TR', graph.cellEditor.text2);
  500. if (row == null)
  501. {
  502. function createTable(rows, cols)
  503. {
  504. var html = ['<table>'];
  505. for (var i = 0; i < rows; i++)
  506. {
  507. html.push('<tr>');
  508. for (var j = 0; j < cols; j++)
  509. {
  510. html.push('<td><br></td>');
  511. }
  512. html.push('</tr>');
  513. }
  514. html.push('</table>');
  515. return html.join('');
  516. };
  517. this.editorUi.menus.addInsertTableItem(menu);
  518. }
  519. else
  520. {
  521. var table = graph.getParentByName(row, 'TABLE', graph.cellEditor.text2);
  522. elt = menu.addItem('', null, mxUtils.bind(this, function()
  523. {
  524. try
  525. {
  526. graph.selectNode(graph.insertColumn(table, (cell != null) ? cell.cellIndex : 0));
  527. }
  528. catch (e)
  529. {
  530. this.editorUi.handleError(e);
  531. }
  532. }), null, 'geIcon geSprite geSprite-insertcolumnbefore');
  533. elt.setAttribute('title', mxResources.get('insertColumnBefore'));
  534. elt = menu.addItem('', null, mxUtils.bind(this, function()
  535. {
  536. try
  537. {
  538. graph.selectNode(graph.insertColumn(table, (cell != null) ? cell.cellIndex + 1 : -1));
  539. }
  540. catch (e)
  541. {
  542. this.editorUi.handleError(e);
  543. }
  544. }), null, 'geIcon geSprite geSprite-insertcolumnafter');
  545. elt.setAttribute('title', mxResources.get('insertColumnAfter'));
  546. elt = menu.addItem('Delete column', null, mxUtils.bind(this, function()
  547. {
  548. if (cell != null)
  549. {
  550. try
  551. {
  552. graph.deleteColumn(table, cell.cellIndex);
  553. }
  554. catch (e)
  555. {
  556. this.editorUi.handleError(e);
  557. }
  558. }
  559. }), null, 'geIcon geSprite geSprite-deletecolumn');
  560. elt.setAttribute('title', mxResources.get('deleteColumn'));
  561. elt = menu.addItem('', null, mxUtils.bind(this, function()
  562. {
  563. try
  564. {
  565. graph.selectNode(graph.insertRow(table, row.sectionRowIndex));
  566. }
  567. catch (e)
  568. {
  569. this.editorUi.handleError(e);
  570. }
  571. }), null, 'geIcon geSprite geSprite-insertrowbefore');
  572. elt.setAttribute('title', mxResources.get('insertRowBefore'));
  573. elt = menu.addItem('', null, mxUtils.bind(this, function()
  574. {
  575. try
  576. {
  577. graph.selectNode(graph.insertRow(table, row.sectionRowIndex + 1));
  578. }
  579. catch (e)
  580. {
  581. this.editorUi.handleError(e);
  582. }
  583. }), null, 'geIcon geSprite geSprite-insertrowafter');
  584. elt.setAttribute('title', mxResources.get('insertRowAfter'));
  585. elt = menu.addItem('', null, mxUtils.bind(this, function()
  586. {
  587. try
  588. {
  589. graph.deleteRow(table, row.sectionRowIndex);
  590. }
  591. catch (e)
  592. {
  593. this.editorUi.handleError(e);
  594. }
  595. }), null, 'geIcon geSprite geSprite-deleterow');
  596. elt.setAttribute('title', mxResources.get('deleteRow'));
  597. elt = menu.addItem('', null, mxUtils.bind(this, function()
  598. {
  599. // Converts rgb(r,g,b) values
  600. var color = table.style.borderColor.replace(
  601. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  602. function($0, $1, $2, $3) {
  603. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  604. });
  605. this.editorUi.pickColor(color, function(newColor)
  606. {
  607. if (newColor == null || newColor == mxConstants.NONE)
  608. {
  609. table.removeAttribute('border');
  610. table.style.border = '';
  611. table.style.borderCollapse = '';
  612. }
  613. else
  614. {
  615. table.setAttribute('border', '1');
  616. table.style.border = '1px solid ' + newColor;
  617. table.style.borderCollapse = 'collapse';
  618. }
  619. });
  620. }), null, 'geIcon geSprite geSprite-strokecolor');
  621. elt.setAttribute('title', mxResources.get('borderColor'));
  622. elt = menu.addItem('', null, mxUtils.bind(this, function()
  623. {
  624. // Converts rgb(r,g,b) values
  625. var color = table.style.backgroundColor.replace(
  626. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  627. function($0, $1, $2, $3) {
  628. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  629. });
  630. this.editorUi.pickColor(color, function(newColor)
  631. {
  632. if (newColor == null || newColor == mxConstants.NONE)
  633. {
  634. table.style.backgroundColor = '';
  635. }
  636. else
  637. {
  638. table.style.backgroundColor = newColor;
  639. }
  640. });
  641. }), null, 'geIcon geSprite geSprite-fillcolor');
  642. elt.setAttribute('title', mxResources.get('backgroundColor'));
  643. elt = menu.addItem('', null, mxUtils.bind(this, function()
  644. {
  645. var value = table.getAttribute('cellPadding') || 0;
  646. var dlg = new FilenameDialog(this.editorUi, value, mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  647. {
  648. if (newValue != null && newValue.length > 0)
  649. {
  650. table.setAttribute('cellPadding', newValue);
  651. }
  652. else
  653. {
  654. table.removeAttribute('cellPadding');
  655. }
  656. }), mxResources.get('spacing'));
  657. this.editorUi.showDialog(dlg.container, 300, 80, true, true);
  658. dlg.init();
  659. }), null, 'geIcon geSprite geSprite-fit');
  660. elt.setAttribute('title', mxResources.get('spacing'));
  661. elt = menu.addItem('', null, mxUtils.bind(this, function()
  662. {
  663. table.setAttribute('align', 'left');
  664. }), null, 'geIcon geSprite geSprite-left');
  665. elt.setAttribute('title', mxResources.get('left'));
  666. elt = menu.addItem('', null, mxUtils.bind(this, function()
  667. {
  668. table.setAttribute('align', 'center');
  669. }), null, 'geIcon geSprite geSprite-center');
  670. elt.setAttribute('title', mxResources.get('center'));
  671. elt = menu.addItem('', null, mxUtils.bind(this, function()
  672. {
  673. table.setAttribute('align', 'right');
  674. }), null, 'geIcon geSprite geSprite-right');
  675. elt.setAttribute('title', mxResources.get('right'));
  676. }
  677. }));
  678. elt.style.position = 'relative';
  679. elt.style.whiteSpace = 'nowrap';
  680. elt.style.overflow = 'hidden';
  681. elt.innerHTML = '<div class="geSprite geSprite-table" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
  682. elt.style.width = (mxClient.IS_QUIRKS) ? '50px' : '30px';
  683. // Fix for item size in kennedy theme
  684. if (EditorUi.compactUi)
  685. {
  686. elt.getElementsByTagName('img')[0].style.left = '22px';
  687. elt.getElementsByTagName('img')[0].style.top = '5px';
  688. }
  689. };
  690. /**
  691. * Hides the current menu.
  692. */
  693. Toolbar.prototype.hideMenu = function()
  694. {
  695. this.editorUi.hideCurrentMenu();
  696. };
  697. /**
  698. * Adds a label to the toolbar.
  699. */
  700. Toolbar.prototype.addMenu = function(label, tooltip, showLabels, name, c, showAll, ignoreState)
  701. {
  702. var menu = this.editorUi.menus.get(name);
  703. var elt = this.addMenuFunction(label, tooltip, showLabels, function()
  704. {
  705. menu.funct.apply(menu, arguments);
  706. }, c, showAll);
  707. // Workaround for possible not a function
  708. // when extending HTML objects
  709. if (!ignoreState && typeof elt.setEnabled === 'function')
  710. {
  711. menu.addListener('stateChanged', function()
  712. {
  713. elt.setEnabled(menu.enabled);
  714. });
  715. }
  716. return elt;
  717. };
  718. /**
  719. * Adds a label to the toolbar.
  720. */
  721. Toolbar.prototype.addMenuFunction = function(label, tooltip, showLabels, funct, c, showAll)
  722. {
  723. return this.addMenuFunctionInContainer((c != null) ? c : this.container, label, tooltip, showLabels, funct, showAll);
  724. };
  725. /**
  726. * Adds a label to the toolbar.
  727. */
  728. Toolbar.prototype.addMenuFunctionInContainer = function(container, label, tooltip, showLabels, funct, showAll)
  729. {
  730. var elt = (showLabels) ? this.createLabel(label) : this.createButton(label);
  731. this.initElement(elt, tooltip);
  732. this.addMenuHandler(elt, showLabels, funct, showAll);
  733. container.appendChild(elt);
  734. return elt;
  735. };
  736. /**
  737. * Adds a separator to the separator.
  738. */
  739. Toolbar.prototype.addSeparator = function(c)
  740. {
  741. c = (c != null) ? c : this.container;
  742. var elt = document.createElement('div');
  743. elt.className = 'geSeparator';
  744. c.appendChild(elt);
  745. return elt;
  746. };
  747. /**
  748. * Adds given action item
  749. */
  750. Toolbar.prototype.addItems = function(keys, c, ignoreDisabled)
  751. {
  752. var items = [];
  753. for (var i = 0; i < keys.length; i++)
  754. {
  755. var key = keys[i];
  756. if (key == '-')
  757. {
  758. items.push(this.addSeparator(c));
  759. }
  760. else
  761. {
  762. items.push(this.addItem('geSprite-' + key.toLowerCase(), key, c, ignoreDisabled));
  763. }
  764. }
  765. return items;
  766. };
  767. /**
  768. * Adds given action item
  769. */
  770. Toolbar.prototype.addItem = function(sprite, key, c, ignoreDisabled)
  771. {
  772. var action = this.editorUi.actions.get(key);
  773. var elt = null;
  774. if (action != null)
  775. {
  776. var tooltip = action.label;
  777. if (action.shortcut != null)
  778. {
  779. tooltip += ' (' + action.shortcut + ')';
  780. }
  781. elt = this.addButton(sprite, tooltip, action.funct, c);
  782. // Workaround for possible not a function
  783. // when extending HTML objects
  784. if (!ignoreDisabled && typeof elt.setEnabled === 'function')
  785. {
  786. elt.setEnabled(action.enabled);
  787. action.addListener('stateChanged', function()
  788. {
  789. elt.setEnabled(action.enabled);
  790. });
  791. }
  792. }
  793. return elt;
  794. };
  795. /**
  796. * Adds a button to the toolbar.
  797. */
  798. Toolbar.prototype.addButton = function(classname, tooltip, funct, c)
  799. {
  800. var elt = this.createButton(classname);
  801. c = (c != null) ? c : this.container;
  802. this.initElement(elt, tooltip);
  803. this.addClickHandler(elt, funct);
  804. c.appendChild(elt);
  805. return elt;
  806. };
  807. /**
  808. * Initializes the given toolbar element.
  809. */
  810. Toolbar.prototype.initElement = function(elt, tooltip)
  811. {
  812. // Adds tooltip
  813. if (tooltip != null)
  814. {
  815. elt.setAttribute('title', tooltip);
  816. }
  817. this.addEnabledState(elt);
  818. };
  819. /**
  820. * Adds enabled state with setter to DOM node (avoids JS wrapper).
  821. */
  822. Toolbar.prototype.addEnabledState = function(elt)
  823. {
  824. var classname = elt.className;
  825. elt.setEnabled = function(value)
  826. {
  827. elt.enabled = value;
  828. if (value)
  829. {
  830. elt.className = classname;
  831. }
  832. else
  833. {
  834. elt.className = classname + ' mxDisabled';
  835. }
  836. };
  837. elt.setEnabled(true);
  838. };
  839. /**
  840. * Adds enabled state with setter to DOM node (avoids JS wrapper).
  841. */
  842. Toolbar.prototype.addClickHandler = function(elt, funct)
  843. {
  844. if (funct != null)
  845. {
  846. mxEvent.addListener(elt, 'click', function(evt)
  847. {
  848. if (elt.enabled)
  849. {
  850. funct(evt);
  851. }
  852. mxEvent.consume(evt);
  853. });
  854. // Prevents focus
  855. mxEvent.addListener(elt, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  856. mxUtils.bind(this, function(evt)
  857. {
  858. evt.preventDefault();
  859. }));
  860. }
  861. };
  862. /**
  863. * Creates and returns a new button.
  864. */
  865. Toolbar.prototype.createButton = function(classname)
  866. {
  867. var elt = document.createElement('a');
  868. elt.className = 'geButton';
  869. var inner = document.createElement('div');
  870. if (classname != null)
  871. {
  872. inner.className = 'geSprite ' + classname;
  873. }
  874. elt.appendChild(inner);
  875. return elt;
  876. };
  877. /**
  878. * Creates and returns a new button.
  879. */
  880. Toolbar.prototype.createLabel = function(label, tooltip)
  881. {
  882. var elt = document.createElement('a');
  883. elt.className = 'geLabel';
  884. mxUtils.write(elt, label);
  885. return elt;
  886. };
  887. /**
  888. * Adds a handler for showing a menu in the given element.
  889. */
  890. Toolbar.prototype.addMenuHandler = function(elt, showLabels, funct, showAll)
  891. {
  892. if (funct != null)
  893. {
  894. var graph = this.editorUi.editor.graph;
  895. var menu = null;
  896. var show = true;
  897. mxEvent.addListener(elt, 'click', mxUtils.bind(this, function(evt)
  898. {
  899. if (show && (elt.enabled == null || elt.enabled))
  900. {
  901. graph.popupMenuHandler.hideMenu();
  902. menu = new mxPopupMenu(funct);
  903. menu.div.className += ' geToolbarMenu';
  904. menu.showDisabled = showAll;
  905. menu.labels = showLabels;
  906. menu.autoExpand = true;
  907. var offset = mxUtils.getOffset(elt);
  908. menu.popup(offset.x, offset.y + elt.offsetHeight, null, evt);
  909. this.editorUi.setCurrentMenu(menu, elt);
  910. // Workaround for scrollbar hiding menu items
  911. if (!showLabels && menu.div.scrollHeight > menu.div.clientHeight)
  912. {
  913. menu.div.style.width = '40px';
  914. }
  915. menu.hideMenu = mxUtils.bind(this, function()
  916. {
  917. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  918. this.editorUi.resetCurrentMenu();
  919. menu.destroy();
  920. });
  921. // Extends destroy to reset global state
  922. menu.addListener(mxEvent.EVENT_HIDE, mxUtils.bind(this, function()
  923. {
  924. this.currentElt = null;
  925. }));
  926. }
  927. show = true;
  928. mxEvent.consume(evt);
  929. }));
  930. // Hides menu if already showing and prevents focus
  931. mxEvent.addListener(elt, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  932. mxUtils.bind(this, function(evt)
  933. {
  934. show = this.currentElt != elt;
  935. evt.preventDefault();
  936. }));
  937. }
  938. };
  939. /**
  940. * Adds a handler for showing a menu in the given element.
  941. */
  942. Toolbar.prototype.destroy = function()
  943. {
  944. if (this.gestureHandler != null)
  945. {
  946. mxEvent.removeGestureListeners(document, this.gestureHandler);
  947. this.gestureHandler = null;
  948. }
  949. };