diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-05-27 20:05:20 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-05-27 20:05:20 -0400 |
commit | e7be72ff06d4152245a674c37abc7e8577bfc7a1 (patch) | |
tree | 894e57e8f6538396faccaa24870bc3843b773400 /ui | |
parent | 12f73d623e54a37cc347f48db4c7dea23648ba1e (diff) | |
download | jquery-ui-e7be72ff06d4152245a674c37abc7e8577bfc7a1.tar.gz jquery-ui-e7be72ff06d4152245a674c37abc7e8577bfc7a1.zip |
Tooltip: Coding standards.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.tooltip.js | 84 |
1 files changed, 45 insertions, 39 deletions
diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index a8a44f1c0..b781174c9 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -12,7 +12,7 @@ * jquery.ui.widget.js * jquery.ui.position.js */ -(function($) { +(function( $ ) { var increments = 0; @@ -28,63 +28,68 @@ $.widget("ui.tooltip", { at: "right center" } }, + _create: function() { - this._bind( { + this._bind({ mouseover: "open", focusin: "open" }); }, - + enable: function() { this.options.disabled = false; }, - + disable: function() { // only set option, disable element style changes this.options.disabled = true; }, - - open: function(event) { - var target = $(event && event.target || this.element).closest(this.options.items); + + open: function( event ) { + var target = $( event ? event.target : this.element ).closest( this.options.items ); if ( !target.length ) { return; } - var self = this; - if ( !target.data("tooltip-title") ) { - target.data("tooltip-title", target.attr("title")); + + var that = this; + if ( !target.data( "tooltip-title" ) ) { + target.data( "tooltip-title", target.attr( "title" ) ); } - var content = this.options.content.call(target[0], function(response) { + var content = this.options.content.call( target[0], function( response ) { // IE may instantly serve a cached response, need to give it a chance to finish with _open before that setTimeout(function() { // when undefined, it got removeAttr, then ignore (ajax response) - // intially its an empty string, so not undefined + // initially its an empty string, so not undefined // TODO is there a better approach to enable ajax tooltips to have two updates? - if (target.attr( "aria-describedby" ) !== undefined) { - self._open(event, target, response); + if ( target.attr( "aria-describedby" ) !== undefined ) { + that._open( event, target, response ); } - }, 13); + }, 13 ); }); - if (content) { - self._open(event, target, content); + if ( content ) { + that._open( event, target, content ); } }, - + _open: function( event, target, content ) { - if ( !content ) + if ( !content ) { return; + } - target.attr("title", ""); + target.attr( "title", "" ); - if ( this.options.disabled ) + // TODO: why is this check after we clear the title? + if ( this.options.disabled ) { return; + } // ajaxy tooltip can update an existing one var tooltip = this._find( target ); - if (!tooltip.length) { + if ( !tooltip.length ) { tooltip = this._tooltip(); target.attr( "aria-describedby", tooltip.attr( "id" ) ); } - tooltip.find(".ui-tooltip-content").html( content ); + tooltip.find( ".ui-tooltip-content" ).html( content ); tooltip.position( $.extend({ of: target }, this.options.position ) ).hide(); @@ -100,36 +105,37 @@ $.widget("ui.tooltip", { click: "close" }); }, - + close: function( event ) { - var target = $( event && event.currentTarget || this.element ); + var target = $( event ? event.currentTarget : this.element ); target.attr( "title", target.data( "tooltip-title" ) ); - - if ( this.options.disabled ) + + if ( this.options.disabled ) { return; + } var tooltip = this._find( target ); target.removeAttr( "aria-describedby" ); - + tooltip.stop( true ); this._hide( tooltip, this.options.hide, function() { $( this ).remove(); }); - + target.unbind( "mouseleave.tooltip blur.tooltip" ); - + this._trigger( "close", event ); }, _tooltip: function() { - var tooltip = $( "<div></div>" ) - .attr( "id", "ui-tooltip-" + increments++ ) - .attr( "role", "tooltip" ) - .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content" ); - if (this.options.tooltipClass) { - tooltip.addClass(this.options.tooltipClass); - } - $( "<div></div>" ) + var tooltip = $( "<div>" ) + .attr({ + id: "ui-tooltip-" + increments++, + role: "tooltip" + }) + .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content" + + ( this.options.tooltipClass || "" ) ); + $( "<div>" ) .addClass( "ui-tooltip-content" ) .appendTo( tooltip ); tooltip.appendTo( document.body ); @@ -144,4 +150,4 @@ $.widget("ui.tooltip", { $.ui.tooltip.version = "@VERSION"; -})(jQuery);
\ No newline at end of file +}( jQuery ) ); |