Files
iD/modules/ui/tooltip.js
T

53 lines
1.2 KiB
JavaScript

import { utilFunctor } from '../util/util';
import { uiPopover } from './popover';
export function uiTooltip(klass) {
var tooltip = uiPopover((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;
}