@@ -36,7 +36,7 @@ export function createTippy(target, opts = {}) {
36
36
* @returns {null|tippy }
37
37
*/
38
38
function attachTooltip ( target , content = null ) {
39
- content = content ?? getTooltipContent ( target ) ;
39
+ content = content ?? target . getAttribute ( 'data-tooltip-content' ) ;
40
40
if ( ! content ) return null ;
41
41
42
42
const props = {
@@ -67,30 +67,18 @@ function lazyTooltipOnMouseHover(e) {
67
67
attachTooltip ( this ) ;
68
68
}
69
69
70
- function getTooltipContent ( target ) {
71
- // prefer to always use the "[data-tooltip-content]" attribute
72
- // for backward compatibility, we also support the ".tooltip[data-content]" attribute
73
- // in next PR, refactor all the ".tooltip[data-content]" to "[data-tooltip-content]"
74
- let content = target . getAttribute ( 'data-tooltip-content' ) ;
75
- if ( ! content && target . classList . contains ( 'tooltip' ) ) {
76
- content = target . getAttribute ( 'data-content' ) ;
77
- }
78
- return content ;
79
- }
80
-
81
70
/**
82
71
* Activate the tooltip for all children elements
83
72
* And if the element has no aria-label, use the tooltip content as aria-label
84
73
* @param target {HTMLElement}
85
74
*/
86
75
function attachChildrenLazyTooltip ( target ) {
87
- // the selector must match the logic in getTippyTooltipContent
88
- for ( const el of target . querySelectorAll ( '[data-tooltip-content], .tooltip[data-content]' ) ) {
76
+ for ( const el of target . querySelectorAll ( '[data-tooltip-content]' ) ) {
89
77
el . addEventListener ( 'mouseover' , lazyTooltipOnMouseHover , true ) ;
90
78
91
79
// meanwhile, if the element has no aria-label, use the tooltip content as aria-label
92
80
if ( ! el . hasAttribute ( 'aria-label' ) ) {
93
- const content = getTooltipContent ( el ) ;
81
+ const content = target . getAttribute ( 'data-tooltip-content' ) ;
94
82
if ( content ) {
95
83
el . setAttribute ( 'aria-label' , content ) ;
96
84
}
@@ -119,7 +107,7 @@ export function initGlobalTooltips() {
119
107
observer . observe ( document , {
120
108
subtree : true ,
121
109
childList : true ,
122
- attributeFilter : [ 'data-tooltip-content' , 'data-content' ] ,
110
+ attributeFilter : [ 'data-tooltip-content' ] ,
123
111
} ) ;
124
112
125
113
attachChildrenLazyTooltip ( document . documentElement ) ;
0 commit comments