Skip to content

Commit

Permalink
chore(context-pad): code style
Browse files Browse the repository at this point in the history
* we should not mix ES5 and >ES5 within a single file
  • Loading branch information
philippfromme authored and marstamm committed Jun 6, 2024
1 parent 6b887f1 commit d0810af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
29 changes: 16 additions & 13 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ContextPad.prototype._init = function() {
return;
}

var { target } = current;
var target = current.target;

var targets = isArray(target) ? target : [ target ];

Expand All @@ -132,8 +132,8 @@ ContextPad.prototype._init = function() {
}
});

this._eventBus.on('canvas.viewbox.changed', () => {
this._updatePosition();
this._eventBus.on('canvas.viewbox.changed', function() {
self._updatePosition();
});

this._eventBus.on('element.marker.update', function(event) {
Expand All @@ -158,7 +158,7 @@ ContextPad.prototype._init = function() {
};

ContextPad.prototype._createContainer = function() {
const container = domify('<div class="djs-context-pad-parent"></div>');
var container = domify('<div class="djs-context-pad-parent"></div>');

this._canvas.getContainer().appendChild(container);

Expand Down Expand Up @@ -242,6 +242,7 @@ ContextPad.prototype.getEntries = function(target) {
* @param {boolean} [autoActivate=false]
*/
ContextPad.prototype.trigger = function(action, event, autoActivate) {
var self = this;

var entry,
originalEvent,
Expand All @@ -255,8 +256,8 @@ ContextPad.prototype.trigger = function(action, event, autoActivate) {
originalEvent = event.originalEvent || event;

if (action === 'mouseover') {
this._timeout = setTimeout(() => {
this._mouseout = this.triggerEntry(entry, 'hover', originalEvent, autoActivate);
this._timeout = setTimeout(function() {
self._mouseout = self.triggerEntry(entry, 'hover', originalEvent, autoActivate);
}, HOVER_DELAY);

return;
Expand Down Expand Up @@ -577,12 +578,12 @@ ContextPad.prototype.hide = function() {
*/
ContextPad.prototype._getPosition = function(target) {
if (!isArray(target) && isConnection(target)) {
const viewbox = this._canvas.viewbox();
var viewbox = this._canvas.viewbox();

const lastWaypoint = getLastWaypoint(target);
var lastWaypoint = getLastWaypoint(target);

const x = lastWaypoint.x * viewbox.scale - viewbox.x * viewbox.scale,
y = lastWaypoint.y * viewbox.scale - viewbox.y * viewbox.scale;
var x = lastWaypoint.x * viewbox.scale - viewbox.x * viewbox.scale,
y = lastWaypoint.y * viewbox.scale - viewbox.y * viewbox.scale;

return {
left: x + CONTEXT_PAD_MARGIN * this._canvas.zoom(),
Expand Down Expand Up @@ -665,13 +666,15 @@ ContextPad.prototype._updateVisibility = function() {
* @returns {Rect & RectTRBL}
*/
ContextPad.prototype._getTargetBounds = function(target) {
var self = this;

var elements = isArray(target) ? target : [ target ];

var elementsGfx = elements.map((element) => {
return this._canvas.getGraphics(element);
var elementsGfx = elements.map(function(element) {
return self._canvas.getGraphics(element);
});

return elementsGfx.reduce((bounds, elementGfx) => {
return elementsGfx.reduce(function(bounds, elementGfx) {
const elementBounds = elementGfx.getBoundingClientRect();

bounds.top = Math.min(bounds.top, elementBounds.top);
Expand Down
14 changes: 7 additions & 7 deletions test/spec/features/context-pad/ContextPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ describe('features/context-pad', function() {
contextPad.trigger('click', event);

// then
const entry = contextPad._current.entries['action.c'];
var entry = contextPad._current.entries['action.c'];

expect(triggerSpy).to.have.been.calledOnce;
expect(triggerSpy.getCall(0).args[1]).to.eql({ entry, event });
Expand Down Expand Up @@ -1606,7 +1606,7 @@ describe('features/context-pad', function() {
var shape = canvas.addShape({ id: 's1', width: 100, height: 100, x: 10, y: 10 });

// when
const pad = contextPad.getPad(shape);
var pad = contextPad.getPad(shape);

// then
expect(pad).to.exist;
Expand All @@ -1624,7 +1624,7 @@ describe('features/context-pad', function() {
var spy = sinon.spy(contextPad, '_createHtml');

// when
const pad = contextPad.getPad(shape);
var pad = contextPad.getPad(shape);

// then
expect(pad).to.exist;
Expand All @@ -1642,7 +1642,7 @@ describe('features/context-pad', function() {
var spy = sinon.spy(contextPad, '_createHtml');

// when
const pad = contextPad.getPad([ shape ]);
var pad = contextPad.getPad([ shape ]);

// then
expect(pad).to.exist;
Expand All @@ -1660,7 +1660,7 @@ describe('features/context-pad', function() {
var spy = sinon.spy(contextPad, '_createHtml');

// when
const pad = contextPad.getPad(shape);
var pad = contextPad.getPad(shape);

// then
expect(pad).to.exist;
Expand All @@ -1679,7 +1679,7 @@ describe('features/context-pad', function() {
var spy = sinon.spy(contextPad, '_createHtml');

// when
const pad = contextPad.getPad(shape2);
var pad = contextPad.getPad(shape2);

// then
expect(pad).to.exist;
Expand All @@ -1705,7 +1705,7 @@ describe('features/context-pad', function() {
var shape = canvas.addShape({ id: 's1', width: 100, height: 100, x: 10, y: 10 });

// when
const pad = contextPad.getPad(shape);
var pad = contextPad.getPad(shape);

// then
expect(pad).to.exist;
Expand Down

0 comments on commit d0810af

Please sign in to comment.