12
12
* jquery.ui.widget.js
13
13
* jquery.ui.position.js
14
14
*/
15
- ( function ( $ ) {
15
+ ( function ( $ ) {
16
16
17
17
var increments = 0 ;
18
18
@@ -28,63 +28,68 @@ $.widget("ui.tooltip", {
28
28
at : "right center"
29
29
}
30
30
} ,
31
+
31
32
_create : function ( ) {
32
- this . _bind ( {
33
+ this . _bind ( {
33
34
mouseover : "open" ,
34
35
focusin : "open"
35
36
} ) ;
36
37
} ,
37
-
38
+
38
39
enable : function ( ) {
39
40
this . options . disabled = false ;
40
41
} ,
41
-
42
+
42
43
disable : function ( ) {
43
44
// only set option, disable element style changes
44
45
this . options . disabled = true ;
45
46
} ,
46
-
47
- open : function ( event ) {
48
- var target = $ ( event && event . target || this . element ) . closest ( this . options . items ) ;
47
+
48
+ open : function ( event ) {
49
+ var target = $ ( event ? event . target : this . element ) . closest ( this . options . items ) ;
49
50
if ( ! target . length ) {
50
51
return ;
51
52
}
52
- var self = this ;
53
- if ( ! target . data ( "tooltip-title" ) ) {
54
- target . data ( "tooltip-title" , target . attr ( "title" ) ) ;
53
+
54
+ var that = this ;
55
+ if ( ! target . data ( "tooltip-title" ) ) {
56
+ target . data ( "tooltip-title" , target . attr ( "title" ) ) ;
55
57
}
56
- var content = this . options . content . call ( target [ 0 ] , function ( response ) {
58
+ var content = this . options . content . call ( target [ 0 ] , function ( response ) {
57
59
// IE may instantly serve a cached response, need to give it a chance to finish with _open before that
58
60
setTimeout ( function ( ) {
59
61
// when undefined, it got removeAttr, then ignore (ajax response)
60
- // intially its an empty string, so not undefined
62
+ // initially its an empty string, so not undefined
61
63
// TODO is there a better approach to enable ajax tooltips to have two updates?
62
- if ( target . attr ( "aria-describedby" ) !== undefined ) {
63
- self . _open ( event , target , response ) ;
64
+ if ( target . attr ( "aria-describedby" ) !== undefined ) {
65
+ that . _open ( event , target , response ) ;
64
66
}
65
- } , 13 ) ;
67
+ } , 13 ) ;
66
68
} ) ;
67
- if ( content ) {
68
- self . _open ( event , target , content ) ;
69
+ if ( content ) {
70
+ that . _open ( event , target , content ) ;
69
71
}
70
72
} ,
71
-
73
+
72
74
_open : function ( event , target , content ) {
73
- if ( ! content )
75
+ if ( ! content ) {
74
76
return ;
77
+ }
75
78
76
- target . attr ( "title" , "" ) ;
79
+ target . attr ( "title" , "" ) ;
77
80
78
- if ( this . options . disabled )
81
+ // TODO: why is this check after we clear the title?
82
+ if ( this . options . disabled ) {
79
83
return ;
84
+ }
80
85
81
86
// ajaxy tooltip can update an existing one
82
87
var tooltip = this . _find ( target ) ;
83
- if ( ! tooltip . length ) {
88
+ if ( ! tooltip . length ) {
84
89
tooltip = this . _tooltip ( ) ;
85
90
target . attr ( "aria-describedby" , tooltip . attr ( "id" ) ) ;
86
91
}
87
- tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
92
+ tooltip . find ( ".ui-tooltip-content" ) . html ( content ) ;
88
93
tooltip . position ( $ . extend ( {
89
94
of : target
90
95
} , this . options . position ) ) . hide ( ) ;
@@ -100,36 +105,37 @@ $.widget("ui.tooltip", {
100
105
click : "close"
101
106
} ) ;
102
107
} ,
103
-
108
+
104
109
close : function ( event ) {
105
- var target = $ ( event && event . currentTarget || this . element ) ;
110
+ var target = $ ( event ? event . currentTarget : this . element ) ;
106
111
target . attr ( "title" , target . data ( "tooltip-title" ) ) ;
107
-
108
- if ( this . options . disabled )
112
+
113
+ if ( this . options . disabled ) {
109
114
return ;
115
+ }
110
116
111
117
var tooltip = this . _find ( target ) ;
112
118
target . removeAttr ( "aria-describedby" ) ;
113
-
119
+
114
120
tooltip . stop ( true ) ;
115
121
this . _hide ( tooltip , this . options . hide , function ( ) {
116
122
$ ( this ) . remove ( ) ;
117
123
} ) ;
118
-
124
+
119
125
target . unbind ( "mouseleave.tooltip blur.tooltip" ) ;
120
-
126
+
121
127
this . _trigger ( "close" , event ) ;
122
128
} ,
123
129
124
130
_tooltip : function ( ) {
125
- var tooltip = $ ( "<div></div> " )
126
- . attr ( "id" , "ui-tooltip-" + increments ++ )
127
- . attr ( "role" , " tooltip" )
128
- . addClass ( "ui- tooltip ui-widget ui-corner-all ui-widget-content" ) ;
129
- if ( this . options . tooltipClass ) {
130
- tooltip . addClass ( this . options . tooltipClass ) ;
131
- }
132
- $ ( "<div></div> " )
131
+ var tooltip = $ ( "<div>" )
132
+ . attr ( {
133
+ id : "ui- tooltip-" + increments ++ ,
134
+ role : " tooltip"
135
+ } )
136
+ . addClass ( "ui-tooltip ui-widget ui-corner-all ui-widget-content" +
137
+ ( this . options . tooltipClass || "" ) ) ;
138
+ $ ( "<div>" )
133
139
. addClass ( "ui-tooltip-content" )
134
140
. appendTo ( tooltip ) ;
135
141
tooltip . appendTo ( document . body ) ;
@@ -144,4 +150,4 @@ $.widget("ui.tooltip", {
144
150
145
151
$ . ui . tooltip . version = "@VERSION" ;
146
152
147
- } ) ( jQuery ) ;
153
+ } ( jQuery ) ) ;
0 commit comments