2017-11-13 01:23:39 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Tooltip Handling
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
import {createElement as e} from 'utilities/dom';
|
2017-11-14 04:11:43 -05:00
|
|
|
import {has, maybe_call} from 'utilities/object';
|
2017-11-13 01:23:39 -05:00
|
|
|
|
|
|
|
import Tooltip from 'utilities/tooltip';
|
|
|
|
import Module from 'utilities/module';
|
|
|
|
|
|
|
|
export default class TooltipProvider extends Module {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
this.types = {};
|
|
|
|
|
|
|
|
this.should_enable = true;
|
|
|
|
|
|
|
|
this.types.json = target => {
|
|
|
|
const title = target.dataset.title;
|
|
|
|
return [
|
|
|
|
title && e('strong', null, title),
|
|
|
|
e('code', {
|
|
|
|
className: `block${title ? ' pd-t-05 border-t mg-t-05' : ''}`,
|
|
|
|
style: {
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
textAlign: 'left'
|
|
|
|
}
|
|
|
|
}, target.dataset.data)
|
|
|
|
]
|
|
|
|
}
|
2017-12-21 20:37:58 -05:00
|
|
|
|
|
|
|
this.types.html = target => {
|
|
|
|
return target.dataset.title;
|
|
|
|
}
|
2017-11-13 01:23:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
onEnable() {
|
2018-03-24 04:19:41 -04:00
|
|
|
const container = document.querySelector('.twilight-root,.twilight-minimal-root') || document.body,
|
|
|
|
is_minimal = container && container.classList.contains('twilight-minimal-root');
|
2017-12-21 20:37:58 -05:00
|
|
|
|
2018-03-24 04:19:41 -04:00
|
|
|
this.tips = new Tooltip(is_minimal ? '.twilight-minimal-root' : 'body #root', 'ffz-tooltip', {
|
2017-11-13 01:23:39 -05:00
|
|
|
html: true,
|
2017-11-14 04:11:43 -05:00
|
|
|
delayHide: this.checkDelayHide.bind(this),
|
|
|
|
delayShow: this.checkDelayShow.bind(this),
|
2017-11-13 01:23:39 -05:00
|
|
|
content: this.process.bind(this),
|
2017-11-14 04:11:43 -05:00
|
|
|
interactive: this.checkInteractive.bind(this),
|
2017-11-13 01:23:39 -05:00
|
|
|
popper: {
|
2017-12-21 20:37:58 -05:00
|
|
|
placement: 'top',
|
|
|
|
modifiers: {
|
|
|
|
flip: {
|
|
|
|
behavior: ['top', 'bottom', 'left', 'right']
|
|
|
|
},
|
|
|
|
preventOverflow: {
|
|
|
|
boundariesElement: container
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 01:23:39 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-14 04:11:43 -05:00
|
|
|
checkDelayShow(target, tip) {
|
|
|
|
const type = target.dataset.tooltipType,
|
|
|
|
handler = this.types[type];
|
|
|
|
|
|
|
|
if ( has(handler, 'delayShow') )
|
|
|
|
return maybe_call(handler.delayShow, null, target, tip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkDelayHide(target, tip) {
|
|
|
|
const type = target.dataset.tooltipType,
|
|
|
|
handler = this.types[type];
|
|
|
|
|
|
|
|
if ( has(handler, 'delayHide') )
|
|
|
|
return maybe_call(handler.delayHide, null, target, tip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkInteractive(target, tip) {
|
|
|
|
const type = target.dataset.tooltipType,
|
|
|
|
handler = this.types[type];
|
|
|
|
|
|
|
|
if ( has(handler, 'interactive') )
|
|
|
|
return maybe_call(handler.interactive, null, target, tip);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
process(target, tip) {
|
2017-11-13 01:23:39 -05:00
|
|
|
const type = target.dataset.tooltipType,
|
|
|
|
handler = this.types[type];
|
|
|
|
|
|
|
|
if ( ! handler )
|
|
|
|
return [
|
|
|
|
e('strong', null, 'Unhandled Tooltip Type'),
|
|
|
|
e('code', {
|
|
|
|
className: 'block pd-t-05 border-t mg-t-05',
|
|
|
|
style: {
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
textAlign: 'left'
|
|
|
|
}
|
|
|
|
}, JSON.stringify(target.dataset, null, 4))
|
|
|
|
];
|
|
|
|
|
|
|
|
return handler(target, tip);
|
|
|
|
}
|
|
|
|
}
|