Commit 8410e0de authored by Piotr Gawron's avatar Piotr Gawron

Merge branch...

Merge branch '668-coordinates-of-context-menu-should-be-taken-from-the-event-not-guiconnector' into 'master'

Resolve "coordinates of context menu should be taken from the event not GuiConnector"

Closes #668

See merge request !819
parents f6171739 12c2f91d
Pipeline #10779 failed with stage
in 13 minutes and 51 seconds
......@@ -15,12 +15,6 @@ var ValidationError = require('./ValidationError');
*/
function GuiConnector() {
ObjectWithListeners.call(this);
// X coordinate of the mouse in a browser.
//@type {number}
this.xPos = 0;
// coordinate of the mouse in a browser.
//@type {number}
this.yPos = 0;
this.getParams = [];
......@@ -81,28 +75,8 @@ GuiConnector.prototype.init = function () {
self.getParams[decode(arguments[1])] = decode(arguments[2]);
});
self._touchStartEvent = function (e) {
if (e.originalEvent !== undefined) {
self.updateMouseCoordinates(e.originalEvent.touches[0].pageX, e.originalEvent.touches[0].pageY);
}
};
self._touchMoveEvent = function (e) {
if (e.originalEvent !== undefined) {
self.updateMouseCoordinates(e.originalEvent.touches[0].pageX, e.originalEvent.touches[0].pageY);
}
};
// force browser to update mouse coordinates whenever mouse move
jQuery(document).ready(function () {
$(document).mousemove(function (e) {
self.updateMouseCoordinates(e.pageX, e.pageY);
});
$(document).on('touchstart', self._touchStartEvent);
$(document).on('touchmove', self._touchMoveEvent);
});
document.addEventListener( 'keydown', function( event ) {
var caps = event.getModifierState && event.getModifierState( 'CapsLock' );
document.addEventListener('keydown', function (event) {
var caps = event.getModifierState && event.getModifierState('CapsLock');
if (self._caps !== caps) {
self._caps = caps;
return self.callListeners("onCapsLockChange", caps);
......@@ -126,7 +100,7 @@ GuiConnector.prototype.init = function () {
//sorting of datatable column by input value https://stackoverflow.com/a/29221907/1127920
$.fn.dataTable.ext.order['dom-input'] = function (settings, col) {
return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
return this.api().column(col, {order: 'index'}).nodes().map(function (td) {
return $('input', td).val();
});
}
......@@ -136,9 +110,9 @@ GuiConnector.prototype.init = function () {
var newUrl = "";
setInterval(function () {
if (global.window !== undefined && newUrl !== "") {
if (!global.window.location.href.endsWith(newUrl)) {
global.window.history.replaceState(null, null, newUrl);
if (window !== undefined && newUrl !== "") {
if (!window.location.href.endsWith(newUrl)) {
window.history.replaceState(null, null, newUrl);
}
}
}, 250);
......@@ -147,7 +121,7 @@ setInterval(function () {
/**
*
* @param {string} key
* @param {string} value
* @param {?null|string} value
*/
GuiConnector.prototype.setUrlParam = function (key, value) {
var self = this;
......@@ -201,14 +175,6 @@ GuiConnector.prototype.getLoadingImg = function () {
return "icons/ajax-loader.gif";
};
/**
*
* @returns {string}
*/
GuiConnector.prototype.getEmptyTileUrl = function () {
return "resources/images/empty_tile.png";
};
/**
* Returns home directory for images in the application.
* @returns {string}
......@@ -217,18 +183,6 @@ GuiConnector.prototype.getImgPrefix = function () {
return "resources/images/";
};
/**
* Updates coordinates of the mouse in the browser.
*
* @param {number} x
* @param {number} y
*/
GuiConnector.prototype.updateMouseCoordinates = function (x, y) {
var self = returnThisOrSingleton(this);
self.xPos = x;
self.yPos = y;
};
/**
*
* @param {string} [messageText]
......@@ -308,7 +262,6 @@ GuiConnector.prototype.showSuccessDialog = function (title, content) {
/**
* Gather information that are presented to the user before submission to MinervaNet.
*
* @param {string|Error} error The error that triggered the report sequence.
* @return {Promise}
*/
GuiConnector.prototype.gatherReportData = function () {
......@@ -507,16 +460,16 @@ GuiConnector.prototype.showConfirmationDialog = function (params) {
modal: true, title: title, zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
"Yes": function () {
$(this).dialog("close");
resolve(true);
},
No: function () {
"No": function () {
$(this).dialog("close");
resolve(false);
}
},
close: function (event, ui) {
close: function () {
$(this).remove();
}
});
......@@ -545,9 +498,6 @@ GuiConnector.prototype.destroy = function () {
}
self._windowResizeEvents = undefined;
$(document).off('touchstart', self._touchStartEvent);
$(document).off('touchmove', self._touchMoveEvent);
};
/**
......
......@@ -198,18 +198,18 @@ AbstractCustomMap.prototype.registerMapClickEvents = function () {
});
// context menu event
this.getMapCanvas().addListener('rightclick', function () {
return self.getTopMap().getContextMenu().open(GuiConnector.xPos, GuiConnector.yPos, new Date().getTime());
this.getMapCanvas().addListener('rightclick', function (e) {
return self.getTopMap().getContextMenu().open(e.arg.client.x, e.arg.client.y, new Date().getTime());
});
//long click should open context menu https://stackoverflow.com/a/38457006/1127920
var mousedUp = false;
$(self.getElement()).on("touchstart", function () {
$(self.getElement()).on("touchstart", function (e) {
mousedUp = false;
setTimeout(function () {
if (mousedUp === false) {
self.getTopMap().getContextMenu().open(GuiConnector.xPos, GuiConnector.yPos, new Date().getTime() + 250);
self.getTopMap().getContextMenu().open(e.touches[0].clientX, e.touches[0].clientY, new Date().getTime() + 250);
}
}, 500);
});
......@@ -231,7 +231,7 @@ AbstractCustomMap.prototype.registerMapClickEvents = function () {
customMap.setActiveSubmapId(self.getId());
// noinspection JSCheckFunctionSignatures
self.getTopMap().setSelectedPolygon(event.arg.polygon);
self.getTopMap().getSelectionContextMenu().open(GuiConnector.xPos, GuiConnector.yPos, new Date().getTime());
self.getTopMap().getSelectionContextMenu().open(event.arg.client.x, event.arg.client.y, new Date().getTime());
});
};
......
......@@ -40,8 +40,11 @@ function GoogleMapsApiCanvas(element, options) {
google.maps.event.addListener(this.getGoogleMap(), "click", function (e) {
return self.callListeners("click", {point: self.fromLatLngToPoint(e.latLng)});
});
google.maps.event.addListener(this.getGoogleMap(), "rightclick", function (e) {
return self.callListeners("rightclick", {point: self.fromLatLngToPoint(e.latLng)});
google.maps.event.addListener(this.getGoogleMap(), "rightclick", function (e, x) {
var offsetX = self.getElement().getBoundingClientRect().x;
var offsetY = self.getElement().getBoundingClientRect().y;
var client = new Point(e.pixel.x + offsetX, e.pixel.y + offsetY);
return self.callListeners("rightclick", {point: self.fromLatLngToPoint(e.latLng), client: client});
});
google.maps.event.addListener(this.getGoogleMap(), "mouseup", function () {
return self.callListeners("mouseup");
......@@ -452,7 +455,16 @@ GoogleMapsApiCanvas.prototype.turnOnDrawing = function () {
var polygon = self.areaToString(newShape);
return self.callListeners("shape-rightclick", {polygon: polygon});
var client = new Point(Number.NaN, Number.NaN);
for (var key in e) {
if (e.hasOwnProperty(key) && e[key] instanceof MouseEvent) {
client = new Point(e[key].clientX, e[key].clientY);
}
}
return self.callListeners("shape-rightclick", {polygon: polygon, client: client});
});
}
});
......
......@@ -93,9 +93,10 @@ function OpenLayerCanvas(element, options) {
});
self.setOpenLayersMap(map);
map.on("click", function (e) {
map.on("click", function (evt) {
var features = [];
map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
var client = new Point(evt.originalEvent.clientX, evt.originalEvent.clientY);
map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
features.push(feature);
if (layer === self._markerLayer) {
return feature.__openLayerMarker.callListeners("click");
......@@ -106,13 +107,13 @@ function OpenLayerCanvas(element, options) {
} else if (layer === self._drawingLayer) {
self.setSelectedArea(feature);
var polygon = self.featureToString(feature);
return self.callListeners("shape-rightclick", {polygon: polygon});
return self.callListeners("shape-rightclick", {polygon: polygon, client: client});
} else if (layer !== null) {
throw new Error("Unknown layer");
}
});
if (features.length === 0) { //we clicked on something - not directly on the map
var point = self.fromProjectionToPoint(e.coordinate);
var point = self.fromProjectionToPoint(evt.coordinate);
return self.callListeners("click", {point: point});
}
});
......@@ -120,6 +121,7 @@ function OpenLayerCanvas(element, options) {
//rightclick
map.getViewport().addEventListener('contextmenu', function (evt) {
evt.preventDefault();
var client = new Point(evt.clientX, evt.clientY);
var featureClicked;
map.forEachFeatureAtPixel(map.getEventPixel(evt), function (feature, layer) {
......@@ -130,11 +132,11 @@ function OpenLayerCanvas(element, options) {
if (featureClicked) {
self.setSelectedArea(featureClicked);
var polygon = self.featureToString(featureClicked);
return self.callListeners("shape-rightclick", {polygon: polygon});
return self.callListeners("shape-rightclick", {polygon: polygon, client: client});
} else {
var projectionPoint = map.getEventCoordinate(evt);
var point = self.fromProjectionToPoint(projectionPoint);
return self.callListeners("rightclick", {point: point});
return self.callListeners("rightclick", {point: point, client: client});
}
});
......@@ -545,8 +547,16 @@ OpenLayerCanvas.prototype.triggerEvent = function (type, data) {
map: map,
pixel: map.getPixelFromCoordinate(projection),
target: map,
type: type
type: type,
originalEvent: new MouseEvent("click")
};
if (mev.pixel !== null) {
var offsetX = self.getElement().getBoundingClientRect().x;
var offsetY = self.getElement().getBoundingClientRect().y;
mev.originalEvent.clientX = mev.pixel.x + offsetX;
mev.originalEvent.clientY = mev.pixel.x + offsetY;
}
return map.dispatchEvent(mev);
} else if (type === "rightclick") {
var clickEvent = new window.Event("contextmenu");
......
......@@ -9,6 +9,7 @@ var GuiConnector = require('./GuiConnector-mock');
var path = require('path');
global.window = undefined;
// -----------------------------
var logger = require('./logger');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment