-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Tooltip: Remove name and id from tooltip content #1525
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,3 +220,35 @@ asyncTest( "multiple active delegated tooltips", function() { | |
| }); | ||
|
|
||
| }( jQuery ) ); | ||
|
|
||
| // http://bugs.jqueryui.com/ticket/11272 | ||
| test ( "remove radio button conflict with live Region and tooltip content", function () { | ||
| expect( 3 ); | ||
| var content = "<div id='content'>" + | ||
| "<input type='radio' name='hobby' checked='checked'><label>option 1</label>" + | ||
| "<input type='radio' name='hobby'><label>option 2</label>" + | ||
| "</div>", | ||
| stripped_content = "<div>" + | ||
| "<input checked=\"checked\" type=\"radio\"><label>option 1</label>" + | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you using single quotes above and escaped double quotes here? Be consistent. |
||
| "<input type=\"radio\"><label>option 2</label>" + | ||
| "</div>", | ||
| element = $( content ); | ||
| $( "#tooltipped1" ).tooltip({ | ||
| content: element, | ||
| open: function( event, ui ) { | ||
| equal( ui.tooltip.children().html().toLowerCase(), stripped_content ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit brittle. Is it even consistent across all browsers?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are definitely right this is probably too brittle I was thinking it might be better to assert that the content does not contain "name" and "id" with a string search? Rather than trying to match the exact output of .html()
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should probably just search for the DOM structure you care about and then make assertions based on the elements' attributes. |
||
| } | ||
| }).tooltip( "open" ).tooltip( "destroy" ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing line breaks and indentation. Please see the style guide. |
||
| $( "#tooltipped1" ).tooltip({ | ||
| content: element[0], | ||
| open: function( event, ui ) { | ||
| equal( ui.tooltip.children().html().toLowerCase(), stripped_content ); | ||
| } | ||
| }).tooltip( "open" ).tooltip( "destroy" ); | ||
| $( "#tooltipped1" ).tooltip({ | ||
| content: content, | ||
| open: function( event, ui ) { | ||
| equal( ui.tooltip.children().html().toLowerCase(), stripped_content ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add messages to make it more obvious what's failing if we regress. |
||
| } | ||
| }).tooltip( "open" ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,14 +280,28 @@ $.widget( "ui.tooltip", { | |
| tooltipData = this._tooltip( target ); | ||
| tooltip = tooltipData.tooltip; | ||
| this._addDescribedBy( target, tooltip.attr( "id" ) ); | ||
| // Parse content into DOM remove attributes id and name | ||
| if ( typeof content === "string" || content.nodeType ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't remove existing blank lines; this violates our style guide. |
||
| if ( typeof content === "string" ) { | ||
| tooltip_content_div = document.createElement("div"); | ||
| tooltip_content_div.innerHTML = content; | ||
| dom_content = $(tooltip_content_div); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is silly, use jQuery. |
||
| } else { | ||
| dom_content = $("<div>").html( content ); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting these is wasteful, they're the exact same logic in jQuery. |
||
| dom_content.find( "[id]" ).removeAttr( "id" ); | ||
| dom_content.find( "[name]" ).removeAttr( "name" ); | ||
| content = dom_content.html(); | ||
| } else if ( content.jquery ) { | ||
| content.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" ); | ||
| content.removeAttr( "name" ).find( "[name]" ).removeAttr( "name" ); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splitting these is also wasteful. |
||
| tooltip.find( ".ui-tooltip-content" ).html( content ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't do all of this stripping before putting the content into the tooltip. Then the content won't work. You have to follow the previous logic of only stripping for the live region.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey scott I am working on all the other fixes mentioned here and I read the jshint output. Could you please further explain this comment. Based on my tests if I don't strip before putting the content into the tooltip then it will have already interfered with the other radio buttons on the page. What problems does the stripping cause with the content?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What other radios on the page? Can you please provide the use case you're considering?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based this jsfiddle off the issue https://jsfiddle.net/o2wk14tq/ .
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're effectively cloning existing content. Can you explain why you would do that for a tooltip?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I finished all the revisions, so thanks so much for the help with the style guide issues, it was a little hard to understand everything =D
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because you're ensuring that they break for other valid uses. Content supplied as the tooltip should be used as is. Only problems created by the live region are considered bugs here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, ok then we agree, I will make a note in the issue with an explanation that this stripping has to be done by the user if they wish to clone existing content into a tooltip. |
||
|
|
||
| // 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(); | ||
| a11yContent = $( "<div>" ).html( tooltip.find( ".ui-tooltip-content" ).html() ); | ||
| a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" ); | ||
| a11yContent.appendTo( this.liveRegion ); | ||
|
|
||
| function position( event ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCase variable names.