@@ -3,42 +3,44 @@ import { getBootstrap } from './context.helper';
33
44const { document : doc } = window ;
55
6- let lastInsertTooltipTarget = null ;
76const TOOLTIPS_SELECTOR = '[title], [data-tooltip-title]' ;
87const observerConfig = {
98 childList : true ,
109 subtree : true ,
10+ attributes : true ,
11+ attributeFilter : [ 'title' , 'data-tooltip-title' , 'data-tooltip-extra-class' , 'data-tooltip-manual-reparsing' ] ,
1112} ;
1213const resizeEllipsisObserver = new ResizeObserver ( ( entries ) => {
1314 entries . forEach ( ( entry ) => {
1415 parse ( entry . target ) ;
1516 } ) ;
1617} ) ;
1718const observer = new MutationObserver ( ( mutationsList ) => {
18- if ( lastInsertTooltipTarget ) {
19- mutationsList . forEach ( ( mutation ) => {
20- const { addedNodes, removedNodes } = mutation ;
21-
22- if ( addedNodes . length ) {
23- addedNodes . forEach ( ( addedNode ) => {
24- if ( addedNode instanceof Element ) {
25- parse ( addedNode ) ;
26- }
27- } ) ;
19+ mutationsList . forEach ( ( mutation ) => {
20+ const { type, target, addedNodes, removedNodes } = mutation ;
21+
22+ if ( type === 'attributes' ) {
23+ const { tooltipManualReparsing } = target . dataset ;
24+
25+ if ( ! tooltipManualReparsing ) {
26+ parse ( target . parentElement ) ;
27+ }
28+ }
29+
30+ addedNodes . forEach ( ( addedNode ) => {
31+ if ( addedNode instanceof Element && ! addedNode ?. classList . contains ( 'ibexa-tooltip' ) ) {
32+ parse ( addedNode ) ;
2833 }
34+ } ) ;
2935
30- if ( removedNodes . length ) {
31- removedNodes . forEach ( ( removedNode ) => {
32- if ( removedNode . classList && ! removedNode . classList . contains ( 'ibexa-tooltip' ) ) {
33- lastInsertTooltipTarget = null ;
34- doc . querySelectorAll ( '.ibexa-tooltip.show' ) . forEach ( ( tooltipNode ) => {
35- tooltipNode . remove ( ) ;
36- } ) ;
37- }
36+ removedNodes . forEach ( ( removedNode ) => {
37+ if ( removedNode . classList && ! removedNode . classList . contains ( 'ibexa-tooltip' ) ) {
38+ removedNode . querySelectorAll ( '.ibexa-tooltip.show' ) . forEach ( ( tooltipNode ) => {
39+ tooltipNode . remove ( ) ;
3840 } ) ;
3941 }
4042 } ) ;
41- }
43+ } ) ;
4244} ) ;
4345const modifyPopperConfig = ( iframe , defaultBsPopperConfig ) => {
4446 if ( ! iframe ) {
@@ -146,10 +148,6 @@ const initializeTooltip = (tooltipNode, hasEllipsisStyle) => {
146148 </div>` ,
147149 } ) ;
148150
149- tooltipNode . addEventListener ( 'inserted.bs.tooltip' , ( event ) => {
150- lastInsertTooltipTarget = event . currentTarget ;
151- } ) ;
152-
153151 if ( isSafari ( ) ) {
154152 if ( tooltipNode . children ) {
155153 const childWithTitle = [ ...tooltipNode . children ] . find ( ( child ) => title === child . textContent ) ;
@@ -169,6 +167,7 @@ const parse = (baseElement = doc) => {
169167 if ( ! baseElement ) {
170168 return ;
171169 }
170+
172171 const bootstrap = getBootstrap ( ) ;
173172 const tooltipNodes = [ ...baseElement . querySelectorAll ( TOOLTIPS_SELECTOR ) ] ;
174173
0 commit comments