mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Generalize tooltip into popover control Use the same popover control for tooltip as the preset browser and tools list popovers Smartly position the preset browser popover and menu bar tooltips to stay fully onscreen Position most tooltips closer to their controls Fix small gap that could appear between a tooltip and its arrow Allow wider toolbar tooltips
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import { utilFunctor } from './util';
|
|
import { popover } from './popover';
|
|
|
|
export function tooltip(klass) {
|
|
|
|
var tooltip = popover((klass || '') + ' tooltip')
|
|
.displayType('hover');
|
|
|
|
var _title = function() {
|
|
var title = this.getAttribute('data-original-title');
|
|
if (title) {
|
|
return title;
|
|
} else {
|
|
title = this.getAttribute('title');
|
|
this.removeAttribute('title');
|
|
this.setAttribute('data-original-title', title);
|
|
}
|
|
return title;
|
|
};
|
|
var _html = utilFunctor(false);
|
|
|
|
|
|
tooltip.title = function(val) {
|
|
if (arguments.length) {
|
|
_title = utilFunctor(val);
|
|
return tooltip;
|
|
} else {
|
|
return _title;
|
|
}
|
|
};
|
|
|
|
|
|
tooltip.html = function(val) {
|
|
if (arguments.length) {
|
|
_html = utilFunctor(val);
|
|
return tooltip;
|
|
} else {
|
|
return _html;
|
|
}
|
|
};
|
|
|
|
tooltip.content(function() {
|
|
var content = _title.apply(this, arguments);
|
|
var markup = _html.apply(this, arguments);
|
|
|
|
return function(selection) {
|
|
selection[markup ? 'html' : 'text'](content);
|
|
};
|
|
});
|
|
|
|
return tooltip;
|
|
}
|