2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2010-04-08 21:21:47 +00:00
|
|
|
* jQuery UI Tooltip @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2010-04-08 21:21:47 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:36:06 +00:00
|
|
|
* http://jquery.org/license
|
2010-04-08 21:21:47 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Tooltip
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Shows additional information for any element on hover or focus.
|
|
|
|
//>>docs: http://api.jqueryui.com/tooltip/
|
|
|
|
//>>demos: http://jqueryui.com/tooltip/
|
2014-04-15 14:45:46 +00:00
|
|
|
//>>css.structure: ../themes/base/core.css
|
|
|
|
//>>css.structure: ../themes/base/tooltip.css
|
|
|
|
//>>css.theme: ../themes/base/theme.css
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2015-03-13 18:36:41 +00:00
|
|
|
( function( factory ) {
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-03-13 18:36:41 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./core",
|
|
|
|
"./widget",
|
|
|
|
"./position"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
}( function( $ ) {
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2014-12-03 16:30:22 +00:00
|
|
|
$.widget( "ui.tooltip", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-04-08 21:21:47 +00:00
|
|
|
options: {
|
2014-12-03 16:30:22 +00:00
|
|
|
classes: {
|
|
|
|
"ui-tooltip": "ui-corner-all ui-widget-shadow"
|
|
|
|
},
|
2010-04-08 21:21:47 +00:00
|
|
|
content: function() {
|
2013-01-11 02:02:28 +00:00
|
|
|
// support: IE<9, Opera in jQuery <1.7
|
|
|
|
// .text() can't accept undefined, so coerce to a string
|
|
|
|
var title = $( this ).attr( "title" ) || "";
|
2012-11-27 16:21:33 +00:00
|
|
|
// Escape title, since we're going from an attribute to raw HTML
|
|
|
|
return $( "<a>" ).text( title ).html();
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-30 22:27:48 +00:00
|
|
|
hide: true,
|
2012-10-13 00:26:47 +00:00
|
|
|
// Disabled elements have inconsistent behavior across browsers (#8661)
|
|
|
|
items: "[title]:not([disabled])",
|
2010-04-08 21:21:47 +00:00
|
|
|
position: {
|
2012-10-23 14:15:19 +00:00
|
|
|
my: "left top+15",
|
|
|
|
at: "left bottom",
|
2012-11-05 18:05:58 +00:00
|
|
|
collision: "flipfit flip"
|
2011-05-29 00:19:23 +00:00
|
|
|
},
|
2011-05-30 22:27:48 +00:00
|
|
|
show: true,
|
2012-06-13 23:02:11 +00:00
|
|
|
track: false,
|
2011-05-30 22:27:48 +00:00
|
|
|
|
|
|
|
// callbacks
|
|
|
|
close: null,
|
|
|
|
open: null
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2013-09-17 14:26:48 +00:00
|
|
|
_addDescribedBy: function( elem, id ) {
|
2015-03-13 18:36:41 +00:00
|
|
|
var describedby = ( elem.attr( "aria-describedby" ) || "" ).split( /\s+/ );
|
2013-09-17 14:26:48 +00:00
|
|
|
describedby.push( id );
|
|
|
|
elem
|
|
|
|
.data( "ui-tooltip-id", id )
|
|
|
|
.attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeDescribedBy: function( elem ) {
|
|
|
|
var id = elem.data( "ui-tooltip-id" ),
|
2015-03-13 18:36:41 +00:00
|
|
|
describedby = ( elem.attr( "aria-describedby" ) || "" ).split( /\s+/ ),
|
2013-09-17 14:26:48 +00:00
|
|
|
index = $.inArray( id, describedby );
|
|
|
|
|
|
|
|
if ( index !== -1 ) {
|
|
|
|
describedby.splice( index, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.removeData( "ui-tooltip-id" );
|
|
|
|
describedby = $.trim( describedby.join( " " ) );
|
|
|
|
if ( describedby ) {
|
|
|
|
elem.attr( "aria-describedby", describedby );
|
|
|
|
} else {
|
|
|
|
elem.removeAttr( "aria-describedby" );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-26 12:41:14 +00:00
|
|
|
_create: function() {
|
2015-03-13 18:36:41 +00:00
|
|
|
this._on( {
|
2011-04-13 12:01:46 +00:00
|
|
|
mouseover: "open",
|
|
|
|
focusin: "open"
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2011-05-28 20:20:01 +00:00
|
|
|
|
|
|
|
// IDs of generated tooltips, needed for destroy
|
|
|
|
this.tooltips = {};
|
2014-09-30 13:44:34 +00:00
|
|
|
|
2012-10-20 00:58:08 +00:00
|
|
|
// IDs of parent tooltips where we removed the title attribute
|
|
|
|
this.parents = {};
|
2012-10-24 14:00:39 +00:00
|
|
|
|
|
|
|
if ( this.options.disabled ) {
|
|
|
|
this._disable();
|
|
|
|
}
|
2013-10-26 15:31:07 +00:00
|
|
|
|
|
|
|
// Append the aria-live region so tooltips announce correctly
|
|
|
|
this.liveRegion = $( "<div>" )
|
2015-03-13 18:36:41 +00:00
|
|
|
.attr( {
|
2013-10-26 15:31:07 +00:00
|
|
|
role: "log",
|
|
|
|
"aria-live": "assertive",
|
|
|
|
"aria-relevant": "additions"
|
2015-03-13 18:36:41 +00:00
|
|
|
} )
|
2013-10-26 15:31:07 +00:00
|
|
|
.appendTo( this.document[ 0 ].body );
|
2014-12-03 16:30:22 +00:00
|
|
|
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
|
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 ) {
|
2012-08-31 19:38:21 +00:00
|
|
|
var that = this;
|
|
|
|
|
2011-05-28 19:25:05 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-08-31 19:38:21 +00:00
|
|
|
|
2011-11-18 11:19:32 +00:00
|
|
|
this._super( key, value );
|
2012-08-31 19:38:21 +00:00
|
|
|
|
|
|
|
if ( key === "content" ) {
|
2014-09-30 13:44:34 +00:00
|
|
|
$.each( this.tooltips, function( id, tooltipData ) {
|
|
|
|
that._updateContent( tooltipData.element );
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2012-08-31 19:38:21 +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
|
|
|
_disable: function() {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
// close open tooltips
|
2014-09-30 13:44:34 +00:00
|
|
|
$.each( this.tooltips, function( id, tooltipData ) {
|
2011-05-30 00:50:21 +00:00
|
|
|
var event = $.Event( "blur" );
|
2014-09-30 13:44:34 +00:00
|
|
|
event.target = event.currentTarget = tooltipData.element[ 0 ];
|
2011-05-30 00:50:21 +00:00
|
|
|
that.close( event, true );
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
|
|
|
// remove title attributes to prevent native tooltips
|
2015-03-13 18:36:41 +00:00
|
|
|
this.element.find( this.options.items ).addBack().each( function() {
|
2011-05-30 00:50:21 +00:00
|
|
|
var element = $( this );
|
|
|
|
if ( element.is( "[title]" ) ) {
|
|
|
|
element
|
2012-03-01 12:32:47 +00:00
|
|
|
.data( "ui-tooltip-title", element.attr( "title" ) )
|
2013-12-24 02:40:30 +00:00
|
|
|
.removeAttr( "title" );
|
2011-05-30 00:50:21 +00:00
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2011-05-30 00:50:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_enable: function() {
|
|
|
|
// restore title attributes
|
2015-03-13 18:36:41 +00:00
|
|
|
this.element.find( this.options.items ).addBack().each( function() {
|
2011-05-30 00:50:21 +00:00
|
|
|
var element = $( this );
|
2012-03-01 12:32:47 +00:00
|
|
|
if ( element.data( "ui-tooltip-title" ) ) {
|
|
|
|
element.attr( "title", element.data( "ui-tooltip-title" ) );
|
2011-05-30 00:50:21 +00:00
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2011-05-30 00:50:21 +00:00
|
|
|
},
|
|
|
|
|
2011-05-28 00:05:20 +00:00
|
|
|
open: function( event ) {
|
2012-10-20 00:58:08 +00:00
|
|
|
var that = this,
|
|
|
|
target = $( event ? event.target : this.element )
|
|
|
|
// we need closest here due to mouseover bubbling,
|
|
|
|
// but always pointing at the same event target
|
|
|
|
.closest( this.options.items );
|
2011-05-29 00:30:14 +00:00
|
|
|
|
2012-11-14 19:42:36 +00:00
|
|
|
// No element to show a tooltip for or the tooltip is already open
|
|
|
|
if ( !target.length || target.data( "ui-tooltip-id" ) ) {
|
2011-02-26 14:06:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2012-03-30 13:06:06 +00:00
|
|
|
if ( target.attr( "title" ) ) {
|
2012-03-01 12:32:47 +00:00
|
|
|
target.data( "ui-tooltip-title", target.attr( "title" ) );
|
2011-04-13 12:01:46 +00:00
|
|
|
}
|
2011-05-29 00:30:14 +00:00
|
|
|
|
2012-11-05 20:03:15 +00:00
|
|
|
target.data( "ui-tooltip-open", true );
|
2012-02-19 20:29:41 +00:00
|
|
|
|
2012-10-20 00:58:08 +00:00
|
|
|
// kill parent tooltips, custom or native, for hover
|
|
|
|
if ( event && event.type === "mouseover" ) {
|
2015-03-13 18:36:41 +00:00
|
|
|
target.parents().each( function() {
|
2012-10-29 00:28:55 +00:00
|
|
|
var parent = $( this ),
|
|
|
|
blurEvent;
|
2012-11-05 20:03:15 +00:00
|
|
|
if ( parent.data( "ui-tooltip-open" ) ) {
|
2012-10-20 00:58:08 +00:00
|
|
|
blurEvent = $.Event( "blur" );
|
|
|
|
blurEvent.target = blurEvent.currentTarget = this;
|
|
|
|
that.close( blurEvent, true );
|
|
|
|
}
|
2012-10-29 00:28:55 +00:00
|
|
|
if ( parent.attr( "title" ) ) {
|
|
|
|
parent.uniqueId();
|
2012-10-20 00:58:08 +00:00
|
|
|
that.parents[ this.id ] = {
|
|
|
|
element: this,
|
2012-10-29 00:28:55 +00:00
|
|
|
title: parent.attr( "title" )
|
2012-10-20 00:58:08 +00:00
|
|
|
};
|
2012-10-29 00:28:55 +00:00
|
|
|
parent.attr( "title", "" );
|
2012-10-20 00:58:08 +00:00
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2012-10-20 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 00:33:01 +00:00
|
|
|
this._registerCloseHandlers( event, target );
|
2012-08-31 19:38:21 +00:00
|
|
|
this._updateContent( target, event );
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateContent: function( target, event ) {
|
|
|
|
var content,
|
2012-08-31 19:41:45 +00:00
|
|
|
contentOption = this.options.content,
|
2012-11-14 19:14:25 +00:00
|
|
|
that = this,
|
|
|
|
eventType = event ? event.type : null;
|
2012-08-31 19:38:21 +00:00
|
|
|
|
2013-05-08 17:15:44 +00:00
|
|
|
if ( typeof contentOption === "string" || contentOption.nodeType ||
|
|
|
|
contentOption.jquery ) {
|
2012-08-31 19:41:45 +00:00
|
|
|
return this._open( event, target, contentOption );
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:36:41 +00:00
|
|
|
content = contentOption.call( target[ 0 ], function( response ) {
|
2015-02-24 00:33:01 +00:00
|
|
|
|
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
|
2015-03-13 18:36:41 +00:00
|
|
|
that._delay( function() {
|
2015-02-24 00:33:01 +00:00
|
|
|
|
|
|
|
// Ignore async response if tooltip was closed already
|
|
|
|
if ( !target.data( "ui-tooltip-open" ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-14 19:14:25 +00:00
|
|
|
// jQuery creates a special event for focusin when it doesn't
|
|
|
|
// exist natively. To improve performance, the native event
|
|
|
|
// object is reused and the type is changed. Therefore, we can't
|
|
|
|
// rely on the type being correct after the event finished
|
|
|
|
// bubbling, so we set it back to the previous value. (#8740)
|
|
|
|
if ( event ) {
|
|
|
|
event.type = eventType;
|
|
|
|
}
|
2012-08-31 19:38:21 +00:00
|
|
|
this._open( event, target, response );
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-05-28 00:05:20 +00:00
|
|
|
if ( content ) {
|
2012-08-31 19:38:21 +00:00
|
|
|
this._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 ) {
|
2015-02-24 00:33:01 +00:00
|
|
|
var tooltipData, tooltip, delayedShow, a11yContent,
|
2012-10-16 16:55:50 +00:00
|
|
|
positionOption = $.extend( {}, this.options.position );
|
2012-10-15 20:15:36 +00:00
|
|
|
|
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
|
|
|
|
2012-06-13 09:18:48 +00:00
|
|
|
// Content can be updated multiple times. If the tooltip already
|
|
|
|
// exists, then just update the content and bail.
|
2014-09-30 13:44:34 +00:00
|
|
|
tooltipData = this._find( target );
|
|
|
|
if ( tooltipData ) {
|
|
|
|
tooltipData.tooltip.find( ".ui-tooltip-content" ).html( content );
|
2012-06-13 09:18:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-05-22 16:34:00 +00:00
|
|
|
//
|
2012-05-09 16:24:47 +00:00
|
|
|
// We use removeAttr only for key events, to allow IE to export the correct
|
|
|
|
// accessible attributes. For mouse events, set to empty string to avoid
|
|
|
|
// native tooltip showing up (happens only when removing inside mouseover).
|
2011-05-29 17:34:37 +00:00
|
|
|
if ( target.is( "[title]" ) ) {
|
2012-05-09 16:24:47 +00:00
|
|
|
if ( event && event.type === "mouseover" ) {
|
|
|
|
target.attr( "title", "" );
|
|
|
|
} else {
|
|
|
|
target.removeAttr( "title" );
|
|
|
|
}
|
2011-05-29 17:34:37 +00:00
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2014-09-30 13:44:34 +00:00
|
|
|
tooltipData = this._tooltip( target );
|
|
|
|
tooltip = tooltipData.tooltip;
|
2013-09-17 14:26:48 +00:00
|
|
|
this._addDescribedBy( target, tooltip.attr( "id" ) );
|
2011-05-28 00:05:20 +00:00
|
|
|
tooltip.find( ".ui-tooltip-content" ).html( content );
|
2012-06-13 23:02:11 +00:00
|
|
|
|
2013-10-26 15:31:07 +00:00
|
|
|
// Support: Voiceover on OS X, JAWS on IE <= 9
|
|
|
|
// JAWS announces deletions even when aria-relevant="additions"
|
|
|
|
// Voiceover will sometimes re-read the entire log region's contents from the beginning
|
|
|
|
this.liveRegion.children().hide();
|
2013-05-08 17:15:44 +00:00
|
|
|
a11yContent = $( "<div>" ).html( tooltip.find( ".ui-tooltip-content" ).html() );
|
|
|
|
a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
|
|
|
|
a11yContent.appendTo( this.liveRegion );
|
2013-10-26 15:31:07 +00:00
|
|
|
|
2012-06-13 23:02:11 +00:00
|
|
|
function position( event ) {
|
|
|
|
positionOption.of = event;
|
2012-10-16 16:55:50 +00:00
|
|
|
if ( tooltip.is( ":hidden" ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-13 23:02:11 +00:00
|
|
|
tooltip.position( positionOption );
|
|
|
|
}
|
2012-11-05 17:59:52 +00:00
|
|
|
if ( this.options.track && event && /^mouse/.test( event.type ) ) {
|
2012-06-13 23:02:11 +00:00
|
|
|
this._on( this.document, {
|
|
|
|
mousemove: position
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2012-06-13 23:02:11 +00:00
|
|
|
// trigger once to override element-relative positioning
|
|
|
|
position( event );
|
|
|
|
} else {
|
2015-03-13 18:36:41 +00:00
|
|
|
tooltip.position( $.extend( {
|
2011-05-30 22:42:06 +00:00
|
|
|
of: target
|
2012-06-13 23:02:11 +00:00
|
|
|
}, this.options.position ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip.hide();
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2011-04-15 14:49:29 +00:00
|
|
|
this._show( tooltip, this.options.show );
|
2012-10-16 16:55:50 +00:00
|
|
|
// Handle tracking tooltips that are shown with a delay (#8644). As soon
|
|
|
|
// as the tooltip is visible, position the tooltip using the most recent
|
|
|
|
// event.
|
|
|
|
if ( this.options.show && this.options.show.delay ) {
|
2015-03-13 18:36:41 +00:00
|
|
|
delayedShow = this.delayedShow = setInterval( function() {
|
2012-10-16 16:55:50 +00:00
|
|
|
if ( tooltip.is( ":visible" ) ) {
|
|
|
|
position( positionOption.of );
|
|
|
|
clearInterval( delayedShow );
|
|
|
|
}
|
|
|
|
}, $.fx.interval );
|
|
|
|
}
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2011-05-30 22:42:06 +00:00
|
|
|
this._trigger( "open", event, { tooltip: tooltip } );
|
2015-02-24 00:33:01 +00:00
|
|
|
},
|
2011-04-13 12:01:46 +00:00
|
|
|
|
2015-02-24 00:33:01 +00:00
|
|
|
_registerCloseHandlers: function( event, target ) {
|
|
|
|
var events = {
|
2011-07-13 22:06:16 +00:00
|
|
|
keyup: function( event ) {
|
2012-04-02 23:12:21 +00:00
|
|
|
if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
|
2015-03-13 18:36:41 +00:00
|
|
|
var fakeEvent = $.Event( event );
|
|
|
|
fakeEvent.currentTarget = target[ 0 ];
|
2011-07-13 22:06:16 +00:00
|
|
|
this.close( fakeEvent, true );
|
|
|
|
}
|
|
|
|
}
|
2012-10-19 22:16:11 +00:00
|
|
|
};
|
2014-01-02 21:51:32 +00:00
|
|
|
|
|
|
|
// Only bind remove handler for delegated targets. Non-delegated
|
|
|
|
// tooltips will handle this in destroy.
|
|
|
|
if ( target[ 0 ] !== this.element[ 0 ] ) {
|
|
|
|
events.remove = function() {
|
2015-02-24 00:33:01 +00:00
|
|
|
this._removeTooltip( this._find( target ).tooltip );
|
2014-01-02 21:51:32 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-10-19 22:16:11 +00:00
|
|
|
if ( !event || event.type === "mouseover" ) {
|
|
|
|
events.mouseleave = "close";
|
|
|
|
}
|
|
|
|
if ( !event || event.type === "focusin" ) {
|
|
|
|
events.focusout = "close";
|
|
|
|
}
|
2012-11-09 18:07:53 +00:00
|
|
|
this._on( true, target, events );
|
2010-04-08 21:21:47 +00:00
|
|
|
},
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2012-10-23 14:36:42 +00:00
|
|
|
close: function( event ) {
|
2014-09-30 13:44:34 +00:00
|
|
|
var tooltip,
|
|
|
|
that = this,
|
2011-05-29 00:30:14 +00:00
|
|
|
target = $( event ? event.currentTarget : this.element ),
|
2014-09-30 13:44:34 +00:00
|
|
|
tooltipData = this._find( target );
|
|
|
|
|
|
|
|
// The tooltip may already be closed
|
|
|
|
if ( !tooltipData ) {
|
2015-02-24 00:33:01 +00:00
|
|
|
|
|
|
|
// We set ui-tooltip-open immediately upon open (in open()), but only set the
|
|
|
|
// additional data once there's actually content to show (in _open()). So even if the
|
|
|
|
// tooltip doesn't have full data, we always remove ui-tooltip-open in case we're in
|
|
|
|
// the period between open() and _open().
|
|
|
|
target.removeData( "ui-tooltip-open" );
|
2014-09-30 13:44:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip = tooltipData.tooltip;
|
2011-05-29 00:30:14 +00:00
|
|
|
|
2012-03-29 22:36:38 +00:00
|
|
|
// disabling closes the tooltip, so we need to track when we're closing
|
|
|
|
// to avoid an infinite loop in case the tooltip becomes disabled on close
|
2014-09-30 13:44:34 +00:00
|
|
|
if ( tooltipData.closing ) {
|
2012-03-29 22:36:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-18 13:38:36 +00:00
|
|
|
// Clear the interval for delayed tracking tooltips
|
|
|
|
clearInterval( this.delayedShow );
|
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
// only set title if we had one before (see comment in _open())
|
2013-12-03 04:03:55 +00:00
|
|
|
// If the title attribute has changed since open(), don't restore
|
|
|
|
if ( target.data( "ui-tooltip-title" ) && !target.attr( "title" ) ) {
|
2012-03-01 12:32:47 +00:00
|
|
|
target.attr( "title", target.data( "ui-tooltip-title" ) );
|
2011-05-30 00:50:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 14:26:48 +00:00
|
|
|
this._removeDescribedBy( target );
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2014-09-30 13:44:34 +00:00
|
|
|
tooltipData.hiding = true;
|
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() {
|
2012-10-15 20:15:36 +00:00
|
|
|
that._removeTooltip( $( this ) );
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2011-05-28 00:05:20 +00:00
|
|
|
|
2012-11-05 20:03:15 +00:00
|
|
|
target.removeData( "ui-tooltip-open" );
|
2012-06-14 16:33:16 +00:00
|
|
|
this._off( target, "mouseleave focusout keyup" );
|
2014-01-02 21:51:32 +00:00
|
|
|
|
2012-10-15 20:15:36 +00:00
|
|
|
// Remove 'remove' binding only on delegated targets
|
2014-01-02 21:51:32 +00:00
|
|
|
if ( target[ 0 ] !== this.element[ 0 ] ) {
|
2012-10-15 20:15:36 +00:00
|
|
|
this._off( target, "remove" );
|
|
|
|
}
|
2012-06-14 14:06:21 +00:00
|
|
|
this._off( this.document, "mousemove" );
|
2012-06-13 23:02:11 +00:00
|
|
|
|
2012-10-20 00:58:08 +00:00
|
|
|
if ( event && event.type === "mouseleave" ) {
|
|
|
|
$.each( this.parents, function( id, parent ) {
|
2012-10-29 00:28:55 +00:00
|
|
|
$( parent.element ).attr( "title", parent.title );
|
2012-10-20 00:58:08 +00:00
|
|
|
delete that.parents[ id ];
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2012-10-20 00:58:08 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 13:44:34 +00:00
|
|
|
tooltipData.closing = true;
|
2011-05-30 22:42:06 +00:00
|
|
|
this._trigger( "close", event, { tooltip: tooltip } );
|
2014-09-30 13:44:34 +00:00
|
|
|
if ( !tooltipData.hiding ) {
|
|
|
|
tooltipData.closing = false;
|
2014-08-05 18:19:06 +00:00
|
|
|
}
|
2011-04-13 12:01:46 +00:00
|
|
|
},
|
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
_tooltip: function( element ) {
|
2014-12-03 16:30:22 +00:00
|
|
|
var tooltip = $( "<div>" ).attr( "role", "tooltip" ),
|
|
|
|
content = $( "<div>" ).appendTo( tooltip ),
|
2013-09-17 14:26:48 +00:00
|
|
|
id = tooltip.uniqueId().attr( "id" );
|
|
|
|
|
2014-12-03 16:30:22 +00:00
|
|
|
this._addClass( content, "ui-tooltip-content" );
|
|
|
|
this._addClass( tooltip, "ui-tooltip", "ui-widget ui-widget-content" );
|
2013-09-17 14:26:48 +00:00
|
|
|
|
2015-03-23 23:09:50 +00:00
|
|
|
tooltip.appendTo( this._appendTo( element ) );
|
2014-09-30 13:44:34 +00:00
|
|
|
|
|
|
|
return this.tooltips[ id ] = {
|
|
|
|
element: element,
|
|
|
|
tooltip: tooltip
|
|
|
|
};
|
2011-04-13 12:01:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_find: function( target ) {
|
2012-05-22 15:06:44 +00:00
|
|
|
var id = target.data( "ui-tooltip-id" );
|
2014-09-30 13:44:34 +00:00
|
|
|
return id ? this.tooltips[ id ] : null;
|
2011-05-28 20:20:01 +00:00
|
|
|
},
|
|
|
|
|
2012-10-15 20:15:36 +00:00
|
|
|
_removeTooltip: function( tooltip ) {
|
|
|
|
tooltip.remove();
|
|
|
|
delete this.tooltips[ tooltip.attr( "id" ) ];
|
|
|
|
},
|
|
|
|
|
2015-03-23 23:09:50 +00:00
|
|
|
_appendTo: function( target ) {
|
|
|
|
var element = target.closest( ".ui-front, dialog" );
|
|
|
|
|
|
|
|
if ( !element.length ) {
|
|
|
|
element = this.document[ 0 ].body;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2011-05-28 23:38:01 +00:00
|
|
|
_destroy: function() {
|
2012-10-05 16:52:02 +00:00
|
|
|
var that = this;
|
|
|
|
|
|
|
|
// close open tooltips
|
2014-09-30 13:44:34 +00:00
|
|
|
$.each( this.tooltips, function( id, tooltipData ) {
|
2012-10-05 16:52:02 +00:00
|
|
|
// Delegate to close method to handle common cleanup
|
2014-09-30 13:44:34 +00:00
|
|
|
var event = $.Event( "blur" ),
|
|
|
|
element = tooltipData.element;
|
|
|
|
event.target = event.currentTarget = element[ 0 ];
|
2012-10-05 16:52:02 +00:00
|
|
|
that.close( event, true );
|
|
|
|
|
|
|
|
// Remove immediately; destroying an open tooltip doesn't use the
|
|
|
|
// hide animation
|
2011-05-28 20:20:01 +00:00
|
|
|
$( "#" + id ).remove();
|
2012-10-05 16:52:02 +00:00
|
|
|
|
|
|
|
// Restore the title
|
|
|
|
if ( element.data( "ui-tooltip-title" ) ) {
|
2013-12-03 04:03:55 +00:00
|
|
|
// If the title attribute has changed since open(), don't restore
|
|
|
|
if ( !element.attr( "title" ) ) {
|
|
|
|
element.attr( "title", element.data( "ui-tooltip-title" ) );
|
|
|
|
}
|
2012-10-05 16:52:02 +00:00
|
|
|
element.removeData( "ui-tooltip-title" );
|
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2013-10-26 15:31:07 +00:00
|
|
|
this.liveRegion.remove();
|
2010-04-08 21:21:47 +00:00
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2010-04-08 21:21:47 +00:00
|
|
|
|
2014-12-03 16:30:22 +00:00
|
|
|
// DEPRECATED
|
|
|
|
// TODO: Switch return back to widget declaration at top of file when this is removed
|
|
|
|
if ( $.uiBackCompat !== false ) {
|
|
|
|
|
|
|
|
// Backcompat for tooltipClass option
|
|
|
|
$.widget( "ui.tooltip", $.ui.tooltip, {
|
|
|
|
options: {
|
|
|
|
tooltipClass: null
|
|
|
|
},
|
|
|
|
_tooltip: function() {
|
|
|
|
var tooltipData = this._superApply( arguments );
|
|
|
|
if ( this.options.tooltipClass ) {
|
|
|
|
tooltipData.tooltip.addClass( this.options.tooltipClass );
|
|
|
|
}
|
|
|
|
return tooltipData;
|
|
|
|
}
|
2015-03-13 18:36:41 +00:00
|
|
|
} );
|
2014-12-03 16:30:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $.ui.tooltip;
|
|
|
|
|
2015-03-13 18:36:41 +00:00
|
|
|
} ) );
|