Commit 68d9403f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

bootstrap popover has a new API

parent eb3b79f2
......@@ -55,9 +55,9 @@
"integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c="
},
"acorn-globals": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-4.3.0.tgz",
"integrity": "sha512-hMtHj3s5RnuhvHPowpBYvJVj3rAar82JiDQHvGs1zO0l10ocX/xEdBShNHTJaboucJUsScghp74pH3s7EnHHQw==",
"version": "4.3.3",
"resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-4.3.3.tgz",
"integrity": "sha512-vkR40VwS2SYO98AIeFvzWWh+xyc2qi9s7OoXSFEGIP/rOJKzjnhykaZJNnHdoq4BL2gGxI5EZOU16z896EYnOQ==",
"dev": true,
"requires": {
"acorn": "^6.0.1",
......@@ -65,17 +65,17 @@
},
"dependencies": {
"acorn": {
"version": "6.0.6",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.6.tgz",
"integrity": "sha512-5M3G/A4uBSMIlfJ+h9W125vJvPFH/zirISsW5qfxF5YzEvXJCtolLoQvM5yZft0DvMcUrPGKPOlgEu55I6iUtA==",
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.1.tgz",
"integrity": "sha512-JD0xT5FCRDNyjDda3Lrg/IxFscp9q4tiYtxE1/nOzlKCk7hIRuYjhq1kCNkbPjMRMZuFq20HNQn1I9k8Oj0E+Q==",
"dev": true
}
}
},
"acorn-walk": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.1.tgz",
"integrity": "sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw==",
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz",
"integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==",
"dev": true
},
"after": {
......@@ -1140,9 +1140,9 @@
"integrity": "sha1-xtJnJjKi5cg+AT5oZKQs6N79IK4="
},
"cssom": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.4.tgz",
"integrity": "sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==",
"version": "0.3.8",
"resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz",
"integrity": "sha512-b0tGHbfegbhPJpxpiBPU2sCkigAqtM9O121le6bbOlgyV+NyGyCmVfJ6QW9eRjz8CpNfWEOYBIMIGRYkLwsIYg==",
"dev": true
},
"cssstyle": {
......@@ -2526,12 +2526,6 @@
"xtend": "^4.0.0"
}
},
"ip-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-3.0.0.tgz",
"integrity": "sha512-T8wDtjy+Qf2TAPDQmBp0eGKJ8GavlWlUnamr3wRn6vvdZlKVuJXXMlSncYFRYgVHOM3If5NR1H4+OvVQU9Idvg==",
"dev": true
},
"is-buffer": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.5.tgz",
......@@ -2849,9 +2843,9 @@
"dev": true
},
"escodegen": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.11.0.tgz",
"integrity": "sha512-IeMV45ReixHS53K/OmfKAIztN/igDHzTJUhZM3k1jMhIZWjk45SMwAtBsEXiJp3vSPmTcu6CXn7mDvFHRN66fw==",
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.11.1.tgz",
"integrity": "sha512-JwiqFD9KdGVVpeuRa68yU3zZnBEOcPs0nKW7wZzXky8Z7tffdYUHbe11bPCV5jYlK6DVdKLWLm0f5I/QlL0Kmw==",
"dev": true,
"requires": {
"esprima": "^3.1.3",
......@@ -4515,23 +4509,31 @@
}
},
"request-promise-core": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.1.tgz",
"integrity": "sha1-Pu4AssWqgyOc+wTFcA2jb4HNCLY=",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz",
"integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==",
"dev": true,
"requires": {
"lodash": "^4.13.1"
"lodash": "^4.17.11"
},
"dependencies": {
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
"dev": true
}
}
},
"request-promise-native": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.5.tgz",
"integrity": "sha1-UoF3D2jgyXGeUWP9P6tIIhX0/aU=",
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.7.tgz",
"integrity": "sha512-rIMnbBdgNViL37nZ1b3L/VfPOpSi0TqVDQPAvO6U14lMzOLrt5nilxCQqtDKhZeDiW0/hkCXGoQjhgJd/tCh6w==",
"dev": true,
"requires": {
"request-promise-core": "1.1.1",
"stealthy-require": "^1.1.0",
"tough-cookie": ">=2.3.3"
"request-promise-core": "1.1.2",
"stealthy-require": "^1.1.1",
"tough-cookie": "^2.3.3"
},
"dependencies": {
"punycode": {
......@@ -4541,12 +4543,11 @@
"dev": true
},
"tough-cookie": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.0.tgz",
"integrity": "sha512-LHMvg+RBP/mAVNqVbOX8t+iJ+tqhBA/t49DuI7+IDAWHrASnesqSu1vWbKB7UrE2yk+HMFUBMadRGMkB4VCfog==",
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
"dev": true,
"requires": {
"ip-regex": "^3.0.0",
"psl": "^1.1.28",
"punycode": "^2.1.1"
}
......@@ -5217,9 +5218,9 @@
}
},
"symbol-tree": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=",
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
"integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==",
"dev": true
},
"syntax-error": {
......
......@@ -84,5 +84,9 @@ GoogleMapsApiInfoWindow.prototype.setMarker = function (marker) {
this._marker = marker.getGoogleMarker();
};
GoogleMapsApiInfoWindow.prototype.destroy = function () {
//do nothing
};
module.exports = GoogleMapsApiInfoWindow;
......@@ -60,5 +60,12 @@ InfoWindow.prototype.setContent = function (content) {
throw new Error("Not implemented");
};
/**
*
*/
InfoWindow.prototype.destroy = function () {
throw new Error("Not implemented");
};
module.exports = InfoWindow;
"use strict";
var $ = require('jquery');
require('bootstrap');
var InfoWindow = require('../InfoWindow');
var OpenLayerMarker = require('./OpenLayerMarker');
......@@ -11,53 +12,9 @@ var Functions = require('../../../Functions');
var Promise = require('bluebird');
/**
* https://stackoverflow.com/a/45092467/1127920
*/
function modifyPopover() {
if ($.fn.popover.Constructor.prototype.reposition === undefined) {
$.fn.popover.Constructor.prototype.reposition = function () {
var $tip = this.tip();
var placement = typeof this.options.placement === 'function' ? this.options.placement.call(this, $tip[0], this.$element[0]) : this.options.placement;
var autoToken = /\s?auto?\s?/i;
var autoPlace = autoToken.test(placement);
if (autoPlace) placement = placement.replace(autoToken, '') || 'top';
var pos = this.getPosition();
var actualWidth = $tip[0].offsetWidth;
var actualHeight = $tip[0].offsetHeight;
if (autoPlace) {
var orgPlacement = placement;
var viewportDim = this.getPosition(this.$viewport);
placement = placement === 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' :
placement === 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' :
placement === 'right' && pos.right + actualWidth > viewportDim.width ? 'left' :
placement === 'left' && pos.left - actualWidth < viewportDim.left ? 'right' :
placement;
$tip
.removeClass(orgPlacement)
.addClass(placement)
}
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight);
this.applyPlacement(calculatedOffset, placement);
this.$element[0].__calculatedToolTipOffset = calculatedOffset;
}
}
}
function OpenLayerInfoWindow(options) {
InfoWindow.call(this, options);
modifyPopover();
var self = this;
if (options.marker !== undefined) {
......@@ -109,28 +66,6 @@ OpenLayerInfoWindow.prototype.updatePosition = function () {
popup.setOffset([0, 0]);
}
popup.setPosition(position);
return Promise.delay(100).then(function () {
var oldOffset = self._element.__calculatedToolTipOffset;
var oldDy = 0;
if (oldOffset) {
oldDy = oldOffset.top;
}
$(self._element).popover('reposition');
var dy = self._element.__calculatedToolTipOffset.top;
if (!self.isOpened()) {
self._element.__calculatedToolTipOffset = oldOffset;
} else {
var mapOffset = self.getMap().getElement().getBoundingClientRect();
if (dy < mapOffset.y && self.isOpened() && oldDy !== dy) {
dy -= mapOffset.y;
dy *= self.getMap().zoomFactor / Math.pow(2, self.getMap().getZoom());
var center = self.getMap().getCenter();
center.y += dy;
return self.getMap().setCenter(center);
}
}
});
};
OpenLayerInfoWindow.prototype.open = function () {
......@@ -205,5 +140,8 @@ OpenLayerInfoWindow.prototype.isOpened = function () {
return this._visible;
};
OpenLayerInfoWindow.prototype.destroy = function () {
$(this._element).popover('dispose');
};
module.exports = OpenLayerInfoWindow;
......@@ -174,24 +174,24 @@ AbstractInfoWindow.prototype.createOverlayInfoDiv = function (overlay, data) {
if (alias !== undefined) {
if (alias.getType() !== undefined) {
if (overlay.name === "drug") {
if (alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
if (alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
alias.getType().toUpperCase() === "GENE") {
return this._createDrugInfoDiv(overlay, data);
} else {
return null;
}
} else if (overlay.name === "chemical") {
if (this.alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
if (this.alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
alias.getType().toUpperCase() === "GENE") {
return this._createChemicalInfoDiv(overlay, data);
} else {
return null;
}
} else if (overlay.name === "mirna") {
if (alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
if (alias.getType().toUpperCase() === "RNA" ||
alias.getType().toUpperCase() === "PROTEIN" ||
alias.getType().toUpperCase() === "GENE") {
return this._createMiRnaInfoDiv(overlay, data);
} else {
......@@ -740,4 +740,11 @@ AbstractInfoWindow.prototype.getPosition = function () {
throw new Error("Not Implemented");
};
AbstractInfoWindow.prototype.destroy = function () {
var infoWindow = this._infoWindow;
if (infoWindow !== null && infoWindow !== undefined) {
return infoWindow.destroy();
}
};
module.exports = AbstractInfoWindow;
......@@ -45,6 +45,8 @@ describe('ReactionInfoWindow', function () {
});
return reactionWindow.init().then(function () {
return reactionWindow.open();
}).finally(function(){
return reactionWindow.destroy();
})
});
});
......
......@@ -22,7 +22,7 @@ function mockEnvironment() {
Hub: {
Config: function () {
},
Queue: function(){
Queue: function () {
}
}
......@@ -49,6 +49,20 @@ function mockEnvironment() {
global.document.elementFromPoint = function () {
};
// https://github.com/FezVrasta/popper.js/issues/478#issuecomment-407422016
global.document.createRange = function () {
return {
setStart: function () {
},
setEnd: function () {
},
commonAncestorContainer: {
nodeName: 'BODY',
ownerDocument: document
}
}
};
// additions to jsdom implementations:
global.Option = window.Option;
global.Blob = window.Blob;
......@@ -58,6 +72,7 @@ function mockEnvironment() {
global.getComputedStyle = window.getComputedStyle;
global.Image = window.Image;
global.Node = {DOCUMENT_POSITION_FOLLOWING: 4};
window.open = function () {
var result = {};
result.focus = function () {
......@@ -136,10 +151,12 @@ function mockEnvironment() {
//open layers uses this function
global.requestAnimationFrame = function () {
};
global.CanvasPattern = function(){
global.cancelAnimationFrame = function () {
};
global.CanvasPattern = function () {
};
global.CanvasGradient = function(){
global.CanvasGradient = function () {
};
......
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