Skip to content

Commit e7be72f

Browse files
committed
Tooltip: Coding standards.
1 parent 12f73d6 commit e7be72f

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

ui/jquery.ui.tooltip.js

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* jquery.ui.widget.js
1313
* jquery.ui.position.js
1414
*/
15-
(function($) {
15+
(function( $ ) {
1616

1717
var increments = 0;
1818

@@ -28,63 +28,68 @@ $.widget("ui.tooltip", {
2828
at: "right center"
2929
}
3030
},
31+
3132
_create: function() {
32-
this._bind( {
33+
this._bind({
3334
mouseover: "open",
3435
focusin: "open"
3536
});
3637
},
37-
38+
3839
enable: function() {
3940
this.options.disabled = false;
4041
},
41-
42+
4243
disable: function() {
4344
// only set option, disable element style changes
4445
this.options.disabled = true;
4546
},
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 );
4950
if ( !target.length ) {
5051
return;
5152
}
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" ) );
5557
}
56-
var content = this.options.content.call(target[0], function(response) {
58+
var content = this.options.content.call( target[0], function( response ) {
5759
// IE may instantly serve a cached response, need to give it a chance to finish with _open before that
5860
setTimeout(function() {
5961
// 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
6163
// 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 );
6466
}
65-
}, 13);
67+
}, 13 );
6668
});
67-
if (content) {
68-
self._open(event, target, content);
69+
if ( content ) {
70+
that._open( event, target, content );
6971
}
7072
},
71-
73+
7274
_open: function( event, target, content ) {
73-
if ( !content )
75+
if ( !content ) {
7476
return;
77+
}
7578

76-
target.attr("title", "");
79+
target.attr( "title", "" );
7780

78-
if ( this.options.disabled )
81+
// TODO: why is this check after we clear the title?
82+
if ( this.options.disabled ) {
7983
return;
84+
}
8085

8186
// ajaxy tooltip can update an existing one
8287
var tooltip = this._find( target );
83-
if (!tooltip.length) {
88+
if ( !tooltip.length ) {
8489
tooltip = this._tooltip();
8590
target.attr( "aria-describedby", tooltip.attr( "id" ) );
8691
}
87-
tooltip.find(".ui-tooltip-content").html( content );
92+
tooltip.find( ".ui-tooltip-content" ).html( content );
8893
tooltip.position( $.extend({
8994
of: target
9095
}, this.options.position ) ).hide();
@@ -100,36 +105,37 @@ $.widget("ui.tooltip", {
100105
click: "close"
101106
});
102107
},
103-
108+
104109
close: function( event ) {
105-
var target = $( event && event.currentTarget || this.element );
110+
var target = $( event ? event.currentTarget : this.element );
106111
target.attr( "title", target.data( "tooltip-title" ) );
107-
108-
if ( this.options.disabled )
112+
113+
if ( this.options.disabled ) {
109114
return;
115+
}
110116

111117
var tooltip = this._find( target );
112118
target.removeAttr( "aria-describedby" );
113-
119+
114120
tooltip.stop( true );
115121
this._hide( tooltip, this.options.hide, function() {
116122
$( this ).remove();
117123
});
118-
124+
119125
target.unbind( "mouseleave.tooltip blur.tooltip" );
120-
126+
121127
this._trigger( "close", event );
122128
},
123129

124130
_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>" )
133139
.addClass( "ui-tooltip-content" )
134140
.appendTo( tooltip );
135141
tooltip.appendTo( document.body );
@@ -144,4 +150,4 @@ $.widget("ui.tooltip", {
144150

145151
$.ui.tooltip.version = "@VERSION";
146152

147-
})(jQuery);
153+
}( jQuery ) );

0 commit comments

Comments
 (0)