diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/assets/javascripts/tooltips/index.js | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/assets/javascripts/tooltips/index.js')
-rw-r--r-- | app/assets/javascripts/tooltips/index.js | 94 |
1 files changed, 30 insertions, 64 deletions
diff --git a/app/assets/javascripts/tooltips/index.js b/app/assets/javascripts/tooltips/index.js index b216affc818..a9978c03a6e 100644 --- a/app/assets/javascripts/tooltips/index.js +++ b/app/assets/javascripts/tooltips/index.js @@ -1,6 +1,5 @@ +import { toArray, isElement } from 'lodash'; import Vue from 'vue'; -import jQuery from 'jquery'; -import { toArray, isFunction, isElement } from 'lodash'; import Tooltips from './components/tooltips.vue'; let app; @@ -60,72 +59,39 @@ const applyToElements = (elements, handler) => { toArray(iterable).forEach(handler); }; -const invokeBootstrapApi = (elements, method) => { - if (isFunction(elements.tooltip)) { - elements.tooltip(method); - } else { - jQuery(elements).tooltip(method); - } -}; - -const isGlTooltipsEnabled = () => Boolean(window.gon.features?.glTooltips); - -const tooltipApiInvoker = ({ glHandler, bsHandler }) => (elements, ...params) => { - if (isGlTooltipsEnabled()) { - applyToElements(elements, glHandler); - } else { - bsHandler(elements, ...params); - } +const createTooltipApiInvoker = (glHandler) => (elements) => { + applyToElements(elements, glHandler); }; export const initTooltips = (config = {}) => { - if (isGlTooltipsEnabled()) { - const triggers = config?.triggers || DEFAULT_TRIGGER; - const events = triggers.split(' ').map((trigger) => EVENTS_MAP[trigger]); - - events.forEach((event) => { - document.addEventListener( - event, - (e) => handleTooltipEvent(document, e, config.selector, config), - true, - ); - }); - - return tooltipsApp(); - } - - return invokeBootstrapApi(document.body, config); -}; -export const add = (elements, config = {}) => { - if (isGlTooltipsEnabled()) { - return addTooltips(elements, config); - } - return invokeBootstrapApi(elements, config); + const triggers = config?.triggers || DEFAULT_TRIGGER; + const events = triggers.split(' ').map((trigger) => EVENTS_MAP[trigger]); + + events.forEach((event) => { + document.addEventListener( + event, + (e) => handleTooltipEvent(document, e, config.selector, config), + true, + ); + }); + + return tooltipsApp(); }; -export const dispose = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().dispose(element), - bsHandler: (elements) => invokeBootstrapApi(elements, 'dispose'), -}); -export const fixTitle = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().fixTitle(element), - bsHandler: (elements) => invokeBootstrapApi(elements, '_fixTitle'), -}); -export const enable = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().triggerEvent(element, 'enable'), - bsHandler: (elements) => invokeBootstrapApi(elements, 'enable'), -}); -export const disable = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().triggerEvent(element, 'disable'), - bsHandler: (elements) => invokeBootstrapApi(elements, 'disable'), -}); -export const hide = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().triggerEvent(element, 'close'), - bsHandler: (elements) => invokeBootstrapApi(elements, 'hide'), -}); -export const show = tooltipApiInvoker({ - glHandler: (element) => tooltipsApp().triggerEvent(element, 'open'), - bsHandler: (elements) => invokeBootstrapApi(elements, 'show'), -}); +export const add = (elements, config = {}) => addTooltips(elements, config); +export const dispose = createTooltipApiInvoker((element) => tooltipsApp().dispose(element)); +export const fixTitle = createTooltipApiInvoker((element) => tooltipsApp().fixTitle(element)); +export const enable = createTooltipApiInvoker((element) => + tooltipsApp().triggerEvent(element, 'enable'), +); +export const disable = createTooltipApiInvoker((element) => + tooltipsApp().triggerEvent(element, 'disable'), +); +export const hide = createTooltipApiInvoker((element) => + tooltipsApp().triggerEvent(element, 'close'), +); +export const show = createTooltipApiInvoker((element) => + tooltipsApp().triggerEvent(element, 'open'), +); export const destroy = () => { tooltipsApp().$destroy(); app = null; |