2010-04-08 21:21:47 +00:00
|
|
|
/*
|
|
|
|
* jQuery UI Tooltip @VERSION
|
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:36:06 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2010-04-08 21:21:47 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Tooltip
|
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* jquery.ui.core.js
|
|
|
|
* jquery.ui.widget.js
|
2010-07-09 13:36:06 +00:00
|
|
|
* jquery.ui.position.js
|
2010-04-08 21:21:47 +00:00
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
|
|
|
var increments = 0;
|
|
|
|
|
|
|
|
$.widget("ui.tooltip", {
|
|
|
|
options: {
|
2011-04-13 12:01:46 +00:00
|
|
|
tooltipClass: null,
|
2010-10-26 15:07:22 +00:00
|
|
|
items: "[title]",
|
2010-04-08 21:21:47 +00:00
|
|
|
content: function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
return $( this ).attr( "title" );
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
|
|
|
position: {
|
2011-05-02 16:21:04 +00:00
|
|
|
my: "left+15 center",
|
|
|
|
at: "right center"
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
},
|
2010-10-26 12:41:14 +00:00
|
|
|
_create: function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
this._bind( {
|
|
|
|
mouseover: "open",
|
|
|
|
focusin: "open"
|
|
|
|
});
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
enable: function() {
|
|
|
|
this.options.disabled = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
disable: function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
// only set option, disable element style changes
|
2010-04-08 21:21:47 +00:00
|
|
|
this.options.disabled = true;
|
|
|
|
},
|
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
open: function(event) {
|
2010-10-26 15:07:22 +00:00
|
|
|
var target = $(event && event.target || this.element).closest(this.options.items);
|
2011-02-26 14:06:06 +00:00
|
|
|
if ( !target.length ) {
|
|
|
|
return;
|
|
|
|
}
|
2010-04-08 21:21:47 +00:00
|
|
|
var self = this;
|
2011-04-13 12:01:46 +00:00
|
|
|
if ( !target.data("tooltip-title") ) {
|
|
|
|
target.data("tooltip-title", target.attr("title"));
|
|
|
|
}
|
2010-04-08 21:21:47 +00:00
|
|
|
var content = this.options.content.call(target[0], function(response) {
|
2011-02-26 14:04:33 +00:00
|
|
|
// IE may instantly serve a cached response, need to give it a chance to finish with _open before that
|
2010-10-21 19:03:48 +00:00
|
|
|
setTimeout(function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
// when undefined, it got removeAttr, then ignore (ajax response)
|
|
|
|
// intially 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) {
|
2011-02-26 14:04:33 +00:00
|
|
|
self._open(event, target, response);
|
2011-04-13 12:01:46 +00:00
|
|
|
}
|
2010-10-21 19:03:48 +00:00
|
|
|
}, 13);
|
2010-04-08 21:21:47 +00:00
|
|
|
});
|
|
|
|
if (content) {
|
2011-02-26 14:04:33 +00:00
|
|
|
self._open(event, target, content);
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
_open: function( event, target, content ) {
|
|
|
|
if ( !content )
|
2010-04-08 21:21:47 +00:00
|
|
|
return;
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2010-04-08 21:21:47 +00:00
|
|
|
target.attr("title", "");
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
if ( this.options.disabled )
|
2010-04-08 21:21:47 +00:00
|
|
|
return;
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
// ajaxy tooltip can update an existing one
|
|
|
|
var tooltip = this._find( target );
|
|
|
|
if (!tooltip.length) {
|
|
|
|
tooltip = this._tooltip();
|
|
|
|
target.attr( "aria-describedby", tooltip.attr( "id" ) );
|
|
|
|
}
|
|
|
|
tooltip.find(".ui-tooltip-content").html( content );
|
|
|
|
tooltip.position( $.extend({
|
2010-04-08 21:21:47 +00:00
|
|
|
of: target
|
2011-04-13 12:01:46 +00:00
|
|
|
}, this.options.position ) ).hide();
|
|
|
|
|
2011-04-21 12:30:42 +00:00
|
|
|
tooltip.stop( true );
|
2011-04-15 14:49:29 +00:00
|
|
|
this._show( tooltip, this.options.show );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
this._trigger( "open", event );
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
this._bind( target, {
|
|
|
|
mouseleave: "close",
|
|
|
|
blur: "close"
|
|
|
|
});
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
close: function( event ) {
|
|
|
|
var target = $( event && event.currentTarget || this.element );
|
|
|
|
target.attr( "title", target.data( "tooltip-title" ) );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
if ( this.options.disabled )
|
2010-04-08 21:21:47 +00:00
|
|
|
return;
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
var tooltip = this._find( target );
|
|
|
|
target.removeAttr( "aria-describedby" );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2011-04-21 12:30:42 +00:00
|
|
|
tooltip.stop( true );
|
2011-04-15 14:49:29 +00:00
|
|
|
this._hide( tooltip, this.options.hide, function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
$( this ).remove();
|
|
|
|
});
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
target.unbind( "mouseleave.tooltip blur.tooltip" );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2010-04-15 07:45:35 +00:00
|
|
|
this._trigger( "close", event );
|
2011-04-13 12:01:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_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>" )
|
|
|
|
.addClass( "ui-tooltip-content" )
|
|
|
|
.appendTo( tooltip );
|
|
|
|
tooltip.appendTo( document.body );
|
|
|
|
return tooltip;
|
|
|
|
},
|
|
|
|
|
|
|
|
_find: function( target ) {
|
|
|
|
var id = target.attr( "aria-describedby" );
|
|
|
|
return id ? $( document.getElementById( id ) ) : $();
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-02-03 17:01:26 +00:00
|
|
|
$.ui.tooltip.version = "@VERSION";
|
|
|
|
|
2010-04-08 21:21:47 +00:00
|
|
|
})(jQuery);
|