/** * Copyright (c) 2006-2015, JGraph Ltd * Copyright (c) 2006-2015, Gaudenz Alder */ /** * Class: mxCellEditor * * In-place editor for the graph. To control this editor, use * , and * . If is true then * ctrl-enter or shift-enter can be used to create a linefeed. The F2 and * escape keys can always be used to stop editing. * * To customize the location of the textbox in the graph, override * as follows: * * (code) * graph.cellEditor.getEditorBounds = function(state) * { * var result = mxCellEditor.prototype.getEditorBounds.apply(this, arguments); * * if (this.graph.getModel().isEdge(state.cell)) * { * result.x = state.getCenterX() - result.width / 2; * result.y = state.getCenterY() - result.height / 2; * } * * return result; * }; * (end) * * Note that this hook is only called if is false. If is true, * then is used to compute the current bounds of the textbox. * * The textarea uses the mxCellEditor CSS class. You can modify this class in * your custom CSS. Note: You should modify the CSS after loading the client * in the page. * * Example: * * To only allow numeric input in the in-place editor, use the following code. * * (code) * var text = graph.cellEditor.textarea; * * mxEvent.addListener(text, 'keydown', function (evt) * { * if (!(evt.keyCode >= 48 && evt.keyCode <= 57) && * !(evt.keyCode >= 96 && evt.keyCode <= 105)) * { * mxEvent.consume(evt); * } * }); * (end) * * Placeholder: * * To implement a placeholder for cells without a label, use the * variable. * * Resize in Chrome: * * Resize of the textarea is disabled by default. If you want to enable * this feature extend and set this.textarea.style.resize = ''. * * To start editing on a key press event, the container of the graph * should have focus or a focusable parent should be used to add the * key press handler as follows. * * (code) * mxEvent.addListener(graph.container, 'keypress', mxUtils.bind(this, function(evt) * { * if (!graph.isEditing() && !graph.isSelectionEmpty() && evt.which !== 0 && * !mxEvent.isAltDown(evt) && !mxEvent.isControlDown(evt) && !mxEvent.isMetaDown(evt)) * { * graph.startEditing(); * * if (mxClient.IS_FF) * { * graph.cellEditor.textarea.value = String.fromCharCode(evt.which); * } * } * })); * (end) * * To allow focus for a DIV, and hence to receive key press events, some browsers * require it to have a valid tabindex attribute. In this case the following * code may be used to keep the container focused. * * (code) * var graphFireMouseEvent = graph.fireMouseEvent; * graph.fireMouseEvent = function(evtName, me, sender) * { * if (evtName == mxEvent.MOUSE_DOWN) * { * this.container.focus(); * } * * graphFireMouseEvent.apply(this, arguments); * }; * (end) * * Constructor: mxCellEditor * * Constructs a new in-place editor for the specified graph. * * Parameters: * * graph - Reference to the enclosing . */ function mxCellEditor(graph) { this.graph = graph; // Stops editing after zoom changes this.zoomHandler = mxUtils.bind(this, function() { if (this.graph.isEditing()) { this.resize(); } }); this.graph.view.addListener(mxEvent.SCALE, this.zoomHandler); this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.zoomHandler); // Adds handling of deleted cells while editing this.changeHandler = mxUtils.bind(this, function(sender) { if (this.editingCell != null && this.graph.getView().getState(this.editingCell) == null) { this.stopEditing(true); } }); this.graph.getModel().addListener(mxEvent.CHANGE, this.changeHandler); }; /** * Variable: graph * * Reference to the enclosing . */ mxCellEditor.prototype.graph = null; /** * Variable: textarea * * Holds the DIV that is used for text editing. Note that this may be null before the first * edit. Instantiated in . */ mxCellEditor.prototype.textarea = null; /** * Variable: editingCell * * Reference to the that is currently being edited. */ mxCellEditor.prototype.editingCell = null; /** * Variable: trigger * * Reference to the event that was used to start editing. */ mxCellEditor.prototype.trigger = null; /** * Variable: modified * * Specifies if the label has been modified. */ mxCellEditor.prototype.modified = false; /** * Variable: autoSize * * Specifies if the textarea should be resized while the text is being edited. * Default is true. */ mxCellEditor.prototype.autoSize = true; /** * Variable: selectText * * Specifies if the text should be selected when editing starts. Default is * true. */ mxCellEditor.prototype.selectText = true; /** * Variable: emptyLabelText * * Text to be displayed for empty labels. Default is '' or '
' in Firefox as * a workaround for the missing cursor bug for empty content editable. This can * be set to eg. "[Type Here]" to easier visualize editing of empty labels. The * value is only displayed before the first keystroke and is never used as the * actual editing value. */ mxCellEditor.prototype.emptyLabelText = (mxClient.IS_FF) ? '
' : ''; /** * Variable: escapeCancelsEditing * * If true, pressing the escape key will stop editing and not accept the new * value. Change this to false to accept the new value on escape, and cancel * editing on Shift+Escape instead. Default is true. */ mxCellEditor.prototype.escapeCancelsEditing = true; /** * Variable: textNode * * Reference to the label DOM node that has been hidden. */ mxCellEditor.prototype.textNode = ''; /** * Variable: zIndex * * Specifies the zIndex for the textarea. Default is 5. */ mxCellEditor.prototype.zIndex = 5; /** * Variable: minResize * * Defines the minimum width and height to be used in . Default is 0x20px. */ mxCellEditor.prototype.minResize = new mxRectangle(0, 20); /** * Variable: wordWrapPadding * * Correction factor for word wrapping width. Default is 2 in quirks, 0 in IE * 11 and 1 in all other browsers and modes. */ mxCellEditor.prototype.wordWrapPadding = (mxClient.IS_QUIRKS) ? 2 : (!mxClient.IS_IE11) ? 1 : 0; /** * Variable: blurEnabled * * If should be called if