-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Attributes: Support the until-found
value for the hidden
attribute
#5607
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
6ee4613
to
2aba711
Compare
Mentioning
|
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.
LGTM!
@gibson042 I pushed the smaller version in the second commit, you can compare the two & suggest improvements. |
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.
Compression pass:
raw gz Compared to last run
-52 -6 dist/jquery.js
-13 -17 dist/jquery.min.js
src/attributes/attr.js
Outdated
} else if ( | ||
name.toLowerCase() !== "hidden" || | ||
String( value ).toLowerCase() !== "until-found" | ||
) { | ||
elem.setAttribute( name, name ); | ||
} else { | ||
elem.setAttribute( name, value ); |
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.
} else if ( | |
name.toLowerCase() !== "hidden" || | |
String( value ).toLowerCase() !== "until-found" | |
) { | |
elem.setAttribute( name, name ); | |
} else { | |
elem.setAttribute( name, value ); | |
} else { | |
elem.setAttribute( name, name.toLowerCase() === "hidden" && | |
strValue.toLowerCase() === "until-found" ? strValue : name ); |
(with var strValue = String( value );
)
src/attributes/attr.js
Outdated
if ( ret != null ) { | ||
if ( lowercaseName !== "hidden" || | ||
ret.toLowerCase() !== "until-found" | ||
) { | ||
ret = lowercaseName; | ||
} | ||
} |
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.
if ( ret != null ) { | |
if ( lowercaseName !== "hidden" || | |
ret.toLowerCase() !== "until-found" | |
) { | |
ret = lowercaseName; | |
} | |
} | |
ret = ret == null || lowercaseName === "hidden" && | |
ret.toLowerCase() === "until-found" ? ret : lowercaseName; |
@gibson042 I applied your suggestions but I got a different diff compared to my second commit:
I pushed it, can you have a look? The diff from
|
32391cf
to
e47c8b5
Compare
@mgol Confirmed your numbers; I must have been doing something slightly different before. I think we're close to a local maximum, but vs. the current state,
is possible by refactoring variable declarations: boolHook = {
set: function( elem, value, name ) {
var strValue = String( value ),
lowercaseName = name.toLowerCase();
if ( value === false ) {
// Remove boolean attributes when set to false
jQuery.removeAttr( elem, name );
} else {
elem.setAttribute( name,
lowercaseName === "hidden" &&
strValue.toLowerCase() === "until-found" ?
strValue :
name
);
}
return name;
}
};
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) {
var getter = attrHandle[ name ] || jQuery.find.attr;
attrHandle[ name ] = function( elem, name, isXML ) {
var ret,
lowercaseName = name.toLowerCase(),
handle = attrHandle[ lowercaseName ];
if ( !isXML ) {
// Avoid an infinite loop by temporarily removing this function from the getter
attrHandle[ lowercaseName ] = ret;
ret = getter( elem, name, isXML );
ret = ret == null ||
( lowercaseName === "hidden" && ret.toLowerCase() === "until-found" ) ?
ret :
lowercaseName;
attrHandle[ lowercaseName ] = handle;
}
return ret;
};
} ); |
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. That said, currently from the attributes we treat as boolean only `hidden` has gained an extra value, let's support it. Ref jquerygh-5388 Ref jquerygh-5452
e47c8b5
to
9c8e3e3
Compare
@gibson042 I am getting a different diff for this version of
|
I'm going to merge it as-is; feel free to submit a PR with various size improvements if you find them. |
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from jquerygh-5607 which landed on `3.x-stable` so that we do test it. Ref jquerygh-5452 Ref jquerygh-5607 (cherry picked from commit 85290c5)
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in jquerygh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from jquerygh-5607 which landed on `3.x-stable` so that we do test it. Ref jquerygh-5452 Ref jquerygh-5607 (cherry picked from commit 85290c5)
The `hidden` attribute used to be a boolean one but it gained a new `until-found` eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in gh-5452 to avoid these issues in the future. We haven't added an explicit test for the `"until-found"` value of the `hidden` attribute which triggered this decision so far, though. Backport the test from gh-5607 which landed on `3.x-stable` so that we do test it. Closes gh-5619 Ref gh-5452 Ref gh-5607 (cherry picked from commit 85290c5)
Summary
The
hidden
attribute used to be a boolean one but it gained a newuntil-found
eventually. This led us to change the way we handle boolean attributes in jQuery 4.0 in gh-5452 to avoid these issues in the future.That said, currently from the attributes we treat as boolean only
hidden
has gained an extra value, let's support it.Ref gh-5388
Ref gh-5452
The cost is currently quite high:
It's possible it could be lowered if we removed the infra for adding future attributes to the list and just mentioned
hidden
&until-found
explicitly in both the getter & setter.Another alternative is to avoid changing the
3.x
line and instead add a note to the docs, showing how to define an attrHook forhidden
that will achieve the same result.Checklist