Skip to content

Allow adding html elements as tooltip content #983

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
wants to merge 2 commits into from

Conversation

daniel-o
Copy link

@daniel-o daniel-o commented May 8, 2013

Can now pass HTMLElement and jQuery objects to the tooltip content option.
Added tests as well. Hopefully those look right.

Pretty much just changed the conditions that are checked for the contentOption variable. I put some of the conditions on separate lines because I thought it increased readability. So if someone could look at the formatting and scold me if I did it wrong, that would be great.

…nd jQuery objects to be set as content.

Added tests for these scenarios.
@scottgonzalez
Copy link
Member

Thanks Daniel. All feature requests need to go through a ticket, but this seems like a reasonable addition. Can you file a ticket for this at http://bugs.jqueryui.com/newticket? I'll also ping the rest of the team to discuss this.

In the meantime, I'll comment on the changes, since I think this will end up landing.

@@ -7,3 +7,4 @@ docs
*.patch
.DS_Store
.settings
*.sw?
Copy link
Member

Choose a reason for hiding this comment

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

You should add this to your global gitignore via core.excludesfile. I actually didn't realize we had so many files in here, I'm going to rip these out :-P

Copy link
Member

Choose a reason for hiding this comment

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

Please remove this.

@scottgonzalez
Copy link
Member

We can't use .html() for the two new cases. While it works today, it's not part of the API and can break without notice. I'm also concerned about what will happen if the same element is used for multiple instances.

}
}).tooltip( "open" );
});
);
Copy link
Member

Choose a reason for hiding this comment

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

This looks like an error and doesn't need to be there.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, looks like this was accidentally pulled from line 98

@daniel-o
Copy link
Author

daniel-o commented May 8, 2013

Created a new ticket: http://bugs.jqueryui.com/ticket/9278

@daniel-o
Copy link
Author

daniel-o commented May 8, 2013

I modified the code to reflect all of the changes you guys posted. The conditions are much simpler.
Sorry about the tests not working on that first commit. I didn't commit the working versions. I've fixed that. Please let me know how they look now.

@scottgonzalez should I update the code to do a deep copy of the element being passed and attach that instead?

Edit: I guess I don't understand what you mean when you said, "I'm also concerned about what will happen if the same element is used for multiple instances"
If the same element is attached to multiple tooltip objects? If so I did some quick tests in the web developer console of my browser and it didn't "break" anything. Then again I'm not sure what the concern is so I don't know what result to look for here. If you can give me some direction on this I can check it out. Thanks.

@scottgonzalez
Copy link
Member

should I update the code to do a deep copy of the element being passed and attach that instead?

Cloning would require stripping all ids, which can be problematic.

I guess I don't understand what you mean when you said, "I'm also concerned about what will happen if the same element is used for multiple instances"

The concern is multiple tooltips open at the same time, using the same element.

I did some quick tests in the web developer console of my browser and it didn't "break" anything.

Did you try with simultaneous tooltips? I'm pretty sure that the current implementation will yank the element out of the first tooltip.

@scottgonzalez
Copy link
Member

We may just want to document that if you use an element, it must be limited to one tooltip. I would hope it'd be rare for anything else to happen anyway.

@daniel-o
Copy link
Author

I see what you're saying now and you're right about it yanking the element out of the first/previous tooltip(s).

I was thinking that there could possibly be a cloneContent option that could be set to true to clone the content if you wanted? Like you said though there is still the problem of handling the id attributes.

@scottgonzalez
Copy link
Member

We definitely won't be adding an option to control another option, so cloneContent isn't a consideration.

@daniel-o
Copy link
Author

Fair enough, I spent some time trying to figure out if that would be a silly suggestion but I obviously don't always have the best judgment.

content: element,
open: function( event, ui ) {
// Getting just the contents of the tooltip wrapper.
equal( ui.tooltip[ 0 ].firstChild.innerHTML, content );
Copy link
Member

Choose a reason for hiding this comment

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

This comparison looks questionable. Not sure about a better way to test this. Maybe domEqual can be used here. Also applies to the equal call below.

@jzaefferer
Copy link
Member

Thanks @daniel-o for the initial implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants