1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
import Cookies from 'js-cookie';
import {
getCookieName,
getSelector,
hidePopover,
setupDismissButton,
mouseenter,
mouseleave,
} from './feature_highlight';
export default class FeatureHighlightManager {
constructor(highlightOrder) {
this.highlightOrder = highlightOrder;
}
init() {
const featureId = this.highlightOrder.find(FeatureHighlightManager.shouldHighlightFeature);
if (featureId) {
FeatureHighlightManager.highlightFeature(featureId);
window.addEventListener('scroll', () => {
const $featureHighlight = $(getSelector(featureId));
hidePopover.call($featureHighlight);
});
}
}
static shouldHighlightFeature(id) {
const element = document.querySelector(getSelector(id));
const previouslyDismissed = Cookies.get(getCookieName(id)) === 'true';
return element && !previouslyDismissed;
}
static highlightFeature(id) {
const $selector = $(getSelector(id));
const $parent = $selector.parent();
const $popoverContent = $parent.siblings('.feature-highlight-popover-content');
$selector
// Setup popover
.data('content', $popoverContent[0].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>
<div class="popover-content"></div>
</div>
`,
})
.on('mouseenter', mouseenter)
.on('mouseleave', mouseleave)
.on('inserted.bs.popover', setupDismissButton)
// Display feature highlight
.removeAttr('disabled');
}
}
|