Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions browser/src/control/jsdialog/Widget.DrawingArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@
* }
*/

/* global JSDialog $ UNOKey app */
/* global JSDialog UNOKey app */

function _drawingAreaControl (parentContainer, data, builder) {
var container = window.L.DomUtil.create('div', builder.options.cssClass + ' ui-drawing-area-container', parentContainer);
container.id = data.id;

container.getCurrent = function () {
if (container.id == "") {
return document.getElementById(data.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to not query whole document, but the minimum required -> for example parentContainer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a clean way to do this; the element has been removed from the DOM (which is the entire problem), so no longer has a parent in the case that the id == "", and when the containing function is ran is the child of a document fragment, so the parent is also useless. It is possible f=by storing the parent after the element is removed:
https://github.com/celestial-starfruit/online/tree/private/maya/push-wwxovxkzppnp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the object under ref: parentContainer still valid? is that detached too?
I guess it migth be scroll window in the .ui in core which is replaced.
In that case - yes we can query the DOM to be safe.

} else {
return container;
}
};
if (!data.image)
return;

Expand Down Expand Up @@ -79,15 +86,8 @@ function _drawingAreaControl (parentContainer, data, builder) {

var getCoordinatesFromEvent = function (e) {
var imageElement = document.getElementById(imageId);
var ret = [0, 0];

if (e.offsetX) {
ret[0] = e.offsetX;
ret[1] = e.offsetY;
} else if (e.changedTouches && e.changedTouches.length) {
ret[0] = e.changedTouches[e.changedTouches.length-1].pageX - $(imageElement).offset().left;
ret[1] = e.changedTouches[e.changedTouches.length-1].pageY - $(imageElement).offset().top;
}
var boundingBox = imageElement.getBoundingClientRect();
var ret = [e.x - boundingBox.left, e.y - boundingBox.top];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we check with touch device (real not simulated) too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, really good point! Not sure how to test that at the moment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Minion3665 could you help?


ret[0] = ret[0] / imageElement.offsetWidth;
ret[1] = ret[1] / imageElement.offsetHeight;
Expand All @@ -105,7 +105,7 @@ function _drawingAreaControl (parentContainer, data, builder) {
clearTimeout(moveTimer);
moveTimer = null;
moveFunc = null;
builder.callback('drawingarea', 'dblclick', container, coordinates, builder);
builder.callback('drawingarea', 'dblclick', container.getCurrent(), coordinates, builder);
}, this);

window.L.DomEvent.on(image, 'click touchend', function(e) {
Expand All @@ -116,7 +116,7 @@ function _drawingAreaControl (parentContainer, data, builder) {
moveTimer = null;
moveFunc = null;

builder.callback('drawingarea', 'click', container, coordinates, builder);
builder.callback('drawingarea', 'click', container.getCurrent(), coordinates, builder);
}, this);

var onMove = function (e) {
Expand All @@ -129,7 +129,7 @@ function _drawingAreaControl (parentContainer, data, builder) {

var pos = getCoordinatesFromEvent(e);
var coordinates = pos[0] + ';' + pos[1];
builder.callback('drawingarea', 'mousemove', container, coordinates, builder);
builder.callback('drawingarea', 'mousemove', container.getCurrent(), coordinates, builder);
};

var endMove = function (e) {
Expand All @@ -142,14 +142,14 @@ function _drawingAreaControl (parentContainer, data, builder) {

var pos = getCoordinatesFromEvent(e);
var coordinates = pos[0] + ';' + pos[1];
builder.callback('drawingarea', 'mouseup', container, coordinates, builder);
builder.callback('drawingarea', 'mouseup', container.getCurrent(), coordinates, builder);
};

image.addEventListener('mousedown', function (e) {
moveFunc = function () {
var pos = getCoordinatesFromEvent(e);
var coordinates = pos[0] + ';' + pos[1];
builder.callback('drawingarea', 'mousedown', container, coordinates, builder);
builder.callback('drawingarea', 'mousedown', container.getCurrent(), coordinates, builder);
};

moveTimer = setTimeout(function () {
Expand All @@ -166,48 +166,48 @@ function _drawingAreaControl (parentContainer, data, builder) {

image.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
builder.callback('drawingarea', 'keypress', container, UNOKey.RETURN | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.RETURN | modifier, builder);
event.preventDefault();
} else if (event.key === 'Escape' || event.key === 'Esc') {
builder.callback('drawingarea', 'keypress', container, UNOKey.ESCAPE | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.ESCAPE | modifier, builder);
event.preventDefault();
} else if (event.key === 'Left' || event.key === 'ArrowLeft') {
builder.callback('drawingarea', 'keypress', container, UNOKey.LEFT | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.LEFT | modifier, builder);
event.preventDefault();
} else if (event.key === 'Right' || event.key === 'ArrowRight') {
builder.callback('drawingarea', 'keypress', container, UNOKey.RIGHT | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.RIGHT | modifier, builder);
event.preventDefault();
} else if (event.key === 'Up' || event.key === 'ArrowUp') {
builder.callback('drawingarea', 'keypress', container, UNOKey.UP | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.UP | modifier, builder);
event.preventDefault();
} else if (event.key === 'Down' || event.key === 'ArrowDown') {
builder.callback('drawingarea', 'keypress', container, UNOKey.DOWN | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.DOWN | modifier, builder);
event.preventDefault();
} else if (event.key === 'Home') {
builder.callback('drawingarea', 'keypress', container, UNOKey.HOME | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.HOME | modifier, builder);
event.preventDefault();
} else if (event.key === 'End') {
builder.callback('drawingarea', 'keypress', container, UNOKey.END | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.END | modifier, builder);
event.preventDefault();
} else if (event.key === 'Backspace') {
builder.callback('drawingarea', 'keypress', container, UNOKey.BACKSPACE | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.BACKSPACE | modifier, builder);
event.preventDefault();
} else if (event.key === 'Delete') {
builder.callback('drawingarea', 'keypress', container, UNOKey.DELETE | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.DELETE | modifier, builder);
event.preventDefault();
} else if (event.key === 'Space') {
builder.callback('drawingarea', 'keypress', container, UNOKey.SPACE | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.SPACE | modifier, builder);
event.preventDefault();
} else if (event.key === 'Tab') {
builder.callback('drawingarea', 'keypress', container, UNOKey.TAB | modifier, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.TAB | modifier, builder);
} else if (event.key === 'Shift') {
modifier = modifier | app.UNOModifier.SHIFT;
event.preventDefault();
} else if (event.key === 'Control') {
modifier = modifier | app.UNOModifier.CTRL;
event.preventDefault();
} else if (event.key === 'a' && event.ctrlKey) {
builder.callback('drawingarea', 'keypress', container, UNOKey.A | app.UNOModifier.CTRL, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), UNOKey.A | app.UNOModifier.CTRL, builder);
}
});

Expand Down Expand Up @@ -252,7 +252,7 @@ function _drawingAreaControl (parentContainer, data, builder) {
keyCode |= app.UNOModifier.CTRL;
}

builder.callback('drawingarea', 'keypress', container, keyCode, builder);
builder.callback('drawingarea', 'keypress', container.getCurrent(), keyCode, builder);
}

event.preventDefault();
Expand Down
Loading