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
|
|
|
*/
|
2011-05-28 00:05:20 +00:00
|
|
|
(function( $ ) {
|
2010-04-08 21:21:47 +00:00
|
|
|
|
|
|
|
var increments = 0;
|
|
|
|
|
2011-05-28 15:43:57 +00:00
|
|
|
$.widget( "ui.tooltip", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-04-08 21:21:47 +00:00
|
|
|
options: {
|
|
|
|
content: function() {
|
2011-04-13 12:01:46 +00:00
|
|
|
return $( this ).attr( "title" );
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-30 22:27:48 +00:00
|
|
|
hide: true,
|
2011-05-29 00:19:23 +00:00
|
|
|
items: "[title]",
|
2010-04-08 21:21:47 +00:00
|
|
|
position: {
|
2011-05-02 16:21:04 +00:00
|
|
|
my: "left+15 center",
|
2011-05-29 16:29:11 +00:00
|
|
|
at: "right center",
|
2011-08-18 19:39:27 +00:00
|
|
|
collision: "flipfit flipfit"
|
2011-05-29 00:19:23 +00:00
|
|
|
},
|
2011-05-30 22:27:48 +00:00
|
|
|
show: true,
|
|
|
|
tooltipClass: null,
|
|
|
|
|
|
|
|
// callbacks
|
|
|
|
close: null,
|
|
|
|
open: null
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2010-10-26 12:41:14 +00:00
|
|
|
_create: function() {
|
2011-05-28 00:05:20 +00:00
|
|
|
this._bind({
|
2011-04-13 12:01:46 +00:00
|
|
|
mouseover: "open",
|
|
|
|
focusin: "open"
|
|
|
|
});
|
2011-05-28 20:20:01 +00:00
|
|
|
|
|
|
|
// IDs of generated tooltips, needed for destroy
|
|
|
|
this.tooltips = {};
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2011-05-28 19:25:05 +00:00
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "disabled" ) {
|
2011-05-30 00:50:21 +00:00
|
|
|
this[ value ? "_disable" : "_enable" ]();
|
2011-05-28 19:25:05 +00:00
|
|
|
this.options[ key ] = value;
|
2011-05-30 00:50:21 +00:00
|
|
|
// disable element style changes
|
2011-05-28 19:25:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-18 11:19:32 +00:00
|
|
|
this._super( key, value );
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
_disable: function() {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
// close open tooltips
|
|
|
|
$.each( this.tooltips, function( id, element ) {
|
|
|
|
var event = $.Event( "blur" );
|
|
|
|
event.target = event.currentTarget = element[0];
|
|
|
|
that.close( event, true );
|
|
|
|
});
|
|
|
|
|
|
|
|
// remove title attributes to prevent native tooltips
|
|
|
|
this.element.find( this.options.items ).andSelf().each(function() {
|
|
|
|
var element = $( this );
|
|
|
|
if ( element.is( "[title]" ) ) {
|
|
|
|
element
|
|
|
|
.data( "tooltip-title", element.attr( "title" ) )
|
|
|
|
.attr( "title", "" );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_enable: function() {
|
|
|
|
// restore title attributes
|
|
|
|
this.element.find( this.options.items ).andSelf().each(function() {
|
|
|
|
var element = $( this );
|
|
|
|
if ( element.data( "tooltip-title" ) ) {
|
|
|
|
element.attr( "title", element.data( "tooltip-title" ) );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-05-28 00:05:20 +00:00
|
|
|
open: function( event ) {
|
2011-05-29 00:30:14 +00:00
|
|
|
var content,
|
|
|
|
that = this,
|
|
|
|
target = $( event ? event.target : this.element )
|
|
|
|
.closest( this.options.items );
|
|
|
|
|
2011-05-29 23:21:31 +00:00
|
|
|
// if aria-describedby exists, then the tooltip is already open
|
|
|
|
if ( !target.length || target.attr( "aria-describedby" ) ) {
|
2011-02-26 14:06:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-28 00:05:20 +00:00
|
|
|
|
|
|
|
if ( !target.data( "tooltip-title" ) ) {
|
|
|
|
target.data( "tooltip-title", target.attr( "title" ) );
|
2011-04-13 12:01:46 +00:00
|
|
|
}
|
2011-05-29 00:30:14 +00:00
|
|
|
|
2012-02-19 20:29:41 +00:00
|
|
|
target.data( "tooltip-open", true );
|
|
|
|
|
2011-05-29 00:30:14 +00:00
|
|
|
content = this.options.content.call( target[0], function( response ) {
|
2012-02-19 20:29:41 +00:00
|
|
|
// ignore async response if tooltip was closed already
|
|
|
|
if ( !target.data( "tooltip-open" ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-28 15:43:57 +00:00
|
|
|
// IE may instantly serve a cached response for ajax requests
|
|
|
|
// delay this call to _open so the other call to _open runs first
|
2010-10-21 19:03:48 +00:00
|
|
|
setTimeout(function() {
|
2011-05-28 21:36:57 +00:00
|
|
|
that._open( event, target, response );
|
2011-05-28 15:43:57 +00:00
|
|
|
}, 1 );
|
2010-04-08 21:21:47 +00:00
|
|
|
});
|
2011-05-28 00:05:20 +00:00
|
|
|
if ( content ) {
|
|
|
|
that._open( event, target, content );
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
_open: function( event, target, content ) {
|
2011-05-28 00:05:20 +00:00
|
|
|
if ( !content ) {
|
2010-04-08 21:21:47 +00:00
|
|
|
return;
|
2011-05-28 00:05:20 +00:00
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2011-05-29 17:34:37 +00:00
|
|
|
// if we have a title, clear it to prevent the native tooltip
|
|
|
|
// we have to check first to avoid defining a title if none exists
|
|
|
|
// (we don't want to cause an element to start matching [title])
|
2012-02-19 20:17:35 +00:00
|
|
|
|
|
|
|
// We don't use removeAttr as that causes the native tooltip to show
|
|
|
|
// up in IE (9 and below, didn't yet test 10). Happens only when removing
|
|
|
|
// inside the mouseover handler.
|
2011-05-29 17:34:37 +00:00
|
|
|
if ( target.is( "[title]" ) ) {
|
|
|
|
target.attr( "title", "" );
|
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
// ajaxy tooltip can update an existing one
|
|
|
|
var tooltip = this._find( target );
|
2011-05-28 00:05:20 +00:00
|
|
|
if ( !tooltip.length ) {
|
2011-05-30 00:50:21 +00:00
|
|
|
tooltip = this._tooltip( target );
|
2011-04-13 12:01:46 +00:00
|
|
|
target.attr( "aria-describedby", tooltip.attr( "id" ) );
|
|
|
|
}
|
2011-05-28 00:05:20 +00:00
|
|
|
tooltip.find( ".ui-tooltip-content" ).html( content );
|
2011-05-28 14:18:39 +00:00
|
|
|
tooltip
|
|
|
|
.stop( true )
|
|
|
|
.position( $.extend({
|
2011-05-30 22:42:06 +00:00
|
|
|
of: target
|
|
|
|
}, this.options.position ) )
|
|
|
|
.hide();
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2011-04-15 14:49:29 +00:00
|
|
|
this._show( tooltip, this.options.show );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2011-05-30 22:42:06 +00:00
|
|
|
this._trigger( "open", event, { tooltip: tooltip } );
|
2011-04-13 12:01:46 +00:00
|
|
|
|
|
|
|
this._bind( target, {
|
|
|
|
mouseleave: "close",
|
2012-02-23 18:37:31 +00:00
|
|
|
focusout: "close",
|
2011-07-13 22:06:16 +00:00
|
|
|
keyup: function( event ) {
|
|
|
|
if ( event.keyCode == $.ui.keyCode.ESCAPE ) {
|
|
|
|
var fakeEvent = $.Event(event);
|
|
|
|
fakeEvent.currentTarget = target[0];
|
|
|
|
this.close( fakeEvent, true );
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
});
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
close: function( event, force ) {
|
2011-05-28 20:20:01 +00:00
|
|
|
var that = this,
|
2011-05-29 00:30:14 +00:00
|
|
|
target = $( event ? event.currentTarget : this.element ),
|
|
|
|
tooltip = this._find( target );
|
|
|
|
|
2011-05-29 23:21:31 +00:00
|
|
|
// don't close if the element has focus
|
|
|
|
// this prevents the tooltip from closing if you hover while focused
|
2011-10-20 20:57:47 +00:00
|
|
|
if ( !force && this.document[0].activeElement === target[0] ) {
|
2010-04-08 21:21:47 +00:00
|
|
|
return;
|
2011-05-28 00:05:20 +00:00
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
// only set title if we had one before (see comment in _open())
|
|
|
|
if ( target.data( "tooltip-title" ) ) {
|
|
|
|
target.attr( "title", target.data( "tooltip-title" ) );
|
|
|
|
}
|
|
|
|
|
2011-04-13 12:01:46 +00:00
|
|
|
target.removeAttr( "aria-describedby" );
|
2011-05-28 00:05:20 +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();
|
2011-05-28 23:38:01 +00:00
|
|
|
delete that.tooltips[ this.id ];
|
2011-04-13 12:01:46 +00:00
|
|
|
});
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2012-02-19 20:29:41 +00:00
|
|
|
target.removeData( "tooltip-open" );
|
2012-02-23 18:37:31 +00:00
|
|
|
target.unbind( "mouseleave.tooltip focusout.tooltip keyup.tooltip" );
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2011-05-30 22:42:06 +00:00
|
|
|
this._trigger( "close", event, { tooltip: tooltip } );
|
2011-04-13 12:01:46 +00:00
|
|
|
},
|
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
_tooltip: function( element ) {
|
2011-05-28 20:20:01 +00:00
|
|
|
var id = "ui-tooltip-" + increments++,
|
|
|
|
tooltip = $( "<div>" )
|
2011-05-29 00:30:14 +00:00
|
|
|
.attr({
|
|
|
|
id: id,
|
|
|
|
role: "tooltip"
|
|
|
|
})
|
|
|
|
.addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
|
|
|
|
( this.options.tooltipClass || "" ) );
|
2011-05-28 00:05:20 +00:00
|
|
|
$( "<div>" )
|
2011-04-13 12:01:46 +00:00
|
|
|
.addClass( "ui-tooltip-content" )
|
|
|
|
.appendTo( tooltip );
|
2011-10-20 20:57:47 +00:00
|
|
|
tooltip.appendTo( this.document[0].body );
|
2011-05-29 23:28:35 +00:00
|
|
|
if ( $.fn.bgiframe ) {
|
|
|
|
tooltip.bgiframe();
|
|
|
|
}
|
2011-05-30 00:50:21 +00:00
|
|
|
this.tooltips[ id ] = element;
|
2011-04-13 12:01:46 +00:00
|
|
|
return tooltip;
|
|
|
|
},
|
|
|
|
|
|
|
|
_find: function( target ) {
|
|
|
|
var id = target.attr( "aria-describedby" );
|
2011-05-28 15:43:57 +00:00
|
|
|
return id ? $( "#" + id ) : $();
|
2011-05-28 20:20:01 +00:00
|
|
|
},
|
|
|
|
|
2011-05-28 23:38:01 +00:00
|
|
|
_destroy: function() {
|
2011-05-28 20:20:01 +00:00
|
|
|
$.each( this.tooltips, function( id ) {
|
|
|
|
$( "#" + id ).remove();
|
|
|
|
});
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-05-28 00:05:20 +00:00
|
|
|
}( jQuery ) );
|