Skip to content

Tooltip: Fix re-enabling of delegated tooltips #1699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/unit/tooltip/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ QUnit.test( "enable/disable", function( assert ) {
$.fx.off = false;
} );

QUnit.test( "enable/disable delegated", function( assert ) {
assert.expect( 1 );
var element = $( "#qunit-fixture" ).tooltip();
var tooltipped = $( "#tooltipped1" );

element.tooltip( "disable" );
element.tooltip( "enable" );

tooltipped.trigger( "mouseover" );
assert.equal( $( ".ui-tooltip" ).length, 1, "open" );

element.tooltip( "destroy" );
} );

QUnit.test( "widget", function( assert ) {
assert.expect( 2 );
var element = $( "#tooltipped1" ).tooltip(),
Expand Down
24 changes: 15 additions & 9 deletions ui/widgets/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ $.widget( "ui.tooltip", {
} )
.appendTo( this.document[ 0 ].body );
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );

this.disabledTitles = $( [] );
},

_setOption: function( key, value ) {
Expand Down Expand Up @@ -143,25 +145,29 @@ $.widget( "ui.tooltip", {
} );

// Remove title attributes to prevent native tooltips
this.element.find( this.options.items ).addBack().each( function() {
var element = $( this );
if ( element.is( "[title]" ) ) {
element
.data( "ui-tooltip-title", element.attr( "title" ) )
.removeAttr( "title" );
}
} );
this.disabledTitles = this.disabledTitles.add(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the .add() call (which tends to be rather slow)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to cover .disable().disable() and makes sure the collection wasn't overwritten.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.disabledTitles = this.element.find( this.options.items ).addBack() [...] would be simpler/faster, could also skip allocating the empty object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would result in this.disabledTitles being an empty set after .disable().disable() using default settings because this.options.items looks for elements with titles, but the titles are removed after the first call.

this.element.find( this.options.items ).addBack()
.filter( function() {
var element = $( this );
if ( element.is( "[title]" ) ) {
return element
.data( "ui-tooltip-title", element.attr( "title" ) )
.removeAttr( "title" );
}
} )
);
},

_enable: function() {

// restore title attributes
this.element.find( this.options.items ).addBack().each( function() {
this.disabledTitles.each( function() {
var element = $( this );
if ( element.data( "ui-tooltip-title" ) ) {
element.attr( "title", element.data( "ui-tooltip-title" ) );
}
} );
this.disabledTitles = $( [] );
},

open: function( event ) {
Expand Down