debian-mirror-gitlab/app/assets/javascripts/feature_highlight/feature_highlight_helper.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import axios from '../lib/utils/axios_utils';
import { __ } from '../locale';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as Flash } from '../flash';
2018-03-17 18:26:18 +05:30
import LazyLoader from '../lazy_loader';
2018-10-15 14:42:47 +05:30
import { togglePopover } from '../shared/popover';
2018-03-17 18:26:18 +05:30
export const getSelector = highlightId => `.js-feature-highlight[data-highlight=${highlightId}]`;
export function dismiss(highlightId) {
2018-12-13 13:39:08 +05:30
axios
.post(this.attr('data-dismiss-endpoint'), {
feature_name: highlightId,
})
.catch(() =>
Flash(
__(
'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.',
),
),
);
2018-03-17 18:26:18 +05:30
togglePopover.call(this, false);
this.hide();
}
export function inserted() {
const popoverId = this.getAttribute('aria-describedby');
const highlightId = this.dataset.highlight;
const $popover = $(this);
const dismissWrapper = dismiss.bind($popover, highlightId);
2018-12-13 13:39:08 +05:30
$(`#${popoverId} .dismiss-feature-highlight`).on('click', dismissWrapper);
2018-03-17 18:26:18 +05:30
const lazyImg = $(`#${popoverId} .feature-highlight-illustration`)[0];
if (lazyImg) {
LazyLoader.loadImage(lazyImg);
}
}