-
Notifications
You must be signed in to change notification settings - Fork 948
Selector: Properly implement :enabled/:disabled for select contents #384
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* Released under the MIT license | ||
* http://jquery.org/license | ||
* | ||
* Date: 2016-02-23 | ||
* Date: 2016-07-31 | ||
*/ | ||
(function( window ) { | ||
|
||
|
@@ -465,26 +465,54 @@ function createButtonPseudo( type ) { | |
* @param {Boolean} disabled true for :disabled; false for :enabled | ||
*/ | ||
function createDisabledPseudo( disabled ) { | ||
// Known :disabled false positives: | ||
// IE: *[disabled]:not(button, input, select, textarea, optgroup, option, menuitem, fieldset) | ||
// not IE: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable | ||
|
||
// Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable | ||
return function( elem ) { | ||
|
||
// Check form elements and option elements for explicit disabling | ||
return "label" in elem && elem.disabled === disabled || | ||
"form" in elem && elem.disabled === disabled || | ||
// Only certain elements can match :enabled or :disabled | ||
// https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled | ||
// https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled | ||
if ( "form" in elem ) { | ||
|
||
// Check for inherited disabledness on relevant non-disabled elements: | ||
// * listed form-associated elements in a disabled fieldset | ||
// https://html.spec.whatwg.org/multipage/forms.html#category-listed | ||
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled | ||
// * option elements in a disabled optgroup | ||
// https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled | ||
// All such elements have a "form" property. | ||
if ( elem.parentNode && elem.disabled === false ) { | ||
|
||
// Option elements defer to a parent optgroup if present | ||
if ( "label" in elem ) { | ||
if ( "label" in elem.parentNode ) { | ||
return elem.parentNode.disabled === disabled; | ||
} else { | ||
return elem.disabled === disabled; | ||
} | ||
} | ||
|
||
// Check non-disabled form elements for fieldset[disabled] ancestors | ||
"form" in elem && elem.disabled === false && ( | ||
// Support: IE6-11+ | ||
// Ancestry is covered for us | ||
elem.isDisabled === disabled || | ||
// Support: IE 6 - 11 | ||
// Use the isDisabled shortcut property to check for disabled fieldset ancestors | ||
return elem.isDisabled === disabled || | ||
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. Can we simplify this 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. Not really. The ternary form is worse. 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. Okay, will not propose here to try |
||
|
||
// Otherwise, assume any non-<option> under fieldset[disabled] is disabled | ||
/* jshint -W018 */ | ||
elem.isDisabled !== !disabled && | ||
("label" in elem || !disabledAncestor( elem )) !== disabled | ||
); | ||
// Where there is no isDisabled, check manually | ||
/* jshint -W018 */ | ||
elem.isDisabled !== !disabled && | ||
disabledAncestor( elem ) === disabled; | ||
} | ||
|
||
return elem.disabled === disabled; | ||
|
||
// Try to winnow out elements that can't be disabled before trusting the disabled property. | ||
// Some victims get caught in our net (label, legend, menu, track), but it shouldn't | ||
// even exist on them, let alone have a boolean value. | ||
} else if ( "label" in elem ) { | ||
return elem.disabled === disabled; | ||
} | ||
|
||
// Remaining elements are neither :enabled nor :disabled | ||
return false; | ||
}; | ||
} | ||
|
||
|
@@ -1693,6 +1721,7 @@ function addCombinator( matcher, combinator, base ) { | |
return matcher( elem, context, xml ); | ||
} | ||
} | ||
return false; | ||
} : | ||
|
||
// Check against all ancestor/preceding elements | ||
|
@@ -1737,6 +1766,7 @@ function addCombinator( matcher, combinator, base ) { | |
} | ||
} | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
|
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.
Just curious, does the
else
here help uglify produce the desired ternary?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.
It's not necessary, I just used it to establish the especially close link between those branches (i.e., option-in-optgroup vs. naked option).
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.
Yeah, had the same question, I think it is established practise to remove redundant
else
statements, but it is not contradicts our style guide