otgsPopoverTooltip.js
43 lines
| 1 | import tippy from 'tippy.js'; |
| 2 | import '../scss/otgsPopoverTooltip.scss'; |
| 3 | |
| 4 | window.addEventListener("DOMContentLoaded", () => { |
| 5 | initialize(); |
| 6 | }); |
| 7 | |
| 8 | /** |
| 9 | * |
| 10 | * @param {Element} element |
| 11 | */ |
| 12 | export function initSingle(element) { |
| 13 | /** |
| 14 | * @see https://atomiks.github.io/tippyjs/#all-options |
| 15 | * @type {{arrow: boolean, theme: string, animation: string, sticky: boolean, interactive: boolean}} |
| 16 | */ |
| 17 | const args = { |
| 18 | arrow: true, |
| 19 | theme: 'otgs', |
| 20 | animation: 'fade', |
| 21 | sticky: true, |
| 22 | interactive: true, |
| 23 | }; |
| 24 | if ( !element.getAttribute('data-tippy-content') && element.getAttribute('title') ) { |
| 25 | args.content = element.getAttribute('title'); |
| 26 | element.removeAttribute('title'); |
| 27 | } |
| 28 | tippy(element, args); |
| 29 | } |
| 30 | |
| 31 | export function initialize() { |
| 32 | /** |
| 33 | * @param {NodeList} elements |
| 34 | */ |
| 35 | //TODO change all .wpml-popover to otgs-popover |
| 36 | const elements = [...document.querySelectorAll('.js-otgs-popover-tooltip, .js-wpml-popover-tooltip')]; |
| 37 | |
| 38 | /** |
| 39 | * @param {Element} element |
| 40 | */ |
| 41 | elements.forEach(element => initSingle(element)); |
| 42 | } |
| 43 |