2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2018-01-11 04:16:27 +00:00
|
|
|
import {
|
|
|
|
getSelector,
|
|
|
|
inserted,
|
2018-03-27 17:17:36 +00:00
|
|
|
} from './feature_highlight_helper';
|
|
|
|
import {
|
|
|
|
togglePopover,
|
2018-01-11 04:16:27 +00:00
|
|
|
mouseenter,
|
2018-03-26 17:46:42 +00:00
|
|
|
debouncedMouseleave,
|
2018-03-27 17:17:36 +00:00
|
|
|
} from '../shared/popover';
|
2018-01-11 04:16:27 +00:00
|
|
|
|
|
|
|
export function setupFeatureHighlightPopover(id, debounceTimeout = 300) {
|
|
|
|
const $selector = $(getSelector(id));
|
|
|
|
const $parent = $selector.parent();
|
|
|
|
const $popoverContent = $parent.siblings('.feature-highlight-popover-content');
|
|
|
|
const hideOnScroll = togglePopover.bind($selector, false);
|
|
|
|
|
|
|
|
$selector
|
|
|
|
// Setup popover
|
|
|
|
.data('content', $popoverContent.prop('outerHTML'))
|
|
|
|
.popover({
|
|
|
|
html: true,
|
|
|
|
// Override the existing template to add custom CSS classes
|
|
|
|
template: `
|
|
|
|
<div class="popover feature-highlight-popover" role="tooltip">
|
|
|
|
<div class="arrow"></div>
|
2018-05-21 16:48:06 +00:00
|
|
|
<div class="popover-body"></div>
|
2018-01-11 04:16:27 +00:00
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
.on('mouseenter', mouseenter)
|
2018-03-26 17:46:42 +00:00
|
|
|
.on('mouseleave', debouncedMouseleave(debounceTimeout))
|
2018-01-11 04:16:27 +00:00
|
|
|
.on('inserted.bs.popover', inserted)
|
2018-04-13 17:01:05 +00:00
|
|
|
.on('show.bs.popover', () => {
|
|
|
|
window.addEventListener('scroll', hideOnScroll, { once: true });
|
2018-01-11 04:16:27 +00:00
|
|
|
})
|
|
|
|
// Display feature highlight
|
|
|
|
.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findHighestPriorityFeature() {
|
|
|
|
let priorityFeature;
|
|
|
|
|
|
|
|
const sortedFeatureEls = [].slice.call(document.querySelectorAll('.js-feature-highlight')).sort((a, b) =>
|
|
|
|
(a.dataset.highlightPriority || 0) < (b.dataset.highlightPriority || 0));
|
|
|
|
|
|
|
|
const [priorityFeatureEl] = sortedFeatureEls;
|
|
|
|
if (priorityFeatureEl) {
|
|
|
|
priorityFeature = priorityFeatureEl.dataset.highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priorityFeature;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function highlightFeatures() {
|
|
|
|
const priorityFeature = findHighestPriorityFeature();
|
|
|
|
|
|
|
|
if (priorityFeature) {
|
|
|
|
setupFeatureHighlightPopover(priorityFeature);
|
|
|
|
}
|
|
|
|
|
|
|
|
return priorityFeature;
|
|
|
|
}
|