Skip to content
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

Simplify and fix ngeo Popover #5189

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions contribs/gmf/src/sass/map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,8 @@ button[ngeo-mobile-geolocation] {
height: inherit;
}
}

.gmf-permalink-tooltip {
white-space: nowrap;
margin-right: 2em;
}
69 changes: 24 additions & 45 deletions src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,26 @@ import olOverlay from 'ol/Overlay.js';
*/
export default class extends olOverlay {
constructor(options = {}) {
super(options);

let originalEl;
if (options.element) {
originalEl = options.element;
delete options.element;
} else {
originalEl = $('<div />')[0];
}
const originalEl = options.element ? options.element : document.createElement('div');
options.element = document.createElement('div');

super(options);

/**
* @type {JQuery}
* @private
*/
this.closeEl_ = $('<button>', {
'class': 'close',
'html': '&times;'
});
const closeEl = document.createElement('div');
closeEl.className = 'close';
closeEl.innerHTML = '&times;';
closeEl.addEventListener('click', this.close.bind(this));

/**
* @type {JQuery}
* @private
*/
this.contentEl_ = $('<div/>')
.append(this.closeEl_)
.append(originalEl);
this.contentEl_ = document.createElement('div');
this.contentEl_.append(closeEl, originalEl);
}

options.element = $('<div />')[0];
close() {
const map = this.getMap();
if (map) {
map.removeOverlay(this);
}
}

/**
Expand All @@ -50,33 +42,20 @@ export default class extends olOverlay {
$(element).popover('dispose');
}

olOverlay.prototype.setMap.call(this, map);
super.setMap(map);

if (map) {
const contentEl = this.contentEl_;
// wait for the overlay to be rendered in the map before popping over
window.setTimeout(() => {
$(element)
.popover({
content: contentEl.get()[0],
html: true,
placement: 'top',
template: [
'<div class="popover ngeo-popover" role="tooltip">',
' <div class="arrow"></div>',
' <h3 class="popover-header"></h3>',
' <div class="popover-body"></div>',
'</div>'
].join('')
}).popover('show');
$(element).popover({
container: element.parentElement,
placement: 'top',
content: contentEl,
html: true
});
$(element).popover('show');
}, 0);

this.closeEl_.one('click', () => {
const map = this.getMap();
if (map) {
map.removeOverlay(this);
}
});
}
}
}