Commit 60432a4a authored by Luke Bennett's avatar Luke Bennett

review

parent 08290d2c
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
togglePopover, togglePopover,
inserted, inserted,
mouseenter, mouseenter,
mouseleave, debouncedMouseleave,
} from './feature_highlight_helper'; } from './feature_highlight_helper';
export function setupFeatureHighlightPopover(id, debounceTimeout = 300) { export function setupFeatureHighlightPopover(id, debounceTimeout = 300) {
...@@ -13,7 +13,6 @@ export function setupFeatureHighlightPopover(id, debounceTimeout = 300) { ...@@ -13,7 +13,6 @@ export function setupFeatureHighlightPopover(id, debounceTimeout = 300) {
const $parent = $selector.parent(); const $parent = $selector.parent();
const $popoverContent = $parent.siblings('.feature-highlight-popover-content'); const $popoverContent = $parent.siblings('.feature-highlight-popover-content');
const hideOnScroll = togglePopover.bind($selector, false); const hideOnScroll = togglePopover.bind($selector, false);
const debouncedMouseleave = _.debounce(mouseleave, debounceTimeout);
$selector $selector
// Setup popover // Setup popover
...@@ -29,7 +28,7 @@ export function setupFeatureHighlightPopover(id, debounceTimeout = 300) { ...@@ -29,7 +28,7 @@ export function setupFeatureHighlightPopover(id, debounceTimeout = 300) {
`, `,
}) })
.on('mouseenter', mouseenter) .on('mouseenter', mouseenter)
.on('mouseleave', debouncedMouseleave) .on('mouseleave', debouncedMouseleave(debounceTimeout))
.on('inserted.bs.popover', inserted) .on('inserted.bs.popover', inserted)
.on('show.bs.popover', () => { .on('show.bs.popover', () => {
window.addEventListener('scroll', hideOnScroll); window.addEventListener('scroll', hideOnScroll);
......
...@@ -3,20 +3,10 @@ import axios from '../lib/utils/axios_utils'; ...@@ -3,20 +3,10 @@ import axios from '../lib/utils/axios_utils';
import { __ } from '../locale'; import { __ } from '../locale';
import Flash from '../flash'; import Flash from '../flash';
import LazyLoader from '../lazy_loader'; import LazyLoader from '../lazy_loader';
import { togglePopover, mouseenter, debouncedMouseleave } from '../shared/popover';
export const getSelector = highlightId => `.js-feature-highlight[data-highlight=${highlightId}]`; export const getSelector = highlightId => `.js-feature-highlight[data-highlight=${highlightId}]`;
export function togglePopover(show) {
const isAlreadyShown = this.hasClass('js-popover-show');
if ((show && isAlreadyShown) || (!show && !isAlreadyShown)) {
return false;
}
this.popover(show ? 'show' : 'hide');
this.toggleClass('disable-animation js-popover-show', show);
return true;
}
export function dismiss(highlightId) { export function dismiss(highlightId) {
axios.post(this.attr('data-dismiss-endpoint'), { axios.post(this.attr('data-dismiss-endpoint'), {
feature_name: highlightId, feature_name: highlightId,
...@@ -27,23 +17,6 @@ export function dismiss(highlightId) { ...@@ -27,23 +17,6 @@ export function dismiss(highlightId) {
this.hide(); this.hide();
} }
export function mouseleave() {
if (!$('.popover:hover').length > 0) {
const $featureHighlight = $(this);
togglePopover.call($featureHighlight, false);
}
}
export function mouseenter() {
const $featureHighlight = $(this);
const showedPopover = togglePopover.call($featureHighlight, true);
if (showedPopover) {
$('.popover')
.on('mouseleave', mouseleave.bind($featureHighlight));
}
}
export function inserted() { export function inserted() {
const popoverId = this.getAttribute('aria-describedby'); const popoverId = this.getAttribute('aria-describedby');
const highlightId = this.dataset.highlight; const highlightId = this.dataset.highlight;
...@@ -58,3 +31,5 @@ export function inserted() { ...@@ -58,3 +31,5 @@ export function inserted() {
LazyLoader.loadImage(lazyImg); LazyLoader.loadImage(lazyImg);
} }
} }
export { togglePopover, mouseenter, debouncedMouseleave };
import $ from 'jquery'; import $ from 'jquery';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
import flash from './flash'; import flash from './flash';
import Popover from './shared/popover'; import { mouseenter, debouncedMouseleave } from './shared/popover';
export default class Milestone { export default class Milestone {
constructor() { constructor() {
...@@ -47,14 +47,20 @@ export default class Milestone { ...@@ -47,14 +47,20 @@ export default class Milestone {
} }
static initDeprecationMessage() { static initDeprecationMessage() {
const deprecationMesssage = document.querySelector('.milestone-deprecation-message'); const deprecationMesssageContainer = document.querySelector('.milestone-deprecation-message');
if (!deprecationMesssage) return; if (!deprecationMesssageContainer) return;
const deprecationMesssageTemplate = deprecationMesssage.querySelector('.milestone-deprecation-message-template').innerHTML; const deprecationMessage = deprecationMesssageContainer.querySelector('.milestone-deprecation-message-template').innerHTML;
const popoverLink = deprecationMesssage.querySelector('.popover-link'); const popoverLink = deprecationMesssageContainer.querySelector('.popover-link');
const popover = new Popover(popoverLink, deprecationMesssageTemplate); $(popoverLink).popover({
popover.init(); content: deprecationMessage,
html: true,
placement: 'bottom',
trigger: 'manual',
})
.on('mouseenter', mouseenter)
.on('mouseleave', debouncedMouseleave());
} }
} }
import $ from 'jquery'; import $ from 'jquery';
import { debounce } from 'underscore';
export default class Popover { export function togglePopover(show) {
constructor(trigger, content) { const isAlreadyShown = this.hasClass('js-popover-show');
this.isOpen = false; if ((show && isAlreadyShown) || (!show && !isAlreadyShown)) {
return false;
this.$popover = $(trigger).popover({
content,
html: true,
placement: 'bottom',
trigger: 'manual',
});
}
init() {
this.registerClickOpenListener();
}
openPopover() {
if (this.isOpen) return;
this.$popover.popover('show');
this.$popover.one('shown.bs.popover', this.enableClose.bind(this));
this.isOpen = true;
}
closePopover() {
if (!this.isOpen) return;
this.$popover.popover('hide');
this.disableClose();
this.isOpen = false;
}
closePopoverClick(event) {
const $target = $(event.target);
if ($target.is(this.$popover) ||
$target.is('.popover') ||
$target.parents('.popover').length > 0) return;
this.closePopover();
}
closePopoverMouseleave() {
if (this.$popover.is(':hover') ||
(this.$popover.siblings('.popover').length > 0 &&
this.$popover.siblings('.popover').is(':hover'))) return;
this.closePopover();
}
closePopoverMouseleaveDelayed() {
setTimeout(this.closePopoverMouseleave.bind(this), 1500);
}
registerClickOpenListener() {
this.$popover.on('click.glPopover.open', this.openPopover.bind(this));
}
registerClickCloseListener() {
$(document.body).on('click.glPopover.close', this.closePopoverClick.bind(this));
} }
this.popover(show ? 'show' : 'hide');
this.toggleClass('disable-animation js-popover-show', show);
registerMouseleaveCloseListener() { return true;
this.$popover.on('mouseleave.glPopover.close', this.closePopoverMouseleaveDelayed.bind(this)); }
this.$popover.siblings('.popover').on('mouseleave.glPopover.close', this.closePopoverMouseleaveDelayed.bind(this));
}
destroyMouseleaveCloseListener() { export function mouseleave() {
this.$popover.off('mouseleave.glPopover.close'); if (!$('.popover:hover').length > 0) {
this.$popover.siblings('.popover').on('mouseleave.glPopover.close'); const $popover = $(this);
togglePopover.call($popover, false);
} }
}
enableClose() { export function mouseenter() {
this.registerClickCloseListener(); const $popover = $(this);
this.registerMouseleaveCloseListener();
}
disableClose() { const showedPopover = togglePopover.call($popover, true);
Popover.destroyClickCloseListener(); if (showedPopover) {
this.destroyMouseleaveCloseListener(); $('.popover')
.on('mouseleave', mouseleave.bind($popover));
} }
}
static destroyClickCloseListener() { export function debouncedMouseleave(debounceTimeout = 300) {
$(document.body).off('click.glPopover.close'); return debounce(mouseleave, debounceTimeout);
}
} }
\ No newline at end of file
...@@ -6,22 +6,10 @@ ...@@ -6,22 +6,10 @@
$popup-triangle-border-size $popup-triangle-border-size
); );
padding: $gl-padding;
background-color: $gray-lighter;
border: 1px solid $gray-darker; border: 1px solid $gray-darker;
box-shadow: 0 5px 10px $popup-box-shadow-color; border-radius: $border-radius-default;
box-shadow: 0 5px 8px $popup-box-shadow-color;
position: relative; position: relative;
.body {
background-color: $gray-lighter;
padding: $gl-padding;
border-top-left-radius: $border-radius-default;
border-top-right-radius: $border-radius-default;
}
.footer {
background-color: $white-light;
padding: $gl-padding;
border-bottom-left-radius: $border-radius-default;
border-bottom-right-radius: $border-radius-default;
border-top: 1px solid $white-dark;
}
} }
...@@ -203,18 +203,18 @@ ...@@ -203,18 +203,18 @@
padding: 0; padding: 0;
} }
.body {
padding: 8px 15px 8px 30px;
background-color: $gray-light;
}
.footer { .footer {
background-color: $white-light;
padding: $gl-padding-8 $gl-padding; padding: $gl-padding-8 $gl-padding;
border-bottom-left-radius: $border-radius-default;
border-bottom-right-radius: $border-radius-default;
border-top: 1px solid $white-dark; border-top: 1px solid $white-dark;
} }
.instructions-list { .instructions-list {
list-style-position: inside; padding: 0;
padding: $gl-padding-8 20px;
background-color: $gray-light;
} }
} }
......
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
%p.append-bottom-default.prepend-top-5 %p.append-bottom-default.prepend-top-5
= _('Use group milestones to manage issues from multiple projects in the same milestone.') = _('Use group milestones to manage issues from multiple projects in the same milestone.')
%br %br
= button_tag _('Promote these project milestones into a group milestone.'), class: 'btn-link popover-link' = button_tag _('Promote these project milestones into a group milestone.'), class: 'btn-link popover-link prepend-left-0'
%div= link_to _('Learn more'), help_page_url('user/project/milestones/index', anchor: 'promoting-project-milestones-to-group-milestones'), class: 'btn btn-default', target: '_blank' %div= link_to _('Learn more'), help_page_url('user/project/milestones/index', anchor: 'promoting-project-milestones-to-group-milestones'), class: 'btn btn-default', target: '_blank'
%template.milestone-deprecation-message-template %template.milestone-deprecation-message-template
.body
%ol.instructions-list.append-bottom-0 %ol.instructions-list.append-bottom-0
%li= _('Click any <strong>project name</strong> in the project list below to navigate to the project milestone.').html_safe %li= _('Click any <strong>project name</strong> in the project list below to navigate to the project milestone.').html_safe
%li= _('Click the <strong>Promote</strong> button in the top right corner to promote it to a group milestone.').html_safe %li= _('Click the <strong>Promote</strong> button in the top right corner to promote it to a group milestone.').html_safe
.footer= link_to _('Learn more'), help_page_url('user/project/milestones/index', anchor: 'promoting-project-milestones-to-group-milestones'), class: 'btn-link', target: '_blank' .footer= link_to _('Learn more'), help_page_url('user/project/milestones/index', anchor: 'promoting-project-milestones-to-group-milestones'), class: 'btn-link prepend-left-0', target: '_blank'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment