2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-12-13 13:39:08 +05:30
|
|
|
import { getSelector, inserted } from './feature_highlight_helper';
|
|
|
|
import { togglePopover, mouseenter, debouncedMouseleave } from '../shared/popover';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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
|
2018-12-05 23:21:45 +05:30
|
|
|
// Set up popover
|
2018-03-17 18:26:18 +05:30
|
|
|
.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-11-08 19:23:39 +05:30
|
|
|
<div class="popover-body"></div>
|
2018-03-17 18:26:18 +05:30
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
.on('mouseenter', mouseenter)
|
2018-10-15 14:42:47 +05:30
|
|
|
.on('mouseleave', debouncedMouseleave(debounceTimeout))
|
2018-03-17 18:26:18 +05:30
|
|
|
.on('inserted.bs.popover', inserted)
|
|
|
|
.on('show.bs.popover', () => {
|
2018-10-15 14:42:47 +05:30
|
|
|
window.addEventListener('scroll', hideOnScroll, { once: true });
|
2018-03-17 18:26:18 +05:30
|
|
|
})
|
|
|
|
// Display feature highlight
|
|
|
|
.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
const getPriority = e => parseInt(e.dataset.highlightPriority, 10) || 0;
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
export function findHighestPriorityFeature() {
|
|
|
|
let priorityFeature;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const sortedFeatureEls = [].slice
|
|
|
|
.call(document.querySelectorAll('.js-feature-highlight'))
|
2019-03-02 22:35:43 +05:30
|
|
|
.sort((a, b) => getPriority(b) - getPriority(a));
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
const [priorityFeatureEl] = sortedFeatureEls;
|
|
|
|
if (priorityFeatureEl) {
|
|
|
|
priorityFeature = priorityFeatureEl.dataset.highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return priorityFeature;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function highlightFeatures() {
|
|
|
|
const priorityFeature = findHighestPriorityFeature();
|
|
|
|
|
|
|
|
if (priorityFeature) {
|
|
|
|
setupFeatureHighlightPopover(priorityFeature);
|
|
|
|
}
|
|
|
|
|
|
|
|
return priorityFeature;
|
|
|
|
}
|