-
Notifications
You must be signed in to change notification settings - Fork 958
Fix DrawingArea sending messages with an empty id #14009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } else { | ||
| return container; | ||
| } | ||
| }; | ||
| if (!data.image) | ||
| return; | ||
|
|
||
|
|
@@ -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]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we check with touch device (real not simulated) too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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) { | ||
|
|
@@ -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 () { | ||
|
|
@@ -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); | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -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(); | ||
|
|
||
There was a problem hiding this comment.
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
parentContainerThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
parentContainerstill 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.