maxGraph/examples/grapheditor/www/js/Toolbar.js

1102 lines
35 KiB
JavaScript
Raw Normal View History

2012-05-21 20:32:26 +00:00
/**
* Copyright (c) 2006-2012, JGraph Ltd
*/
/**
* Construcs a new toolbar for the given editor.
*/
function Toolbar(editorUi, container)
{
this.editorUi = editorUi;
this.container = container;
2015-08-28 13:41:48 +00:00
this.staticElements = [];
2012-05-21 20:32:26 +00:00
this.init();
// Global handler to hide the current menu
2015-08-28 13:41:48 +00:00
this.gestureHandler = mxUtils.bind(this, function(evt)
2012-05-21 20:32:26 +00:00
{
2016-01-06 10:57:28 +00:00
if (this.editorUi.currentMenu != null && mxEvent.getSource(evt) != this.editorUi.currentMenu.div)
{
this.hideMenu();
}
2015-08-28 13:41:48 +00:00
});
mxEvent.addGestureListeners(document, this.gestureHandler);
2012-05-21 20:32:26 +00:00
};
2015-08-28 13:41:48 +00:00
/**
* Image for the dropdown arrow.
*/
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';
/**
* Image element for the dropdown arrow.
*/
Toolbar.prototype.dropdownImageHtml = '<img border="0" style="position:absolute;right:4px;top:' +
((!EditorUi.compactUi) ? 8 : 6) + 'px;" src="' + Toolbar.prototype.dropdownImage + '" valign="middle"/>';
2014-07-25 06:48:01 +00:00
/**
* Defines the background for selected buttons.
*/
Toolbar.prototype.selectedBackground = '#d0d0d0';
/**
* Defines the background for selected buttons.
*/
Toolbar.prototype.unselectedBackground = 'none';
2015-08-28 13:41:48 +00:00
/**
* Array that contains the DOM nodes that should never be removed.
*/
Toolbar.prototype.staticElements = null;
2012-05-21 20:32:26 +00:00
/**
* Adds the toolbar elements.
*/
Toolbar.prototype.init = function()
{
2016-04-06 08:10:17 +00:00
var sw = screen.width;
// Takes into account initial compact mode
sw -= (screen.height > 740) ? 56 : 0;
if (sw >= 700)
{
var formatMenu = this.addMenu('', mxResources.get('view') + ' (' + mxResources.get('panTooltip') + ')', true, 'viewPanels', null, true);
this.addDropDownArrow(formatMenu, 'geSprite-formatpanel', 38, 50, -4, -3, 36, -8);
this.addSeparator();
}
2015-08-28 13:41:48 +00:00
var viewMenu = this.addMenu('', mxResources.get('zoom') + ' (Alt+Mousewheel)', true, 'viewZoom', null, true);
viewMenu.showDisabled = true;
viewMenu.style.whiteSpace = 'nowrap';
viewMenu.style.position = 'relative';
viewMenu.style.overflow = 'hidden';
if (EditorUi.compactUi)
{
2021-03-20 04:32:46 +00:00
viewMenu.style.width = '50px';
2015-08-28 13:41:48 +00:00
}
else
{
2021-03-20 04:32:46 +00:00
viewMenu.style.width = '36px';
2015-08-28 13:41:48 +00:00
}
2016-04-06 08:10:17 +00:00
if (sw >= 420)
{
this.addSeparator();
var elts = this.addItems(['zoomIn', 'zoomOut']);
elts[0].setAttribute('title', mxResources.get('zoomIn') + ' (' + this.editorUi.actions.get('zoomIn').shortcut + ')');
elts[1].setAttribute('title', mxResources.get('zoomOut') + ' (' + this.editorUi.actions.get('zoomOut').shortcut + ')');
}
2015-08-28 13:41:48 +00:00
// Updates the label if the scale changes
2017-01-16 08:36:34 +00:00
this.updateZoom = mxUtils.bind(this, function()
2012-06-14 12:43:20 +00:00
{
2015-08-28 13:41:48 +00:00
viewMenu.innerHTML = Math.round(this.editorUi.editor.graph.view.scale * 100) + '%' +
this.dropdownImageHtml;
if (EditorUi.compactUi)
{
viewMenu.getElementsByTagName('img')[0].style.right = '1px';
viewMenu.getElementsByTagName('img')[0].style.top = '5px';
}
2015-10-01 10:34:51 +00:00
});
2016-04-06 08:10:17 +00:00
2017-01-16 08:36:34 +00:00
this.editorUi.editor.graph.view.addListener(mxEvent.EVENT_SCALE, this.updateZoom);
this.editorUi.editor.addListener('resetGraphView', this.updateZoom);
2015-08-28 13:41:48 +00:00
2016-04-06 08:10:17 +00:00
var elts = this.addItems(['-', 'undo', 'redo']);
2015-08-28 13:41:48 +00:00
elts[1].setAttribute('title', mxResources.get('undo') + ' (' + this.editorUi.actions.get('undo').shortcut + ')');
elts[2].setAttribute('title', mxResources.get('redo') + ' (' + this.editorUi.actions.get('redo').shortcut + ')');
2016-04-06 08:10:17 +00:00
2017-06-27 11:43:19 +00:00
if (sw >= 320)
2014-10-09 13:52:12 +00:00
{
2016-04-06 08:10:17 +00:00
var elts = this.addItems(['-', 'delete']);
elts[1].setAttribute('title', mxResources.get('delete') + ' (' + this.editorUi.actions.get('delete').shortcut + ')');
}
2015-08-28 13:41:48 +00:00
2016-04-06 08:10:17 +00:00
if (sw >= 550)
{
this.addItems(['-', 'toFront', 'toBack']);
}
2015-08-28 13:41:48 +00:00
2017-06-27 11:43:19 +00:00
if (sw >= 740)
2016-04-06 08:10:17 +00:00
{
2017-06-27 11:43:19 +00:00
this.addItems(['-', 'fillColor']);
if (sw >= 780)
{
this.addItems(['strokeColor']);
if (sw >= 820)
{
this.addItems(['shadow']);
}
}
2016-04-06 08:10:17 +00:00
}
2017-06-27 11:43:19 +00:00
if (sw >= 400)
2012-06-14 12:43:20 +00:00
{
2016-04-06 08:10:17 +00:00
this.addSeparator();
2017-06-27 11:43:19 +00:00
if (sw >= 440)
2016-04-06 08:10:17 +00:00
{
2017-06-27 11:43:19 +00:00
this.edgeShapeMenu = this.addMenuFunction('', mxResources.get('connection'), false, mxUtils.bind(this, function(menu)
{
this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], [null, null], 'geIcon geSprite geSprite-connection', null, true).setAttribute('title', mxResources.get('line'));
this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['link', null], 'geIcon geSprite geSprite-linkedge', null, true).setAttribute('title', mxResources.get('link'));
this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['flexArrow', null], 'geIcon geSprite geSprite-arrow', null, true).setAttribute('title', mxResources.get('arrow'));
this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_SHAPE, 'width'], ['arrow', null], 'geIcon geSprite geSprite-simplearrow', null, true).setAttribute('title', mxResources.get('simpleArrow'));
}));
2015-03-05 09:43:42 +00:00
2017-06-27 11:43:19 +00:00
this.addDropDownArrow(this.edgeShapeMenu, 'geSprite-connection', 44, 50, 0, 0, 22, -4);
}
2014-07-25 06:48:01 +00:00
2016-04-06 08:10:17 +00:00
this.edgeStyleMenu = this.addMenuFunction('geSprite-orthogonal', mxResources.get('waypoints'), false, mxUtils.bind(this, function(menu)
{
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'));
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'));
2017-01-16 08:36:34 +00:00
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'));
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'));
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'));
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'));
2016-04-06 08:10:17 +00:00
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'));
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'));
}));
this.addDropDownArrow(this.edgeStyleMenu, 'geSprite-orthogonal', 44, 50, 0, 0, 22, -4);
}
2015-08-28 13:41:48 +00:00
this.addSeparator();
var insertMenu = this.addMenu('', mxResources.get('insert') + ' (' + mxResources.get('doubleClickTooltip') + ')', true, 'insert', null, true);
this.addDropDownArrow(insertMenu, 'geSprite-plus', 38, 48, -4, -3, 36, -8);
2020-06-19 12:31:34 +00:00
this.addTableDropDown();
};
/**
* Adds the toolbar elements.
*/
Toolbar.prototype.addTableDropDown = function()
{
this.addSeparator();
2020-03-31 14:07:32 +00:00
2020-06-19 12:31:34 +00:00
// KNOWN: All table stuff does not work with undo/redo
// KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
// to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
2020-10-28 14:58:34 +00:00
var menuElt = this.addMenuFunction('geIcon geSprite geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
var graph = this.editorUi.editor.graph;
var cell = graph.getSelectionCell();
if (!graph.isTableCell(cell) && !graph.isTableRow(cell) && !graph.isTable(cell))
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
this.editorUi.menus.addInsertTableCellItem(menu);
}
else
{
2020-10-28 14:58:34 +00:00
var elt = menu.addItem('', null, mxUtils.bind(this, function()
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
try
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
graph.insertTableColumn(cell, true);
}
catch (e)
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
this.editorUi.handleError(e);
}
}), null, 'geIcon geSprite geSprite-insertcolumnbefore');
elt.setAttribute('title', mxResources.get('insertColumnBefore'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
try
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
graph.insertTableColumn(cell, false);
}
catch (e)
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
this.editorUi.handleError(e);
}
}), null, 'geIcon geSprite geSprite-insertcolumnafter');
elt.setAttribute('title', mxResources.get('insertColumnAfter'));
elt = menu.addItem('Delete column', null, mxUtils.bind(this, function()
{
if (cell != null)
2020-03-31 14:07:32 +00:00
{
try
{
2020-06-19 12:31:34 +00:00
graph.deleteTableColumn(cell);
2020-03-31 14:07:32 +00:00
}
catch (e)
{
this.editorUi.handleError(e);
}
2020-06-19 12:31:34 +00:00
}
}), null, 'geIcon geSprite geSprite-deletecolumn');
elt.setAttribute('title', mxResources.get('deleteColumn'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
try
2020-03-31 14:07:32 +00:00
{
2020-06-19 12:31:34 +00:00
graph.insertTableRow(cell, true);
}
catch (e)
{
this.editorUi.handleError(e);
}
}), null, 'geIcon geSprite geSprite-insertrowbefore');
elt.setAttribute('title', mxResources.get('insertRowBefore'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
try
{
graph.insertTableRow(cell, false);
}
catch (e)
{
this.editorUi.handleError(e);
}
}), null, 'geIcon geSprite geSprite-insertrowafter');
elt.setAttribute('title', mxResources.get('insertRowAfter'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
try
{
graph.deleteTableRow(cell);
}
catch (e)
{
this.editorUi.handleError(e);
}
}), null, 'geIcon geSprite geSprite-deleterow');
elt.setAttribute('title', mxResources.get('deleteRow'));
}
}));
2020-03-31 14:07:32 +00:00
2020-10-28 14:58:34 +00:00
menuElt.style.position = 'relative';
menuElt.style.whiteSpace = 'nowrap';
menuElt.style.overflow = 'hidden';
menuElt.innerHTML = '<div class="geSprite geSprite-table" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
menuElt.style.width = '30px';
2020-06-19 12:31:34 +00:00
// Fix for item size in kennedy theme
if (EditorUi.compactUi)
{
2020-10-28 14:58:34 +00:00
menuElt.getElementsByTagName('img')[0].style.left = '22px';
menuElt.getElementsByTagName('img')[0].style.top = '5px';
2020-06-19 12:31:34 +00:00
}
// Connects to insert menu enabled state
var menu = this.editorUi.menus.get('insert');
2020-10-28 14:58:34 +00:00
// Workaround for possible not a function
// when extending HTML objects
if (menu != null && typeof menuElt.setEnabled === 'function')
2020-06-19 12:31:34 +00:00
{
menu.addListener('stateChanged', function()
2020-03-31 14:07:32 +00:00
{
2020-10-28 14:58:34 +00:00
menuElt.setEnabled(menu.enabled);
2020-06-19 12:31:34 +00:00
});
2020-03-31 14:07:32 +00:00
}
2020-06-19 12:31:34 +00:00
2020-10-28 14:58:34 +00:00
return menuElt;
2015-08-28 13:41:48 +00:00
};
/**
* Adds the toolbar elements.
*/
Toolbar.prototype.addDropDownArrow = function(menu, sprite, width, atlasWidth, left, top, atlasDelta, atlasLeft)
{
atlasDelta = (atlasDelta != null) ? atlasDelta : 32;
left = (EditorUi.compactUi) ? left : atlasLeft;
2014-05-05 08:30:00 +00:00
2015-08-28 13:41:48 +00:00
menu.style.whiteSpace = 'nowrap';
menu.style.overflow = 'hidden';
menu.style.position = 'relative';
menu.innerHTML = '<div class="geSprite ' + sprite + '" style="margin-left:' + left + 'px;margin-top:' + top + 'px;"></div>' +
this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
menu.style.width = (atlasWidth - atlasDelta) + 'px';
2015-08-28 13:41:48 +00:00
// Fix for item size in kennedy theme
if (EditorUi.compactUi)
2015-01-05 14:01:01 +00:00
{
2015-08-28 13:41:48 +00:00
menu.getElementsByTagName('img')[0].style.left = '24px';
menu.getElementsByTagName('img')[0].style.top = '5px';
2021-03-20 04:32:46 +00:00
menu.style.width = (width - 10) + 'px';
2015-01-05 14:01:01 +00:00
}
2015-08-28 13:41:48 +00:00
};
2015-01-05 14:01:01 +00:00
2015-08-28 13:41:48 +00:00
/**
* Sets the current font name.
*/
Toolbar.prototype.setFontName = function(value)
{
if (this.fontMenu != null)
2014-05-05 08:30:00 +00:00
{
2015-08-28 13:41:48 +00:00
this.fontMenu.innerHTML = '<div style="width:60px;overflow:hidden;display:inline-block;">' +
mxUtils.htmlEntities(value) + '</div>' + this.dropdownImageHtml;
}
};
2015-01-05 14:01:01 +00:00
2015-08-28 13:41:48 +00:00
/**
* Sets the current font name.
*/
Toolbar.prototype.setFontSize = function(value)
{
if (this.sizeMenu != null)
2015-01-05 14:01:01 +00:00
{
2015-08-28 13:41:48 +00:00
this.sizeMenu.innerHTML = '<div style="width:24px;overflow:hidden;display:inline-block;">' +
2020-10-28 14:58:34 +00:00
mxUtils.htmlEntities(value) + '</div>' + this.dropdownImageHtml;
2015-01-05 14:01:01 +00:00
}
2012-05-21 20:32:26 +00:00
};
2014-01-08 16:23:20 +00:00
/**
* Hides the current menu.
*/
Toolbar.prototype.createTextToolbar = function()
{
var graph = this.editorUi.editor.graph;
2015-08-28 13:41:48 +00:00
var styleElt = this.addMenu('', mxResources.get('style'), true, 'formatBlock');
styleElt.style.position = 'relative';
styleElt.style.whiteSpace = 'nowrap';
styleElt.style.overflow = 'hidden';
styleElt.innerHTML = mxResources.get('style') + this.dropdownImageHtml;
if (EditorUi.compactUi)
{
styleElt.style.paddingRight = '18px';
styleElt.getElementsByTagName('img')[0].style.right = '1px';
styleElt.getElementsByTagName('img')[0].style.top = '5px';
}
this.addSeparator();
this.fontMenu = this.addMenu('', mxResources.get('fontFamily'), true, 'fontFamily');
this.fontMenu.style.position = 'relative';
this.fontMenu.style.whiteSpace = 'nowrap';
this.fontMenu.style.overflow = 'hidden';
2021-03-20 04:32:46 +00:00
this.fontMenu.style.width = '60px';
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
this.setFontName(Menus.prototype.defaultFont);
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
if (EditorUi.compactUi)
{
this.fontMenu.style.paddingRight = '18px';
this.fontMenu.getElementsByTagName('img')[0].style.right = '1px';
this.fontMenu.getElementsByTagName('img')[0].style.top = '5px';
}
2014-01-08 16:23:20 +00:00
this.addSeparator();
2015-08-28 13:41:48 +00:00
this.sizeMenu = this.addMenu(Menus.prototype.defaultFontSize, mxResources.get('fontSize'), true, 'fontSize');
this.sizeMenu.style.position = 'relative';
this.sizeMenu.style.whiteSpace = 'nowrap';
this.sizeMenu.style.overflow = 'hidden';
2021-03-20 04:32:46 +00:00
this.sizeMenu.style.width = '24px';
2015-08-28 13:41:48 +00:00
this.setFontSize(Menus.prototype.defaultFontSize);
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
if (EditorUi.compactUi)
{
this.sizeMenu.style.paddingRight = '18px';
this.sizeMenu.getElementsByTagName('img')[0].style.right = '1px';
this.sizeMenu.getElementsByTagName('img')[0].style.top = '5px';
}
var elts = this.addItems(['-', 'undo', 'redo','-', 'bold', 'italic', 'underline']);
elts[1].setAttribute('title', mxResources.get('undo') + ' (' + this.editorUi.actions.get('undo').shortcut + ')');
elts[2].setAttribute('title', mxResources.get('redo') + ' (' + this.editorUi.actions.get('redo').shortcut + ')');
elts[4].setAttribute('title', mxResources.get('bold') + ' (' + this.editorUi.actions.get('bold').shortcut + ')');
elts[5].setAttribute('title', mxResources.get('italic') + ' (' + this.editorUi.actions.get('italic').shortcut + ')');
elts[6].setAttribute('title', mxResources.get('underline') + ' (' + this.editorUi.actions.get('underline').shortcut + ')');
2014-01-08 16:23:20 +00:00
// KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
// to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
2015-08-28 13:41:48 +00:00
var alignMenu = this.addMenuFunction('', mxResources.get('align'), false, mxUtils.bind(this, function(menu)
2014-01-08 16:23:20 +00:00
{
2019-07-15 10:46:53 +00:00
elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
2015-08-28 13:41:48 +00:00
{
2019-07-15 10:46:53 +00:00
graph.cellEditor.alignText(mxConstants.ALIGN_LEFT, evt);
2015-08-28 13:41:48 +00:00
}), null, 'geIcon geSprite geSprite-left');
elt.setAttribute('title', mxResources.get('left'));
2014-01-08 16:23:20 +00:00
2019-07-15 10:46:53 +00:00
elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
2015-08-28 13:41:48 +00:00
{
2019-07-15 10:46:53 +00:00
graph.cellEditor.alignText(mxConstants.ALIGN_CENTER, evt);
2015-08-28 13:41:48 +00:00
}), null, 'geIcon geSprite geSprite-center');
elt.setAttribute('title', mxResources.get('center'));
2019-07-15 10:46:53 +00:00
elt = menu.addItem('', null, mxUtils.bind(this, function(evt)
2015-08-28 13:41:48 +00:00
{
2019-07-15 10:46:53 +00:00
graph.cellEditor.alignText(mxConstants.ALIGN_RIGHT, evt);
2015-08-28 13:41:48 +00:00
}), null, 'geIcon geSprite geSprite-right');
elt.setAttribute('title', mxResources.get('right'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('justifyfull', false, null);
}), null, 'geIcon geSprite geSprite-justifyfull');
elt.setAttribute('title', mxResources.get('justifyfull'));
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('insertorderedlist', false, null);
}), null, 'geIcon geSprite geSprite-orderedlist');
elt.setAttribute('title', mxResources.get('numberedList'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('insertunorderedlist', false, null);
}), null, 'geIcon geSprite geSprite-unorderedlist');
elt.setAttribute('title', mxResources.get('bulletedList'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('outdent', false, null);
}), null, 'geIcon geSprite geSprite-outdent');
elt.setAttribute('title', mxResources.get('decreaseIndent'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('indent', false, null);
}), null, 'geIcon geSprite geSprite-indent');
elt.setAttribute('title', mxResources.get('increaseIndent'));
}));
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
alignMenu.style.position = 'relative';
alignMenu.style.whiteSpace = 'nowrap';
alignMenu.style.overflow = 'hidden';
alignMenu.innerHTML = '<div class="geSprite geSprite-left" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
alignMenu.style.width = '30px';
2015-08-28 13:41:48 +00:00
if (EditorUi.compactUi)
{
alignMenu.getElementsByTagName('img')[0].style.left = '22px';
alignMenu.getElementsByTagName('img')[0].style.top = '5px';
}
var formatMenu = this.addMenuFunction('', mxResources.get('format'), false, mxUtils.bind(this, function(menu)
{
2016-09-07 12:29:15 +00:00
elt = menu.addItem('', null, this.editorUi.actions.get('subscript').funct,
null, 'geIcon geSprite geSprite-subscript');
2017-08-28 09:54:36 +00:00
elt.setAttribute('title', mxResources.get('subscript') + ' (' + Editor.ctrlKey + '+,)');
2016-09-07 12:29:15 +00:00
elt = menu.addItem('', null, this.editorUi.actions.get('superscript').funct,
null, 'geIcon geSprite geSprite-superscript');
2017-08-28 09:54:36 +00:00
elt.setAttribute('title', mxResources.get('superscript') + ' (' + Editor.ctrlKey + '+.)');
2015-08-28 13:41:48 +00:00
// KNOWN: IE+FF don't return keyboard focus after color dialog (calling focus doesn't help)
2016-09-07 12:29:15 +00:00
elt = menu.addItem('', null, this.editorUi.actions.get('fontColor').funct,
null, 'geIcon geSprite geSprite-fontcolor');
2015-08-28 13:41:48 +00:00
elt.setAttribute('title', mxResources.get('fontColor'));
2016-09-07 12:29:15 +00:00
elt = menu.addItem('', null, this.editorUi.actions.get('backgroundColor').funct,
null, 'geIcon geSprite geSprite-fontbackground');
2015-08-28 13:41:48 +00:00
elt.setAttribute('title', mxResources.get('backgroundColor'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
document.execCommand('removeformat', false, null);
}), null, 'geIcon geSprite geSprite-removeformat');
elt.setAttribute('title', mxResources.get('removeFormat'));
2014-01-08 16:23:20 +00:00
}));
2015-08-28 13:41:48 +00:00
formatMenu.style.position = 'relative';
formatMenu.style.whiteSpace = 'nowrap';
formatMenu.style.overflow = 'hidden';
2016-09-07 12:29:15 +00:00
formatMenu.innerHTML = '<div class="geSprite geSprite-dots" style="margin-left:-2px;"></div>' +
this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
formatMenu.style.width = '30px';
2015-08-28 13:41:48 +00:00
if (EditorUi.compactUi)
{
formatMenu.getElementsByTagName('img')[0].style.left = '22px';
formatMenu.getElementsByTagName('img')[0].style.top = '5px';
}
2014-01-08 16:23:20 +00:00
this.addSeparator();
2015-08-28 13:41:48 +00:00
this.addButton('geIcon geSprite geSprite-code', mxResources.get('html'), function()
2014-01-08 16:23:20 +00:00
{
2015-08-28 13:41:48 +00:00
graph.cellEditor.toggleViewMode();
if (graph.cellEditor.textarea.innerHTML.length > 0 && (graph.cellEditor.textarea.innerHTML != '&nbsp;' || !graph.cellEditor.clearOnChange))
{
window.setTimeout(function()
{
document.execCommand('selectAll', false, null);
});
}
2014-01-08 16:23:20 +00:00
});
2015-08-28 13:41:48 +00:00
this.addSeparator();
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
var insertMenu = this.addMenuFunction('', mxResources.get('insert'), true, mxUtils.bind(this, function(menu)
2014-01-08 16:23:20 +00:00
{
2015-08-28 13:41:48 +00:00
menu.addItem(mxResources.get('insertLink'), null, mxUtils.bind(this, function()
{
this.editorUi.actions.get('link').funct();
}));
menu.addItem(mxResources.get('insertImage'), null, mxUtils.bind(this, function()
{
this.editorUi.actions.get('image').funct();
}));
menu.addItem(mxResources.get('insertHorizontalRule'), null, mxUtils.bind(this, function()
{
document.execCommand('inserthorizontalrule', false, null);
}));
}));
2014-01-08 16:23:20 +00:00
2015-08-28 13:41:48 +00:00
insertMenu.style.whiteSpace = 'nowrap';
insertMenu.style.overflow = 'hidden';
insertMenu.style.position = 'relative';
insertMenu.innerHTML = '<div class="geSprite geSprite-plus" style="margin-left:-4px;margin-top:-3px;"></div>' +
this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
insertMenu.style.width = '16px';
2015-08-28 13:41:48 +00:00
// Fix for item size in kennedy theme
if (EditorUi.compactUi)
2014-01-08 16:23:20 +00:00
{
2015-08-28 13:41:48 +00:00
insertMenu.getElementsByTagName('img')[0].style.left = '24px';
insertMenu.getElementsByTagName('img')[0].style.top = '5px';
2021-03-20 04:32:46 +00:00
insertMenu.style.width = '30px';
2015-08-28 13:41:48 +00:00
}
2014-01-08 16:23:20 +00:00
this.addSeparator();
2014-01-13 16:13:21 +00:00
// KNOWN: All table stuff does not work with undo/redo
// KNOWN: Lost focus after click on submenu with text (not icon) in quirks and IE8. This is because the TD seems
// to catch the focus on click in these browsers. NOTE: Workaround in mxPopupMenu for icon items (without text).
var elt = this.addMenuFunction('geIcon geSprite geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
{
2015-01-05 14:01:01 +00:00
var elt = graph.getSelectedElement();
2019-07-15 10:46:53 +00:00
var cell = graph.getParentByNames(elt, ['TD', 'TH'], graph.cellEditor.text2);
2015-01-05 14:01:01 +00:00
var row = graph.getParentByName(elt, 'TR', graph.cellEditor.text2);
2014-01-13 16:13:21 +00:00
if (row == null)
{
2020-03-31 14:07:32 +00:00
function createTable(rows, cols)
{
var html = ['<table>'];
for (var i = 0; i < rows; i++)
{
html.push('<tr>');
for (var j = 0; j < cols; j++)
{
html.push('<td><br></td>');
}
html.push('</tr>');
}
html.push('</table>');
return html.join('');
};
2015-01-05 14:01:01 +00:00
this.editorUi.menus.addInsertTableItem(menu);
2014-01-13 16:13:21 +00:00
}
else
{
2015-01-05 14:01:01 +00:00
var table = graph.getParentByName(row, 'TABLE', graph.cellEditor.text2);
2014-01-13 16:13:21 +00:00
2014-07-25 06:48:01 +00:00
elt = menu.addItem('', null, mxUtils.bind(this, function()
2014-01-13 16:13:21 +00:00
{
2015-08-28 13:41:48 +00:00
try
{
graph.selectNode(graph.insertColumn(table, (cell != null) ? cell.cellIndex : 0));
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}), null, 'geIcon geSprite geSprite-insertcolumnbefore');
elt.setAttribute('title', mxResources.get('insertColumnBefore'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
2015-08-28 13:41:48 +00:00
{
try
{
graph.selectNode(graph.insertColumn(table, (cell != null) ? cell.cellIndex + 1 : -1));
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}), null, 'geIcon geSprite geSprite-insertcolumnafter');
elt.setAttribute('title', mxResources.get('insertColumnAfter'));
elt = menu.addItem('Delete column', null, mxUtils.bind(this, function()
{
if (cell != null)
{
2015-08-28 13:41:48 +00:00
try
{
graph.deleteColumn(table, cell.cellIndex);
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}
}), null, 'geIcon geSprite geSprite-deletecolumn');
elt.setAttribute('title', mxResources.get('deleteColumn'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
2015-08-28 13:41:48 +00:00
try
{
graph.selectNode(graph.insertRow(table, row.sectionRowIndex));
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}), null, 'geIcon geSprite geSprite-insertrowbefore');
elt.setAttribute('title', mxResources.get('insertRowBefore'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
2015-08-28 13:41:48 +00:00
try
{
graph.selectNode(graph.insertRow(table, row.sectionRowIndex + 1));
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}), null, 'geIcon geSprite geSprite-insertrowafter');
elt.setAttribute('title', mxResources.get('insertRowAfter'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
2015-08-28 13:41:48 +00:00
try
{
graph.deleteRow(table, row.sectionRowIndex);
}
catch (e)
{
2019-07-15 10:46:53 +00:00
this.editorUi.handleError(e);
2015-08-28 13:41:48 +00:00
}
2014-01-13 16:13:21 +00:00
}), null, 'geIcon geSprite geSprite-deleterow');
elt.setAttribute('title', mxResources.get('deleteRow'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
2015-01-05 14:01:01 +00:00
// Converts rgb(r,g,b) values
var color = table.style.borderColor.replace(
2014-01-13 16:13:21 +00:00
/\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
function($0, $1, $2, $3) {
return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
});
2015-01-05 14:01:01 +00:00
this.editorUi.pickColor(color, function(newColor)
2014-01-13 16:13:21 +00:00
{
2015-01-05 14:01:01 +00:00
if (newColor == null || newColor == mxConstants.NONE)
2014-01-13 16:13:21 +00:00
{
table.removeAttribute('border');
table.style.border = '';
table.style.borderCollapse = '';
}
else
{
table.setAttribute('border', '1');
2015-01-05 14:01:01 +00:00
table.style.border = '1px solid ' + newColor;
2014-01-13 16:13:21 +00:00
table.style.borderCollapse = 'collapse';
}
});
}), null, 'geIcon geSprite geSprite-strokecolor');
elt.setAttribute('title', mxResources.get('borderColor'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
// Converts rgb(r,g,b) values
2015-01-05 14:01:01 +00:00
var color = table.style.backgroundColor.replace(
2014-01-13 16:13:21 +00:00
/\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
function($0, $1, $2, $3) {
return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
});
2015-01-05 14:01:01 +00:00
this.editorUi.pickColor(color, function(newColor)
2014-01-13 16:13:21 +00:00
{
2015-01-05 14:01:01 +00:00
if (newColor == null || newColor == mxConstants.NONE)
2014-01-13 16:13:21 +00:00
{
table.style.backgroundColor = '';
}
else
{
2015-01-05 14:01:01 +00:00
table.style.backgroundColor = newColor;
2014-01-13 16:13:21 +00:00
}
});
}), null, 'geIcon geSprite geSprite-fillcolor');
elt.setAttribute('title', mxResources.get('backgroundColor'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
var value = table.getAttribute('cellPadding') || 0;
var dlg = new FilenameDialog(this.editorUi, value, mxResources.get('apply'), mxUtils.bind(this, function(newValue)
{
if (newValue != null && newValue.length > 0)
{
table.setAttribute('cellPadding', newValue);
}
else
{
table.removeAttribute('cellPadding');
}
}), mxResources.get('spacing'));
this.editorUi.showDialog(dlg.container, 300, 80, true, true);
dlg.init();
}), null, 'geIcon geSprite geSprite-fit');
elt.setAttribute('title', mxResources.get('spacing'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
table.setAttribute('align', 'left');
}), null, 'geIcon geSprite geSprite-left');
elt.setAttribute('title', mxResources.get('left'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
table.setAttribute('align', 'center');
}), null, 'geIcon geSprite geSprite-center');
elt.setAttribute('title', mxResources.get('center'));
elt = menu.addItem('', null, mxUtils.bind(this, function()
{
table.setAttribute('align', 'right');
}), null, 'geIcon geSprite geSprite-right');
elt.setAttribute('title', mxResources.get('right'));
}
}));
2015-08-28 13:41:48 +00:00
elt.style.position = 'relative';
elt.style.whiteSpace = 'nowrap';
elt.style.overflow = 'hidden';
elt.innerHTML = '<div class="geSprite geSprite-table" style="margin-left:-2px;"></div>' + this.dropdownImageHtml;
2021-03-20 04:32:46 +00:00
elt.style.width = '30px';
2015-08-28 13:41:48 +00:00
// Fix for item size in kennedy theme
if (EditorUi.compactUi)
2014-01-08 16:23:20 +00:00
{
2015-08-28 13:41:48 +00:00
elt.getElementsByTagName('img')[0].style.left = '22px';
elt.getElementsByTagName('img')[0].style.top = '5px';
}
2014-01-08 16:23:20 +00:00
};
2012-05-21 20:32:26 +00:00
/**
* Hides the current menu.
*/
Toolbar.prototype.hideMenu = function()
{
2015-12-11 09:22:19 +00:00
this.editorUi.hideCurrentMenu();
2012-05-21 20:32:26 +00:00
};
/**
* Adds a label to the toolbar.
*/
2018-09-21 08:36:59 +00:00
Toolbar.prototype.addMenu = function(label, tooltip, showLabels, name, c, showAll, ignoreState)
2012-05-21 20:32:26 +00:00
{
var menu = this.editorUi.menus.get(name);
2017-01-16 08:36:34 +00:00
var elt = this.addMenuFunction(label, tooltip, showLabels, function()
{
menu.funct.apply(menu, arguments);
}, c, showAll);
2012-05-21 20:32:26 +00:00
2020-10-28 14:58:34 +00:00
// Workaround for possible not a function
// when extending HTML objects
if (!ignoreState && typeof elt.setEnabled === 'function')
2012-05-21 20:32:26 +00:00
{
2018-09-21 08:36:59 +00:00
menu.addListener('stateChanged', function()
{
elt.setEnabled(menu.enabled);
});
}
2012-05-21 20:32:26 +00:00
return elt;
};
/**
* Adds a label to the toolbar.
*/
2015-08-28 13:41:48 +00:00
Toolbar.prototype.addMenuFunction = function(label, tooltip, showLabels, funct, c, showAll)
2015-01-05 14:01:01 +00:00
{
2015-08-28 13:41:48 +00:00
return this.addMenuFunctionInContainer((c != null) ? c : this.container, label, tooltip, showLabels, funct, showAll);
2015-01-05 14:01:01 +00:00
};
/**
* Adds a label to the toolbar.
*/
2015-08-28 13:41:48 +00:00
Toolbar.prototype.addMenuFunctionInContainer = function(container, label, tooltip, showLabels, funct, showAll)
2012-05-21 20:32:26 +00:00
{
var elt = (showLabels) ? this.createLabel(label) : this.createButton(label);
this.initElement(elt, tooltip);
2015-08-28 13:41:48 +00:00
this.addMenuHandler(elt, showLabels, funct, showAll);
2015-01-05 14:01:01 +00:00
container.appendChild(elt);
2012-05-21 20:32:26 +00:00
return elt;
};
/**
* Adds a separator to the separator.
*/
2015-01-05 14:01:01 +00:00
Toolbar.prototype.addSeparator = function(c)
2012-05-21 20:32:26 +00:00
{
2015-01-05 14:01:01 +00:00
c = (c != null) ? c : this.container;
2012-05-21 20:32:26 +00:00
var elt = document.createElement('div');
2012-06-14 12:43:20 +00:00
elt.className = 'geSeparator';
2015-01-05 14:01:01 +00:00
c.appendChild(elt);
2012-05-21 20:32:26 +00:00
return elt;
};
/**
* Adds given action item
*/
2015-01-05 14:01:01 +00:00
Toolbar.prototype.addItems = function(keys, c, ignoreDisabled)
2012-05-21 20:32:26 +00:00
{
2014-05-05 08:30:00 +00:00
var items = [];
2012-05-21 20:32:26 +00:00
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
if (key == '-')
{
2015-01-05 14:01:01 +00:00
items.push(this.addSeparator(c));
2012-05-21 20:32:26 +00:00
}
else
{
2015-01-05 14:01:01 +00:00
items.push(this.addItem('geSprite-' + key.toLowerCase(), key, c, ignoreDisabled));
2012-05-21 20:32:26 +00:00
}
}
2014-05-05 08:30:00 +00:00
return items;
2012-05-21 20:32:26 +00:00
};
/**
* Adds given action item
*/
2015-01-05 14:01:01 +00:00
Toolbar.prototype.addItem = function(sprite, key, c, ignoreDisabled)
2012-05-21 20:32:26 +00:00
{
var action = this.editorUi.actions.get(key);
var elt = null;
if (action != null)
{
2017-01-16 08:36:34 +00:00
var tooltip = action.label;
if (action.shortcut != null)
{
tooltip += ' (' + action.shortcut + ')';
}
elt = this.addButton(sprite, tooltip, action.funct, c);
2015-01-05 14:01:01 +00:00
2020-10-28 14:58:34 +00:00
// Workaround for possible not a function
// when extending HTML objects
if (!ignoreDisabled && typeof elt.setEnabled === 'function')
2012-05-21 20:32:26 +00:00
{
elt.setEnabled(action.enabled);
2015-01-05 14:01:01 +00:00
action.addListener('stateChanged', function()
{
elt.setEnabled(action.enabled);
});
}
2012-05-21 20:32:26 +00:00
}
return elt;
};
/**
* Adds a button to the toolbar.
*/
2015-01-05 14:01:01 +00:00
Toolbar.prototype.addButton = function(classname, tooltip, funct, c)
2012-05-21 20:32:26 +00:00
{
var elt = this.createButton(classname);
2015-01-05 14:01:01 +00:00
c = (c != null) ? c : this.container;
2012-05-21 20:32:26 +00:00
this.initElement(elt, tooltip);
this.addClickHandler(elt, funct);
2015-01-05 14:01:01 +00:00
c.appendChild(elt);
2012-05-21 20:32:26 +00:00
return elt;
};
/**
* Initializes the given toolbar element.
*/
Toolbar.prototype.initElement = function(elt, tooltip)
{
// Adds tooltip
if (tooltip != null)
{
elt.setAttribute('title', tooltip);
}
this.addEnabledState(elt);
};
/**
* Adds enabled state with setter to DOM node (avoids JS wrapper).
*/
Toolbar.prototype.addEnabledState = function(elt)
{
var classname = elt.className;
elt.setEnabled = function(value)
{
elt.enabled = value;
if (value)
{
elt.className = classname;
}
else
{
2014-01-08 16:23:20 +00:00
elt.className = classname + ' mxDisabled';
2012-05-21 20:32:26 +00:00
}
};
elt.setEnabled(true);
};
/**
* Adds enabled state with setter to DOM node (avoids JS wrapper).
*/
Toolbar.prototype.addClickHandler = function(elt, funct)
{
if (funct != null)
{
mxEvent.addListener(elt, 'click', function(evt)
{
if (elt.enabled)
{
funct(evt);
}
mxEvent.consume(evt);
});
2014-01-08 16:23:20 +00:00
2018-12-14 11:54:12 +00:00
// Prevents focus
mxEvent.addListener(elt, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
mxUtils.bind(this, function(evt)
{
evt.preventDefault();
}));
2012-05-21 20:32:26 +00:00
}
};
/**
* Creates and returns a new button.
*/
Toolbar.prototype.createButton = function(classname)
{
var elt = document.createElement('a');
2012-06-14 12:43:20 +00:00
elt.className = 'geButton';
2012-05-21 20:32:26 +00:00
var inner = document.createElement('div');
2014-01-08 16:23:20 +00:00
if (classname != null)
{
inner.className = 'geSprite ' + classname;
}
2012-05-21 20:32:26 +00:00
elt.appendChild(inner);
return elt;
};
/**
* Creates and returns a new button.
*/
Toolbar.prototype.createLabel = function(label, tooltip)
{
var elt = document.createElement('a');
2012-06-14 12:43:20 +00:00
elt.className = 'geLabel';
2012-05-21 20:32:26 +00:00
mxUtils.write(elt, label);
return elt;
};
/**
* Adds a handler for showing a menu in the given element.
*/
Toolbar.prototype.addMenuHandler = function(elt, showLabels, funct, showAll)
{
if (funct != null)
{
var graph = this.editorUi.editor.graph;
var menu = null;
2015-01-05 14:01:01 +00:00
var show = true;
2012-05-21 20:32:26 +00:00
mxEvent.addListener(elt, 'click', mxUtils.bind(this, function(evt)
{
2015-01-05 14:01:01 +00:00
if (show && (elt.enabled == null || elt.enabled))
2012-05-21 20:32:26 +00:00
{
2013-06-28 19:07:06 +00:00
graph.popupMenuHandler.hideMenu();
2012-05-21 20:32:26 +00:00
menu = new mxPopupMenu(funct);
2012-06-14 12:43:20 +00:00
menu.div.className += ' geToolbarMenu';
2012-05-21 20:32:26 +00:00
menu.showDisabled = showAll;
menu.labels = showLabels;
menu.autoExpand = true;
2015-01-05 14:01:01 +00:00
2013-11-11 12:31:46 +00:00
var offset = mxUtils.getOffset(elt);
menu.popup(offset.x, offset.y + elt.offsetHeight, null, evt);
2015-12-11 09:22:19 +00:00
this.editorUi.setCurrentMenu(menu, elt);
2015-01-05 14:01:01 +00:00
2016-01-06 10:57:28 +00:00
// Workaround for scrollbar hiding menu items
if (!showLabels && menu.div.scrollHeight > menu.div.clientHeight)
{
menu.div.style.width = '40px';
}
2017-08-28 09:54:36 +00:00
menu.hideMenu = mxUtils.bind(this, function()
{
mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
this.editorUi.resetCurrentMenu();
menu.destroy();
});
2015-01-05 14:01:01 +00:00
// Extends destroy to reset global state
menu.addListener(mxEvent.EVENT_HIDE, mxUtils.bind(this, function()
{
this.currentElt = null;
}));
2012-05-21 20:32:26 +00:00
}
2015-01-05 14:01:01 +00:00
show = true;
2012-05-21 20:32:26 +00:00
mxEvent.consume(evt);
}));
2015-01-05 14:01:01 +00:00
2018-12-14 11:54:12 +00:00
// Hides menu if already showing and prevents focus
mxEvent.addListener(elt, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
mxUtils.bind(this, function(evt)
2014-01-08 16:23:20 +00:00
{
2015-01-05 14:01:01 +00:00
show = this.currentElt != elt;
2018-12-14 11:54:12 +00:00
evt.preventDefault();
2015-01-05 14:01:01 +00:00
}));
2012-05-21 20:32:26 +00:00
}
};
2015-08-28 13:41:48 +00:00
/**
* Adds a handler for showing a menu in the given element.
*/
Toolbar.prototype.destroy = function()
{
if (this.gestureHandler != null)
{
mxEvent.removeGestureListeners(document, this.gestureHandler);
this.gestureHandler = null;
}
};