gitlab-org--gitlab-foss/app/assets/javascripts/shared/popover.js

34 lines
839 B
JavaScript
Raw Normal View History

2018-03-23 15:13:54 -04:00
import $ from 'jquery';
import { debounce } from 'lodash';
2018-03-23 15:13:54 -04:00
2018-03-26 13:46:42 -04:00
export function togglePopover(show) {
2018-04-15 11:35:32 -04:00
const isAlreadyShown = this.hasClass('js-popover-show');
2018-03-26 13:46:42 -04:00
if ((show && isAlreadyShown) || (!show && !isAlreadyShown)) {
return false;
2018-03-21 14:23:33 -04:00
}
2018-04-15 11:35:32 -04:00
this.popover(show ? 'show' : 'hide');
this.toggleClass('disable-animation js-popover-show', show);
2018-03-21 14:23:33 -04:00
2018-03-26 13:46:42 -04:00
return true;
}
2018-03-21 14:23:33 -04:00
2018-03-26 13:46:42 -04:00
export function mouseleave() {
if (!$('.popover:hover').length > 0) {
const $popover = $(this);
togglePopover.call($popover, false);
2018-03-21 14:23:33 -04:00
}
2018-03-26 13:46:42 -04:00
}
2018-03-21 14:23:33 -04:00
2018-03-26 13:46:42 -04:00
export function mouseenter() {
const $popover = $(this);
2018-03-21 14:23:33 -04:00
2018-03-26 13:46:42 -04:00
const showedPopover = togglePopover.call($popover, true);
if (showedPopover) {
2018-03-27 13:17:36 -04:00
$('.popover').on('mouseleave', mouseleave.bind($popover));
2018-03-21 14:23:33 -04:00
}
}
2018-03-26 13:46:42 -04:00
export function debouncedMouseleave(debounceTimeout = 300) {
return debounce(mouseleave, debounceTimeout);
2018-03-27 11:15:18 -04:00
}