@@ -42,14 +42,46 @@ $.widget( "ui.tooltip", {
42
42
} ,
43
43
44
44
_setOption : function ( key , value ) {
45
- // only set option, disable element style changes
46
45
if ( key === "disabled" ) {
46
+ this [ value ? "_disable" : "_enable" ] ( ) ;
47
47
this . options [ key ] = value ;
48
+ // disable element style changes
48
49
return ;
49
50
}
50
51
this . _super ( "_setOption" , key , value ) ;
51
52
} ,
52
53
54
+ _disable : function ( ) {
55
+ var that = this ;
56
+
57
+ // close open tooltips
58
+ $ . each ( this . tooltips , function ( id , element ) {
59
+ var event = $ . Event ( "blur" ) ;
60
+ event . target = event . currentTarget = element [ 0 ] ;
61
+ that . close ( event , true ) ;
62
+ } ) ;
63
+
64
+ // remove title attributes to prevent native tooltips
65
+ this . element . find ( this . options . items ) . andSelf ( ) . each ( function ( ) {
66
+ var element = $ ( this ) ;
67
+ if ( element . is ( "[title]" ) ) {
68
+ element
69
+ . data ( "tooltip-title" , element . attr ( "title" ) )
70
+ . attr ( "title" , "" ) ;
71
+ }
72
+ } ) ;
73
+ } ,
74
+
75
+ _enable : function ( ) {
76
+ // restore title attributes
77
+ this . element . find ( this . options . items ) . andSelf ( ) . each ( function ( ) {
78
+ var element = $ ( this ) ;
79
+ if ( element . data ( "tooltip-title" ) ) {
80
+ element . attr ( "title" , element . data ( "tooltip-title" ) ) ;
81
+ }
82
+ } ) ;
83
+ } ,
84
+
53
85
open : function ( event ) {
54
86
var content ,
55
87
that = this ,
@@ -83,24 +115,17 @@ $.widget( "ui.tooltip", {
83
115
}
84
116
85
117
// if we have a title, clear it to prevent the native tooltip
86
- // we do this before the disabled check to prevent native tooltips
87
- // even when disabled
88
- // TODO: the above doesn't work since ._bind() does a disabled check
89
118
// we have to check first to avoid defining a title if none exists
90
119
// (we don't want to cause an element to start matching [title])
91
120
// TODO: document why we don't use .removeAttr()
92
121
if ( target . is ( "[title]" ) ) {
93
122
target . attr ( "title" , "" ) ;
94
123
}
95
124
96
- if ( this . options . disabled ) {
97
- return ;
98
- }
99
-
100
125
// ajaxy tooltip can update an existing one
101
126
var tooltip = this . _find ( target ) ;
102
127
if ( ! tooltip . length ) {
103
- tooltip = this . _tooltip ( ) ;
128
+ tooltip = this . _tooltip ( target ) ;
104
129
target . attr ( "aria-describedby" , tooltip . attr ( "id" ) ) ;
105
130
}
106
131
tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
@@ -124,22 +149,22 @@ $.widget( "ui.tooltip", {
124
149
} ) ;
125
150
} ,
126
151
127
- close : function ( event ) {
152
+ close : function ( event , force ) {
128
153
var that = this ,
129
154
target = $ ( event ? event . currentTarget : this . element ) ,
130
155
tooltip = this . _find ( target ) ;
131
156
132
- // only set title if we had one before (see comment in _open())
133
- if ( target . data ( "tooltip-title" ) ) {
134
- target . attr ( "title" , target . data ( "tooltip-title" ) ) ;
135
- }
136
-
137
157
// don't close if the element has focus
138
158
// this prevents the tooltip from closing if you hover while focused
139
- if ( this . options . disabled || document . activeElement === target [ 0 ] ) {
159
+ if ( ! force && document . activeElement === target [ 0 ] ) {
140
160
return ;
141
161
}
142
162
163
+ // only set title if we had one before (see comment in _open())
164
+ if ( target . data ( "tooltip-title" ) ) {
165
+ target . attr ( "title" , target . data ( "tooltip-title" ) ) ;
166
+ }
167
+
143
168
target . removeAttr ( "aria-describedby" ) ;
144
169
145
170
tooltip . stop ( true ) ;
@@ -153,7 +178,7 @@ $.widget( "ui.tooltip", {
153
178
this . _trigger ( "close" , event ) ;
154
179
} ,
155
180
156
- _tooltip : function ( ) {
181
+ _tooltip : function ( element ) {
157
182
var id = "ui-tooltip-" + increments ++ ,
158
183
tooltip = $ ( "<div>" )
159
184
. attr ( {
@@ -169,7 +194,7 @@ $.widget( "ui.tooltip", {
169
194
if ( $ . fn . bgiframe ) {
170
195
tooltip . bgiframe ( ) ;
171
196
}
172
- this . tooltips [ id ] = true ;
197
+ this . tooltips [ id ] = element ;
173
198
return tooltip ;
174
199
} ,
175
200
0 commit comments