started removing mxUtils.bind() calls in favor of ()=>{} style functions

development
mcyph 2021-03-20 22:38:03 +11:00
parent 2edc6c838f
commit cefe19455b
28 changed files with 155 additions and 175 deletions

View File

@ -39,8 +39,7 @@
img.style.top = (state.y + state.height) + 'px'; img.style.top = (state.y + state.height) + 'px';
mxEvent.addGestureListeners(img, mxEvent.addGestureListeners(img,
mxUtils.bind(this, function(evt) (evt) => {
{
var s = graph.gridSize; var s = graph.gridSize;
graph.setSelectionCells(graph.moveCells([state.cell], s, s, true)); graph.setSelectionCells(graph.moveCells([state.cell], s, s, true));
mxEvent.consume(evt); mxEvent.consume(evt);
@ -62,20 +61,18 @@
img.style.top = (state.y - 16) + 'px'; img.style.top = (state.y - 16) + 'px';
mxEvent.addGestureListeners(img, mxEvent.addGestureListeners(img,
mxUtils.bind(this, function(evt) (evt) => {
{
// Disables dragging the image // Disables dragging the image
mxEvent.consume(evt); mxEvent.consume(evt);
}) }
); );
mxEvent.addListener(img, 'click', mxEvent.addListener(img, 'click',
mxUtils.bind(this, function(evt) (evt) => {
{
graph.removeCells([state.cell]); graph.removeCells([state.cell]);
mxEvent.consume(evt); mxEvent.consume(evt);
this.destroy(); this.destroy();
}) }
); );
state.view.graph.container.appendChild(img); state.view.graph.container.appendChild(img);

View File

@ -1,18 +0,0 @@
div.mxTooltip {
filter:progid:DXImageTransform.Microsoft.DropShadow(OffX=4, OffY=4,
Color='#A2A2A2', Positive='true');
}
div.mxPopupMenu {
filter:progid:DXImageTransform.Microsoft.DropShadow(OffX=4, OffY=4,
Color='#C0C0C0', Positive='true');
}
div.mxWindow {
_filter:progid:DXImageTransform.Microsoft.DropShadow(OffX=4, OffY=4,
Color='#C0C0C0', Positive='true');
}
td.mxWindowTitle {
_height: 23px;
}
.mxDisabled {
filter:alpha(opacity=20) !important;
}

View File

@ -95,9 +95,9 @@ class mxDefaultKeyHandler {
* Default is false. * Default is false.
*/ */
bindAction = (code, action, control) => { bindAction = (code, action, control) => {
let keyHandler = mxUtils.bind(this, () => { let keyHandler = () => {
this.editor.execute(action); this.editor.execute(action);
}); };
if (control) { if (control) {
// Binds the function to control-down keycode // Binds the function to control-down keycode

View File

@ -109,18 +109,18 @@ class mxDefaultToolbar {
// Installs the insert function in the editor if an item is // Installs the insert function in the editor if an item is
// selected in the toolbar // selected in the toolbar
this.toolbar.addListener(mxEvent.SELECT, mxUtils.bind(this, (sender, evt) => { this.toolbar.addListener(mxEvent.SELECT, (sender, evt) => {
let funct = evt.getProperty('function'); let funct = evt.getProperty('function');
if (funct != null) { if (funct != null) {
this.editor.insertFunction = mxUtils.bind(this, () => { this.editor.insertFunction = () => {
funct.apply(this, arguments); funct.apply(this, arguments);
this.toolbar.resetMode(); this.toolbar.resetMode();
}); };
} else { } else {
this.editor.insertFunction = null; this.editor.insertFunction = null;
} }
})); });
// Resets the selected tool after a doubleclick or escape keystroke // Resets the selected tool after a doubleclick or escape keystroke
this.resetHandler = mxUtils.bind(this, () => { this.resetHandler = mxUtils.bind(this, () => {
@ -148,12 +148,11 @@ class mxDefaultToolbar {
* pressed - Optional URL of the icon for the pressed state. * pressed - Optional URL of the icon for the pressed state.
*/ */
addItem = (title, icon, action, pressed) => { addItem = (title, icon, action, pressed) => {
let clickHandler = mxUtils.bind(this, () => { let clickHandler = () => {
if (action != null && action.length > 0) { if (action != null && action.length > 0) {
this.editor.execute(action); this.editor.execute(action);
} }
}); };
return this.toolbar.addItem(title, icon, clickHandler, pressed); return this.toolbar.addItem(title, icon, clickHandler, pressed);
}; };
@ -251,14 +250,13 @@ class mxDefaultToolbar {
* selected. * selected.
*/ */
addMode = (title, icon, mode, pressed, funct) => { addMode = (title, icon, mode, pressed, funct) => {
let clickHandler = mxUtils.bind(this, () => { let clickHandler = () => {
this.editor.setMode(mode); this.editor.setMode(mode);
if (funct != null) { if (funct != null) {
funct(this.editor); funct(this.editor);
} }
}); };
return this.toolbar.addSwitchMode(title, icon, clickHandler, pressed); return this.toolbar.addSwitchMode(title, icon, clickHandler, pressed);
}; };
@ -298,7 +296,7 @@ class mxDefaultToolbar {
// Defines the function for a click event on the graph // Defines the function for a click event on the graph
// after this item has been selected in the toolbar // after this item has been selected in the toolbar
let clickHandler = mxUtils.bind(this, (evt, cell) => { let clickHandler = (evt, cell) => {
if (typeof (insert) == 'function') { if (typeof (insert) == 'function') {
insert(this.editor, factory(), evt, cell); insert(this.editor, factory(), evt, cell);
} else { } else {
@ -307,7 +305,7 @@ class mxDefaultToolbar {
this.toolbar.resetMode(); this.toolbar.resetMode();
mxEvent.consume(evt); mxEvent.consume(evt);
}); };
let img = this.toolbar.addMode(title, icon, clickHandler, pressed, null, toggle); let img = this.toolbar.addMode(title, icon, clickHandler, pressed, null, toggle);

View File

@ -1470,16 +1470,16 @@ class mxEditor extends mxEventSource {
// Redirects the function for creating the // Redirects the function for creating the
// popupmenu items // popupmenu items
graph.popupMenuHandler.factoryMethod = graph.popupMenuHandler.factoryMethod =
mxUtils.bind(this, (menu, cell, evt) => { (menu, cell, evt) => {
return this.createPopupMenu(menu, cell, evt); return this.createPopupMenu(menu, cell, evt);
}); };
// Redirects the function for creating // Redirects the function for creating
// new connections in the diagram // new connections in the diagram
graph.connectionHandler.factoryMethod = graph.connectionHandler.factoryMethod =
mxUtils.bind(this, (source, target) => { (source, target) => {
return this.createEdge(source, target); return this.createEdge(source, target);
}); };
// Maintains swimlanes and installs autolayout // Maintains swimlanes and installs autolayout
this.createSwimlaneManager(graph); this.createSwimlaneManager(graph);
@ -1500,9 +1500,9 @@ class mxEditor extends mxEventSource {
return this.horizontalFlow; return this.horizontalFlow;
}); });
swimlaneMgr.isEnabled = mxUtils.bind(this, () => { swimlaneMgr.isEnabled = () => {
return this.maintainSwimlanes; return this.maintainSwimlanes;
}); };
return swimlaneMgr; return swimlaneMgr;
}; };
@ -1604,10 +1604,10 @@ class mxEditor extends mxEventSource {
* Adds the <undoManager> to the graph model and the view. * Adds the <undoManager> to the graph model and the view.
*/ */
installUndoHandler = (graph) => { installUndoHandler = (graph) => {
var listener = mxUtils.bind(this, (sender, evt) => { var listener = (sender, evt) => {
var edit = evt.getProperty('edit'); var edit = evt.getProperty('edit');
this.undoManager.undoableEditHappened(edit); this.undoManager.undoableEditHappened(edit);
}); };
graph.getModel().addListener(mxEvent.UNDO, listener); graph.getModel().addListener(mxEvent.UNDO, listener);
graph.getView().addListener(mxEvent.UNDO, listener); graph.getView().addListener(mxEvent.UNDO, listener);
@ -1644,7 +1644,7 @@ class mxEditor extends mxEventSource {
* fires a <root> event. * fires a <root> event.
*/ */
installChangeHandler = (graph) => { installChangeHandler = (graph) => {
var listener = mxUtils.bind(this, (sender, evt) => { var listener = (sender, evt) => {
// Updates the modified state // Updates the modified state
this.setModified(true); this.setModified(true);
@ -1669,7 +1669,7 @@ class mxEditor extends mxEventSource {
break; break;
} }
} }
}); };
graph.getModel().addListener(mxEvent.CHANGE, listener); graph.getModel().addListener(mxEvent.CHANGE, listener);
}; };
@ -1790,10 +1790,10 @@ class mxEditor extends mxEventSource {
// Updates the statusbar to display the filename // Updates the statusbar to display the filename
// when new files are opened // when new files are opened
this.addListener(mxEvent.OPEN, mxUtils.bind(this, () => { this.addListener(mxEvent.OPEN, () => {
this.setStatus((mxResources.get(this.currentFileResource) || this.setStatus((mxResources.get(this.currentFileResource) ||
this.currentFileResource) + ': ' + this.filename); this.currentFileResource) + ': ' + this.filename);
})); });
} }
}; };
@ -2042,10 +2042,10 @@ class mxEditor extends mxEventSource {
} }
mxUtils.post(url, this.postParameterName + '=' + data, mxUtils.post(url, this.postParameterName + '=' + data,
mxUtils.bind(this, (req) => { (req) => {
this.fireEvent(new mxEventObject(mxEvent.POST, this.fireEvent(new mxEventObject(mxEvent.POST,
'request', req, 'url', url, 'data', data)); 'request', req, 'url', url, 'data', data));
}) }
); );
}; };
@ -2297,10 +2297,10 @@ class mxEditor extends mxEventSource {
// Defines the function to be executed when the // Defines the function to be executed when the
// Cancel button is pressed in the dialog // Cancel button is pressed in the dialog
var cancelFunction = mxUtils.bind(this, () => { var cancelFunction = () => {
// Hides the dialog // Hides the dialog
this.hideProperties(); this.hideProperties();
}); };
form.addButtons(okFunction, cancelFunction); form.addButtons(okFunction, cancelFunction);

View File

@ -374,9 +374,9 @@ class mxConnectionHandler extends mxEventSource {
this.init(); this.init();
// Handles escape keystrokes // Handles escape keystrokes
this.escapeHandler = mxUtils.bind(this, (sender, evt) => { this.escapeHandler = (sender, evt) => {
this.reset(); this.reset();
}); };
this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler); this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
} }
@ -499,9 +499,9 @@ class mxConnectionHandler extends mxEventSource {
this.graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, this.changeHandler); this.graph.getView().addListener(mxEvent.SCALE_AND_TRANSLATE, this.changeHandler);
// Removes the icon if we step into/up or start editing // Removes the icon if we step into/up or start editing
this.drillHandler = mxUtils.bind(this, (sender) => { this.drillHandler = (sender) => {
this.reset(); this.reset();
}); };
this.graph.addListener(mxEvent.START_EDITING, this.drillHandler); this.graph.addListener(mxEvent.START_EDITING, this.drillHandler);
this.graph.getView().addListener(mxEvent.DOWN, this.drillHandler); this.graph.getView().addListener(mxEvent.DOWN, this.drillHandler);
@ -579,31 +579,30 @@ class mxConnectionHandler extends mxEventSource {
}); });
// Sets the highlight color according to validateConnection // Sets the highlight color according to validateConnection
marker.isValidState = mxUtils.bind(this, (state) => { marker.isValidState = (state) => {
if (this.isConnecting()) { if (this.isConnecting()) {
return this.error == null; return this.error == null;
} else { } else {
return isValidState.apply(marker, arguments); return isValidState.apply(marker, arguments);
} }
}); };
// Overrides to use marker color only in highlight mode or for // Overrides to use marker color only in highlight mode or for
// target selection // target selection
marker.getMarkerColor = mxUtils.bind(this, (evt, state, isValid) => { marker.getMarkerColor = mxUtils.bind(this, (evt, state, isValid) => {
return (this.connectImage == null || this.isConnecting()) ? return (this.connectImage == null || this.isConnecting()) ?
getMarkerColor.apply(marker, arguments) : super.getMarkerColor(evt, state, isValid) :
null; null;
}); });
// Overrides to use hotspot only for source selection otherwise // Overrides to use hotspot only for source selection otherwise
// intersects always returns true when over a cell // intersects always returns true when over a cell
marker.intersects = mxUtils.bind(this, (state, evt) => { marker.intersects = (state, evt) => {
if (this.connectImage != null || this.isConnecting()) { if (this.connectImage != null || this.isConnecting()) {
return true; return true;
} }
return super.intersects(state, evt);
return intersects.apply(marker, arguments); };
});
return marker; return marker;
}; };
@ -759,18 +758,18 @@ class mxConnectionHandler extends mxEventSource {
icon.node.style.cursor = mxConstants.CURSOR_CONNECT; icon.node.style.cursor = mxConstants.CURSOR_CONNECT;
// Events transparency // Events transparency
var getState = mxUtils.bind(this, () => { var getState = () => {
return (this.currentState != null) ? this.currentState : state; return (this.currentState != null) ? this.currentState : state;
}); };
// Updates the local icon before firing the mouse down event. // Updates the local icon before firing the mouse down event.
var mouseDown = mxUtils.bind(this, (evt) => { var mouseDown = (evt) => {
if (!mxEvent.isConsumed(evt)) { if (!mxEvent.isConsumed(evt)) {
this.icon = icon; this.icon = icon;
this.graph.fireMouseEvent(mxEvent.MOUSE_DOWN, this.graph.fireMouseEvent(mxEvent.MOUSE_DOWN,
new mxMouseEvent(evt, getState())); new mxMouseEvent(evt, getState()));
} }
}); };
mxEvent.redirectMouseEvents(icon.node, this.graph, getState, mouseDown); mxEvent.redirectMouseEvents(icon.node, this.graph, getState, mouseDown);

View File

@ -54,13 +54,13 @@ class mxConstraintHandler {
this.graph = graph; this.graph = graph;
// Adds a graph model listener to update the current focus on changes // Adds a graph model listener to update the current focus on changes
this.resetHandler = mxUtils.bind(this, (sender, evt) => { this.resetHandler = (sender, evt) => {
if (this.currentFocus != null && this.graph.view.getState(this.currentFocus.cell) == null) { if (this.currentFocus != null && this.graph.view.getState(this.currentFocus.cell) == null) {
this.reset(); this.reset();
} else { } else {
this.redraw(); this.redraw();
} }
}); };
this.graph.model.addListener(mxEvent.CHANGE, this.resetHandler); this.graph.model.addListener(mxEvent.CHANGE, this.resetHandler);
this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.resetHandler); this.graph.view.addListener(mxEvent.SCALE_AND_TRANSLATE, this.resetHandler);
@ -292,9 +292,9 @@ class mxConstraintHandler {
hl.init(this.graph.getView().getOverlayPane()); hl.init(this.graph.getView().getOverlayPane());
this.focusHighlight = hl; this.focusHighlight = hl;
var getState = mxUtils.bind(this, () => { var getState = () => {
return (this.currentFocus != null) ? this.currentFocus : state; return (this.currentFocus != null) ? this.currentFocus : state;
}); };
mxEvent.redirectMouseEvents(hl.node, this.graph, getState); mxEvent.redirectMouseEvents(hl.node, this.graph, getState);
} }

View File

@ -233,14 +233,14 @@ class mxEdgeHandler {
this.init(); this.init();
// Handles escape keystrokes // Handles escape keystrokes
this.escapeHandler = mxUtils.bind(this, (sender, evt) => { this.escapeHandler = (sender, evt) => {
var dirty = this.index != null; var dirty = this.index != null;
this.reset(); this.reset();
if (dirty) { if (dirty) {
this.graph.cellRenderer.redraw(this.state, false, state.view.isRendering()); this.graph.cellRenderer.redraw(this.state, false, state.view.isRendering());
} }
}); };
this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler); this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
} }
@ -554,13 +554,13 @@ class mxEdgeHandler {
var terminal = source || target; var terminal = source || target;
if (terminal || this.graph.isCellBendable(cell)) { if (terminal || this.graph.isCellBendable(cell)) {
(mxUtils.bind(this, (index) => { ((index) => {
var bend = this.createHandleShape(index); var bend = this.createHandleShape(index);
this.initBend(bend, mxUtils.bind(this, mxUtils.bind(this, () => { this.initBend(bend, () => {
if (this.dblClickRemoveEnabled) { if (this.dblClickRemoveEnabled) {
this.removePoint(this.state, index); this.removePoint(this.state, index);
} }
}))); });
if (this.isHandleEnabled(i)) { if (this.isHandleEnabled(i)) {
bend.setCursor((terminal) ? mxConstants.CURSOR_TERMINAL_HANDLE : mxConstants.CURSOR_BEND_HANDLE); bend.setCursor((terminal) ? mxConstants.CURSOR_TERMINAL_HANDLE : mxConstants.CURSOR_BEND_HANDLE);
@ -572,7 +572,7 @@ class mxEdgeHandler {
this.points.push(new mxPoint(0, 0)); this.points.push(new mxPoint(0, 0));
bend.node.style.visibility = 'hidden'; bend.node.style.visibility = 'hidden';
} }
}))(i); })(i);
} }
} }
} }

View File

@ -55,12 +55,12 @@ class mxElbowEdgeHandler extends mxEdgeHandler {
bends.push(bend); bends.push(bend);
// Virtual // Virtual
bends.push(this.createVirtualBend(mxUtils.bind(this, (evt) => { bends.push(this.createVirtualBend((evt) => {
if (!mxEvent.isConsumed(evt) && this.flipEnabled) { if (!mxEvent.isConsumed(evt) && this.flipEnabled) {
this.graph.flipEdge(this.state.cell, evt); this.graph.flipEdge(this.state.cell, evt);
mxEvent.consume(evt); mxEvent.consume(evt);
} }
}))); }));
this.points.push(new mxPoint(0, 0)); this.points.push(new mxPoint(0, 0));

View File

@ -220,12 +220,12 @@ class mxGraphHandler {
this.graph.addMouseListener(this); this.graph.addMouseListener(this);
// Repaints the handler after autoscroll // Repaints the handler after autoscroll
this.panHandler = mxUtils.bind(this, () => { this.panHandler = () => {
if (!this.suspended) { if (!this.suspended) {
this.updatePreview(); this.updatePreview();
this.updateHint(); this.updateHint();
} }
}); };
this.graph.addListener(mxEvent.PAN, this.panHandler); this.graph.addListener(mxEvent.PAN, this.panHandler);
@ -237,7 +237,7 @@ class mxGraphHandler {
this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler); this.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
// Updates the preview box for remote changes // Updates the preview box for remote changes
this.refreshHandler = mxUtils.bind(this, (sender, evt) => { this.refreshHandler = (sender, evt) => {
// Merges multiple pending calls // Merges multiple pending calls
if (this.refreshThread) { if (this.refreshThread) {
window.clearTimeout(this.refreshThread); window.clearTimeout(this.refreshThread);
@ -275,12 +275,12 @@ class mxGraphHandler {
} }
} }
}), 0); }), 0);
}); };
this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler); this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler);
this.graph.addListener(mxEvent.REFRESH, this.refreshHandler); this.graph.addListener(mxEvent.REFRESH, this.refreshHandler);
this.keyHandler = mxUtils.bind(this, (e) => { this.keyHandler = (e) => {
if (this.graph.container != null && this.graph.container.style.visibility != 'hidden' && if (this.graph.container != null && this.graph.container.style.visibility != 'hidden' &&
this.first != null && !this.suspended) { this.first != null && !this.suspended) {
var clone = this.graph.isCloneEvent(e) && var clone = this.graph.isCloneEvent(e) &&
@ -293,7 +293,7 @@ class mxGraphHandler {
this.updatePreview(); this.updatePreview();
} }
} }
}); };
mxEvent.addListener(document, 'keydown', this.keyHandler); mxEvent.addListener(document, 'keydown', this.keyHandler);
mxEvent.addListener(document, 'keyup', this.keyHandler); mxEvent.addListener(document, 'keyup', this.keyHandler);
@ -762,7 +762,7 @@ class mxGraphHandler {
} }
} }
this.guide.isStateIgnored = mxUtils.bind(this, (state) => { this.guide.isStateIgnored = (state) => {
var p = this.graph.model.getParent(state.cell); var p = this.graph.model.getParent(state.cell);
return state.cell != null && ((!this.cloning && return state.cell != null && ((!this.cloning &&
@ -771,7 +771,7 @@ class mxGraphHandler {
!connected.get(state) && !connected.get(state) &&
(this.target == null || this.graph.model.getChildCount( (this.target == null || this.graph.model.getChildCount(
this.target) >= 2) && p != (this.target || parent))); this.target) >= 2) && p != (this.target || parent)));
}); };
} }
}; };
@ -1291,7 +1291,7 @@ class mxGraphHandler {
*/ */
resetLivePreview = () => { resetLivePreview = () => {
if (this.allCells != null) { if (this.allCells != null) {
this.allCells.visit(mxUtils.bind(this, (key, state) => { this.allCells.visit((key, state) => {
// Restores event handling // Restores event handling
if (state.shape != null && state.shape.originalPointerEvents != null) { if (state.shape != null && state.shape.originalPointerEvents != null) {
state.shape.pointerEvents = state.shape.originalPointerEvents; state.shape.pointerEvents = state.shape.originalPointerEvents;
@ -1321,7 +1321,7 @@ class mxGraphHandler {
// Forces repaint of connected edges // Forces repaint of connected edges
state.view.invalidate(state.cell); state.view.invalidate(state.cell);
})); });
// Repaints all invalid states // Repaints all invalid states
this.graph.view.validate(); this.graph.view.validate();

View File

@ -126,9 +126,9 @@ class mxKeyHandler {
this.controlKeys = []; this.controlKeys = [];
this.controlShiftKeys = []; this.controlShiftKeys = [];
this.keydownHandler = mxUtils.bind(this, (evt) => { this.keydownHandler = (evt) => {
this.keyDown(evt); this.keyDown(evt);
}); };
// Installs the keystroke listener in the target // Installs the keystroke listener in the target
mxEvent.addListener(this.target, 'keydown', this.keydownHandler); mxEvent.addListener(this.target, 'keydown', this.keydownHandler);

View File

@ -145,7 +145,7 @@ class mxPanningHandler extends mxEventSource {
this.graph.addMouseListener(this); this.graph.addMouseListener(this);
// Handles force panning event // Handles force panning event
this.forcePanningHandler = mxUtils.bind(this, (sender, evt) => { this.forcePanningHandler = (sender, evt) => {
var evtName = evt.getProperty('eventName'); var evtName = evt.getProperty('eventName');
var me = evt.getProperty('event'); var me = evt.getProperty('event');
@ -155,7 +155,7 @@ class mxPanningHandler extends mxEventSource {
this.fireEvent(new mxEventObject(mxEvent.PAN_START, 'event', me)); this.fireEvent(new mxEventObject(mxEvent.PAN_START, 'event', me));
me.consume(); me.consume();
} }
}); };
this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forcePanningHandler); this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forcePanningHandler);
@ -184,11 +184,11 @@ class mxPanningHandler extends mxEventSource {
this.graph.addListener(mxEvent.GESTURE, this.gestureHandler); this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);
this.mouseUpListener = mxUtils.bind(this, () => { this.mouseUpListener = () => {
if (this.active) { if (this.active) {
this.reset(); this.reset();
} }
}); };
// Stops scrolling on every mouseup anywhere in the document // Stops scrolling on every mouseup anywhere in the document
mxEvent.addListener(document, 'mouseup', this.mouseUpListener); mxEvent.addListener(document, 'mouseup', this.mouseUpListener);

View File

@ -66,7 +66,7 @@ class mxPopupMenuHandler extends mxPopupMenu {
* Constructs an event handler that creates a <mxPopupMenu>. * Constructs an event handler that creates a <mxPopupMenu>.
*/ */
constructor(graph, factoryMethod) { constructor(graph, factoryMethod) {
//super(); super();
if (graph != null) { if (graph != null) {
this.graph = graph; this.graph = graph;
@ -74,9 +74,9 @@ class mxPopupMenuHandler extends mxPopupMenu {
this.graph.addMouseListener(this); this.graph.addMouseListener(this);
// Does not show menu if any touch gestures take place after the trigger // Does not show menu if any touch gestures take place after the trigger
this.gestureHandler = mxUtils.bind(this, (sender, eo) => { this.gestureHandler = (sender, eo) => {
this.inTolerance = false; this.inTolerance = false;
}); };
this.graph.addListener(mxEvent.GESTURE, this.gestureHandler); this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);

View File

@ -77,7 +77,7 @@ class mxRubberband {
this.graph.addMouseListener(this); this.graph.addMouseListener(this);
// Handles force rubberband event // Handles force rubberband event
this.forceRubberbandHandler = mxUtils.bind(this, (sender, evt) => { this.forceRubberbandHandler = (sender, evt) => {
var evtName = evt.getProperty('eventName'); var evtName = evt.getProperty('eventName');
var me = evt.getProperty('event'); var me = evt.getProperty('event');
@ -89,7 +89,7 @@ class mxRubberband {
this.start(me.getX() + origin.x, me.getY() + origin.y); this.start(me.getX() + origin.x, me.getY() + origin.y);
me.consume(false); me.consume(false);
} }
}); };
this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forceRubberbandHandler); this.graph.addListener(mxEvent.FIRE_MOUSE_EVENT, this.forceRubberbandHandler);
@ -101,11 +101,11 @@ class mxRubberband {
this.graph.addListener(mxEvent.PAN, this.panHandler); this.graph.addListener(mxEvent.PAN, this.panHandler);
// Does not show menu if any touch gestures take place after the trigger // Does not show menu if any touch gestures take place after the trigger
this.gestureHandler = mxUtils.bind(this, (sender, eo) => { this.gestureHandler = (sender, eo) => {
if (this.first != null) { if (this.first != null) {
this.reset(); this.reset();
} }
}); };
this.graph.addListener(mxEvent.GESTURE, this.gestureHandler); this.graph.addListener(mxEvent.GESTURE, this.gestureHandler);
} }
@ -190,9 +190,9 @@ class mxRubberband {
this.mouseMove(this.graph, createMouseEvent(evt)); this.mouseMove(this.graph, createMouseEvent(evt));
}); });
this.dropHandler = mxUtils.bind(this, (evt) => { this.dropHandler = (evt) => {
this.mouseUp(this.graph, createMouseEvent(evt)); this.mouseUp(this.graph, createMouseEvent(evt));
}); };
// Workaround for rubberband stopping if the mouse leaves the container in Firefox // Workaround for rubberband stopping if the mouse leaves the container in Firefox
if (mxClient.IS_FF) { if (mxClient.IS_FF) {

View File

@ -68,11 +68,11 @@ class mxSelectionCellsHandler extends mxEventSource {
this.handlers = new mxDictionary(); this.handlers = new mxDictionary();
this.graph.addMouseListener(this); this.graph.addMouseListener(this);
this.refreshHandler = mxUtils.bind(this, (sender, evt) => { this.refreshHandler = (sender, evt) => {
if (this.isEnabled()) { if (this.isEnabled()) {
this.refresh(); this.refresh();
} }
}); };
this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.refreshHandler); this.graph.getSelectionModel().addListener(mxEvent.CHANGE, this.refreshHandler);
this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler); this.graph.getModel().addListener(mxEvent.CHANGE, this.refreshHandler);

View File

@ -131,13 +131,13 @@ class mxTooltipHandler {
document.body.appendChild(this.div); document.body.appendChild(this.div);
mxEvent.addGestureListeners(this.div, mxUtils.bind(this, (evt) => { mxEvent.addGestureListeners(this.div, (evt) => {
var source = mxEvent.getSource(evt); var source = mxEvent.getSource(evt);
if (source.nodeName != 'A') { if (source.nodeName != 'A') {
this.hideTooltip(); this.hideTooltip();
} }
})); });
} }
}; };
@ -224,7 +224,7 @@ class mxTooltipHandler {
var y = me.getY(); var y = me.getY();
var stateSource = me.isSource(state.shape) || me.isSource(state.text); var stateSource = me.isSource(state.shape) || me.isSource(state.text);
this.thread = window.setTimeout(mxUtils.bind(this, () => { this.thread = window.setTimeout(() => {
if (!this.graph.isEditing() && !this.graph.popupMenuHandler.isMenuShowing() && !this.graph.isMouseDown) { if (!this.graph.isEditing() && !this.graph.popupMenuHandler.isMenuShowing() && !this.graph.isMouseDown) {
// Uses information from inside event cause using the event at // Uses information from inside event cause using the event at
// this (delayed) point in time is not possible in IE as it no // this (delayed) point in time is not possible in IE as it no
@ -235,7 +235,7 @@ class mxTooltipHandler {
this.node = node; this.node = node;
this.stateSource = stateSource; this.stateSource = stateSource;
} }
}), this.delay); }, this.delay);
} }
} }
}; };

View File

@ -167,7 +167,7 @@ class mxVertexHandler {
this.init(); this.init();
// Handles escape keystrokes // Handles escape keystrokes
this.escapeHandler = mxUtils.bind(this, (sender, evt) => { this.escapeHandler = (sender, evt) => {
if (this.livePreview && this.index != null) { if (this.livePreview && this.index != null) {
// Redraws the live preview // Redraws the live preview
this.state.view.graph.cellRenderer.redraw(this.state, true); this.state.view.graph.cellRenderer.redraw(this.state, true);
@ -179,7 +179,7 @@ class mxVertexHandler {
} }
this.reset(); this.reset();
}); };
this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler); this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
} }
@ -485,7 +485,7 @@ class mxVertexHandler {
var hit = (this.allowHandleBoundsCheck && tol > 0) ? var hit = (this.allowHandleBoundsCheck && tol > 0) ?
new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null; new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
var checkShape = mxUtils.bind(this, (shape) => { var checkShape = (shape) => {
var st = (shape != null && shape.constructor != mxImageShape && var st = (shape != null && shape.constructor != mxImageShape &&
this.allowHandleBoundsCheck) ? shape.strokewidth + shape.svgStrokeTolerance : null; this.allowHandleBoundsCheck) ? shape.strokewidth + shape.svgStrokeTolerance : null;
var real = (st != null) ? new mxRectangle(me.getGraphX() - Math.floor(st / 2), var real = (st != null) ? new mxRectangle(me.getGraphX() - Math.floor(st / 2),
@ -493,7 +493,7 @@ class mxVertexHandler {
return shape != null && (me.isSource(shape) || (real != null && mxUtils.intersects(shape.bounds, real) && return shape != null && (me.isSource(shape) || (real != null && mxUtils.intersects(shape.bounds, real) &&
shape.node.style.display != 'none' && shape.node.style.visibility != 'hidden')); shape.node.style.display != 'none' && shape.node.style.visibility != 'hidden'));
}); };
if (checkShape(this.rotationShape)) { if (checkShape(this.rotationShape)) {
return mxEvent.ROTATION_HANDLE; return mxEvent.ROTATION_HANDLE;

View File

@ -98,7 +98,7 @@ class mxParallelEdgeLayout extends mxGraphLayout {
findParallels = (parent, cells) => { findParallels = (parent, cells) => {
var lookup = []; var lookup = [];
var addCell = mxUtils.bind(this, (cell) => { var addCell = (cell) => {
if (!this.isEdgeIgnored(cell)) { if (!this.isEdgeIgnored(cell)) {
var id = this.getEdgeId(cell); var id = this.getEdgeId(cell);
@ -110,7 +110,7 @@ class mxParallelEdgeLayout extends mxGraphLayout {
lookup[id].push(cell); lookup[id].push(cell);
} }
} }
}); };
if (cells != null) { if (cells != null) {
for (var i = 0; i < cells.length; i++) { for (var i = 0; i < cells.length; i++) {

View File

@ -265,14 +265,14 @@ class mxStackLayout extends mxGraphLayout {
} }
if (this.allowGaps) { if (this.allowGaps) {
cells.sort(mxUtils.bind(this, (c1, c2) => { cells.sort((c1, c2) => {
var geo1 = this.graph.getCellGeometry(c1); var geo1 = this.graph.getCellGeometry(c1);
var geo2 = this.graph.getCellGeometry(c2); var geo2 = this.graph.getCellGeometry(c2);
return (this.horizontal) ? return (this.horizontal) ?
((geo1.x == geo2.x) ? 0 : ((geo1.x > geo2.x > 0) ? 1 : -1)) : ((geo1.x == geo2.x) ? 0 : ((geo1.x > geo2.x > 0) ? 1 : -1)) :
((geo1.y == geo2.y) ? 0 : ((geo1.y > geo2.y > 0) ? 1 : -1)); ((geo1.y == geo2.y) ? 0 : ((geo1.y > geo2.y > 0) ? 1 : -1));
})); });
} }
return cells; return cells;

View File

@ -682,7 +682,7 @@ class mxText extends mxShape {
mxSvgCanvas2D.createCss(w + 2, h, this.align, this.valign, this.wrap, this.overflow, this.clipped, mxSvgCanvas2D.createCss(w + 2, h, this.align, this.valign, this.wrap, this.overflow, this.clipped,
(this.background != null) ? mxUtils.htmlEntities(this.background) : null, (this.background != null) ? mxUtils.htmlEntities(this.background) : null,
(this.border != null) ? mxUtils.htmlEntities(this.border) : null, (this.border != null) ? mxUtils.htmlEntities(this.border) : null,
flex, block, this.scale, mxUtils.bind(this, (dx, dy, flex, item, block, ofl) => { flex, block, this.scale, (dx, dy, flex, item, block, ofl) => {
var r = this.getTextRotation(); var r = this.getTextRotation();
var tr = ((this.scale != 1) ? 'scale(' + this.scale + ') ' : '') + var tr = ((this.scale != 1) ? 'scale(' + this.scale + ') ' : '') +
((r != 0) ? 'rotate(' + r + 'deg) ' : '') + ((r != 0) ? 'rotate(' + r + 'deg) ' : '') +
@ -719,7 +719,7 @@ class mxText extends mxShape {
this.node.firstChild.firstChild.setAttribute('style', block); this.node.firstChild.firstChild.setAttribute('style', block);
this.node.firstChild.setAttribute('style', item); this.node.firstChild.setAttribute('style', item);
})); });
}; };
/** /**

View File

@ -72,13 +72,13 @@ class mxDivResizer {
} }
mxEvent.addListener(container, 'resize', mxEvent.addListener(container, 'resize',
mxUtils.bind(this, (evt) => { (evt) => {
if (!this.handlingResize) { if (!this.handlingResize) {
this.handlingResize = true; this.handlingResize = true;
this.resize(); this.resize();
this.handlingResize = false; this.handlingResize = false;
} }
}) }
); );
this.resize(); this.resize();

View File

@ -370,12 +370,12 @@ var mxEvent =
var dy0 = 0; var dy0 = 0;
// Adds basic listeners for graph event dispatching // Adds basic listeners for graph event dispatching
mxEvent.addGestureListeners(target, mxUtils.bind(this, (evt) => { mxEvent.addGestureListeners(target, (evt) => {
if (!mxEvent.isMouseEvent(evt) && evt.pointerId != null) { if (!mxEvent.isMouseEvent(evt) && evt.pointerId != null) {
evtCache.push(evt); evtCache.push(evt);
} }
}), },
mxUtils.bind(this, (evt) => { (evt) => {
if (!mxEvent.isMouseEvent(evt) && evtCache.length == 2) { if (!mxEvent.isMouseEvent(evt) && evtCache.length == 2) {
// Find this event in the cache and update its record with this event // Find this event in the cache and update its record with this event
for (var i = 0; i < evtCache.length; i++) { for (var i = 0; i < evtCache.length; i++) {
@ -402,12 +402,12 @@ var mxEvent =
dy0 = dy; dy0 = dy;
} }
} }
}), },
mxUtils.bind(this, (evt) => { (evt) => {
evtCache = []; evtCache = [];
dx0 = 0; dx0 = 0;
dy0 = 0; dy0 = 0;
})); });
} }
mxEvent.addListener(target, 'wheel', wheelHandler); mxEvent.addListener(target, 'wheel', wheelHandler);

View File

@ -29,10 +29,16 @@ class mxPoint {
* Constructs a new point for the optional x and y coordinates. If no * Constructs a new point for the optional x and y coordinates. If no
* coordinates are given, then the default values for <x> and <y> are used. * coordinates are given, then the default values for <x> and <y> are used.
*/ */
constructor(x, y) { constructor(...args) {
// forward to this._constructor to allow not calling
// the constructor from mxRectangle/mxCellState
this._constructor(...args);
};
_constructor(x, y) {
this.x = (x != null) ? x : 0; this.x = (x != null) ? x : 0;
this.y = (y != null) ? y : 0; this.y = (y != null) ? y : 0;
}; }
/** /**
* Function: equals * Function: equals

View File

@ -30,11 +30,15 @@ class mxRectangle extends mxPoint {
*/ */
height = null; height = null;
constructor(x, y, width, height) { constructor(...args) {
super(x, y); super(...args);
};
_constructor(x, y, width, height) {
// replace super of mxPoint
this.width = (width != null) ? width : 0; this.width = (width != null) ? width : 0;
this.height = (height != null) ? height : 0; this.height = (height != null) ? height : 0;
}; }
/** /**
* Function: fromRectangle * Function: fromRectangle

View File

@ -2,6 +2,7 @@
* Copyright (c) 2006-2020, JGraph Ltd * Copyright (c) 2006-2020, JGraph Ltd
* Copyright (c) 2006-2020, draw.io AG * Copyright (c) 2006-2020, draw.io AG
*/ */
import mxUtils from "./mxUtils";
class mxXmlRequest { class mxXmlRequest {
/** /**
@ -205,7 +206,7 @@ class mxXmlRequest {
* Returns true if the response is ready. * Returns true if the response is ready.
*/ */
isReady = () => { isReady = () => {
return this.request.readyState == 4; return this.request.readyState === 4;
}; };
/** /**
@ -260,8 +261,6 @@ class mxXmlRequest {
* Creates and returns the inner <request> object. * Creates and returns the inner <request> object.
*/ */
create = () => { create = () => {
if (window.XMLHttpRequest) {
return () => {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
// TODO: Check for overrideMimeType required here? // TODO: Check for overrideMimeType required here?
@ -271,15 +270,6 @@ class mxXmlRequest {
return req; return req;
}; };
} else if (typeof (ActiveXObject) != 'undefined') {
return () => {
// TODO: Implement binary option
return new ActiveXObject('Microsoft.XMLHTTP');
};
}
}
()
;
/** /**
* Function: send * Function: send
@ -372,7 +362,7 @@ class mxXmlRequest {
doc = doc || document; doc = doc || document;
var old = null; var old = null;
if (doc == document) { if (doc === document) {
old = window.onbeforeunload; old = window.onbeforeunload;
window.onbeforeunload = null; window.onbeforeunload = null;
} }

View File

@ -158,8 +158,12 @@ class mxCellState extends mxRectangle {
* cell - <mxCell> that this state represents. * cell - <mxCell> that this state represents.
* style - Array of key, value pairs that constitute the style. * style - Array of key, value pairs that constitute the style.
*/ */
constructor(view, cell, style) { constructor(...args) {
// no super super(...args)
}
_constructor(view, cell, style) {
// replace super of mxPoint/mxRectangle
this.view = view; this.view = view;
this.cell = cell; this.cell = cell;
this.style = (style != null) ? style : {}; this.style = (style != null) ? style : {};

View File

@ -1519,9 +1519,9 @@ class mxGraph extends mxEventSource {
this.view = this.createGraphView(); this.view = this.createGraphView();
// Adds a graph model listener to update the view // Adds a graph model listener to update the view
this.graphModelChangeListener = mxUtils.bind(this, (sender, evt) => { this.graphModelChangeListener = (sender, evt) => {
this.graphModelChanged(evt.getProperty('edit').changes); this.graphModelChanged(evt.getProperty('edit').changes);
}); };
this.model.addListener(mxEvent.CHANGE, this.graphModelChangeListener); this.model.addListener(mxEvent.CHANGE, this.graphModelChangeListener);
@ -1752,7 +1752,7 @@ class mxGraph extends mxEventSource {
var dict = new mxDictionary(); var dict = new mxDictionary();
var cells = []; var cells = [];
var addCell = mxUtils.bind(this, (cell) => { var addCell = (cell) => {
if (!dict.get(cell) && this.model.contains(cell)) { if (!dict.get(cell) && this.model.contains(cell)) {
if (this.model.isEdge(cell) || this.model.isVertex(cell)) { if (this.model.isEdge(cell) || this.model.isVertex(cell)) {
dict.put(cell, true); dict.put(cell, true);
@ -1765,7 +1765,7 @@ class mxGraph extends mxEventSource {
} }
} }
} }
}); };
for (var i = 0; i < changes.length; i++) { for (var i = 0; i < changes.length; i++) {
var change = changes[i]; var change = changes[i];
@ -2134,11 +2134,11 @@ class mxGraph extends mxEventSource {
// Adds a handler for single mouseclicks to select the cell // Adds a handler for single mouseclicks to select the cell
if (isSelect) { if (isSelect) {
overlay.addListener(mxEvent.CLICK, overlay.addListener(mxEvent.CLICK,
mxUtils.bind(this, (sender, evt) => { (sender, evt) => {
if (this.isEnabled()) { if (this.isEnabled()) {
this.setSelectionCell(cell); this.setSelectionCell(cell);
} }
}) }
); );
} }
@ -2368,13 +2368,13 @@ class mxGraph extends mxEventSource {
var active = false; var active = false;
var tmp = this.getCellAt(me.graphX, me.graphY, null, null, null, var tmp = this.getCellAt(me.graphX, me.graphY, null, null, null,
mxUtils.bind(this, (state) => { (state) => {
var selected = this.isCellSelected(state.cell); var selected = this.isCellSelected(state.cell);
active = active || selected; active = active || selected;
return !active || selected || (state.cell != cell && return !active || selected || (state.cell != cell &&
this.model.isAncestor(state.cell, cell)); this.model.isAncestor(state.cell, cell));
})); });
if (tmp != null) { if (tmp != null) {
cell = tmp; cell = tmp;
@ -2916,7 +2916,7 @@ class mxGraph extends mxEventSource {
this.verticalPageBreaks = []; this.verticalPageBreaks = [];
} }
var drawPageBreaks = mxUtils.bind(this, (breaks) => { var drawPageBreaks = (breaks) => {
if (breaks != null) { if (breaks != null) {
var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount; var count = (breaks == this.horizontalPageBreaks) ? horizontalCount : verticalCount;
@ -2948,7 +2948,7 @@ class mxGraph extends mxEventSource {
breaks.splice(count, breaks.length - count); breaks.splice(count, breaks.length - count);
} }
}); };
drawPageBreaks(this.horizontalPageBreaks); drawPageBreaks(this.horizontalPageBreaks);
drawPageBreaks(this.verticalPageBreaks); drawPageBreaks(this.verticalPageBreaks);

View File

@ -473,14 +473,14 @@ class mxPrintPreview {
var vpages = Math.max(1, Math.ceil((bounds.height + this.y0) / availableHeight)); var vpages = Math.max(1, Math.ceil((bounds.height + this.y0) / availableHeight));
this.pageCount = hpages * vpages; this.pageCount = hpages * vpages;
var writePageSelector = mxUtils.bind(this, () => { var writePageSelector = () => {
if (this.pageSelector && (vpages > 1 || hpages > 1)) { if (this.pageSelector && (vpages > 1 || hpages > 1)) {
var table = this.createPageSelector(vpages, hpages); var table = this.createPageSelector(vpages, hpages);
doc.body.appendChild(table); doc.body.appendChild(table);
} }
}); };
var addPage = mxUtils.bind(this, (div, addBreak) => { var addPage = (div, addBreak) => {
// Border of the DIV (aka page) inside the document // Border of the DIV (aka page) inside the document
if (this.borderColor != null) { if (this.borderColor != null) {
div.style.borderColor = this.borderColor; div.style.borderColor = this.borderColor;
@ -525,7 +525,7 @@ class mxPrintPreview {
if (forcePageBreaks || addBreak) { if (forcePageBreaks || addBreak) {
this.addPageBreak(doc); this.addPageBreak(doc);
} }
}); };
var cov = this.getCoverPages(this.pageFormat.width, this.pageFormat.height); var cov = this.getCoverPages(this.pageFormat.width, this.pageFormat.height);
@ -921,9 +921,9 @@ class mxPrintPreview {
// Creates the temporary cell states in the view and // Creates the temporary cell states in the view and
// draws them onto the temporary DOM nodes in the view // draws them onto the temporary DOM nodes in the view
var cells = [this.getRoot()]; var cells = [this.getRoot()];
temp = new mxTemporaryCellStates(view, scale, cells, null, mxUtils.bind(this, (state) => { temp = new mxTemporaryCellStates(view, scale, cells, null, (state) => {
return this.getLinkForCellState(state); return this.getLinkForCellState(state);
})); });
} finally { } finally {
// Removes everything but the SVG node // Removes everything but the SVG node
var tmp = div.firstChild; var tmp = div.firstChild;