-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Datepicker: Make sure text option are text, shorten HTML strings #1953
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
Conversation
ui/widgets/datepicker.js
Outdated
" title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w" ) + "'>" + prevText + "</span></a>" : | ||
( hideIfNoPrevNext ? "" : "<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w" ) + "'>" + prevText + "</span></a>" ) ); | ||
if ( this._canAdjustMonth( inst, -1, drawYear, drawMonth ) ) { | ||
prev = $( "<a></a>" ) |
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.
"<a>"
should be enough or is there a reason you added the closing tag here?
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.
The string I used is natively compliant with both HTML & XHTML, although for the single tag case it doesn't matter much as jQuery uses a shortcut that just does document.createElement
then. I can change it to "<a>"
.
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.
Using <a>
would be more consistent with what we have in other (more modern, UI widget factory using) widgets.
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.
@fnagel Although it's safe to do a single unclosed tag, an unclosed tag with attributes or several unclosed tags in a string can be an issue. It's been hard to explain these subtle differences to people so closing tags is a good practice.
I guess another option would be <a />
which jQuery also shortcuts to document.createElement
? Not sure if that's better or not.
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.
@dmethvin Sadly, the linked news does not provide a recommendation what is the best practice. Looks like best thing to do is using closed tags, right?
I would suggest to keep this consistent with all other widgets (using single, unclosed tags if no attributes are used) and then do a PR changing this to single closed tags.
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.
The code deciding on whether to use the shortcut or not is here:
https://github.com/jquery/jquery/blob/a70274632dc19ff4a64d7bb7657a2cc647ff38b9/src/core/parseHTML.js#L35-L43
If the regex matches, the simple route is chosen. As Dave mention, just adding an attribute will break it, though, which makes $("<div>")
work fine in XHTML mode but $("<div a='b'>")
break. It's safer to always close tags for this reason. $("<div a='b' />")
would work, though - in HTML mode the slash is ignored and in XHTML mode all tags can be self-closing. Because />
is generally just >
in HTML mode, though, the fact that it works is a bit magical. But maybe that's fine.
I'm fine with making the change here as advised and modifying all single tags separately in a subsequent PR.
ui/widgets/datepicker.js
Outdated
" title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e" ) + "'>" + nextText + "</span></a>" : | ||
( hideIfNoPrevNext ? "" : "<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e" ) + "'>" + nextText + "</span></a>" ) ); | ||
if ( this._canAdjustMonth( inst, +1, drawYear, drawMonth ) ) { | ||
next = $( "<a></a>" ) |
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.
See comment above.
ui/widgets/datepicker.js
Outdated
} else if ( hideIfNoPrevNext ) { | ||
prev = ""; | ||
} else { | ||
prev = $( "<a></a>" ) |
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.
See comment above.
ui/widgets/datepicker.js
Outdated
} else if ( hideIfNoPrevNext ) { | ||
next = ""; | ||
} else { | ||
next = $( "<a></a>" ) |
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.
See comment above.
ui/widgets/datepicker.js
Outdated
">" + currentText + "</button>" : "" ) + ( isRTL ? "" : controls ) + "</div>" : ""; | ||
controls = ""; | ||
if ( !inst.inline ) { | ||
controls = $( "<button></button>" ) |
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.
Same here: is there a reason you added the closing tag?
ui/widgets/datepicker.js
Outdated
title: buttonText | ||
} ); | ||
} else { | ||
inst.trigger = $( "<button type='button'></button>" ) |
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.
Closing tag not needed.
ui/widgets/datepicker.js
Outdated
@@ -240,7 +240,9 @@ $.extend( Datepicker.prototype, { | |||
inst.append.remove(); | |||
} | |||
if ( appendText ) { | |||
inst.append = $( "<span class='" + this._appendClass + "'>" + appendText + "</span>" ); | |||
inst.append = $( "<span></span>" ) | |||
.attr( "class", this._appendClass ) |
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.
Why not using addClass
here?
ui/widgets/datepicker.js
Outdated
} ) | ||
.append( | ||
$( "<span>" ) | ||
.attr( "class", "ui-icon ui-icon-circle-triangle-" + |
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.
Why not using addClass
here?
ui/widgets/datepicker.js
Outdated
} ) | ||
.append( | ||
$( "<span>" ) | ||
.attr( "class", "ui-icon ui-icon-circle-triangle-" + |
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.
Why not using addClass
here?
ui/widgets/datepicker.js
Outdated
} ) | ||
.append( | ||
$( "<span>" ) | ||
.attr( "class", "ui-icon ui-icon-circle-triangle-" + |
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.
Why not using addClass
here?
Instead of using enormous HTML strings, various elements are now constructed using jQuery APIs. This makes it more obvious user-provided data is used correctly. Fixes #15284
5a69022
to
7cd8b25
Compare
49ccf42
to
463654d
Compare
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.
+1 by reading
Instead of using enormous HTML strings, various elements are now constructed
using jQuery APIs. This makes it more obvious user-provided data is used
correctly.
Fixes #15284