|
6 | 6 | * Released under the MIT license
|
7 | 7 | * http://jquery.org/license
|
8 | 8 | *
|
9 |
| - * Date: 2016-02-23 |
| 9 | + * Date: 2016-08-08 |
10 | 10 | */
|
11 | 11 | (function( window ) {
|
12 | 12 |
|
@@ -465,26 +465,54 @@ function createButtonPseudo( type ) {
|
465 | 465 | * @param {Boolean} disabled true for :disabled; false for :enabled
|
466 | 466 | */
|
467 | 467 | function createDisabledPseudo( disabled ) {
|
468 |
| - // Known :disabled false positives: |
469 |
| - // IE: *[disabled]:not(button, input, select, textarea, optgroup, option, menuitem, fieldset) |
470 |
| - // not IE: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable |
| 468 | + |
| 469 | + // Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable |
471 | 470 | return function( elem ) {
|
472 | 471 |
|
473 |
| - // Check form elements and option elements for explicit disabling |
474 |
| - return "label" in elem && elem.disabled === disabled || |
475 |
| - "form" in elem && elem.disabled === disabled || |
| 472 | + // Only certain elements can match :enabled or :disabled |
| 473 | + // https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled |
| 474 | + // https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled |
| 475 | + if ( "form" in elem ) { |
| 476 | + |
| 477 | + // Check for inherited disabledness on relevant non-disabled elements: |
| 478 | + // * listed form-associated elements in a disabled fieldset |
| 479 | + // https://html.spec.whatwg.org/multipage/forms.html#category-listed |
| 480 | + // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled |
| 481 | + // * option elements in a disabled optgroup |
| 482 | + // https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled |
| 483 | + // All such elements have a "form" property. |
| 484 | + if ( elem.parentNode && elem.disabled === false ) { |
| 485 | + |
| 486 | + // Option elements defer to a parent optgroup if present |
| 487 | + if ( "label" in elem ) { |
| 488 | + if ( "label" in elem.parentNode ) { |
| 489 | + return elem.parentNode.disabled === disabled; |
| 490 | + } else { |
| 491 | + return elem.disabled === disabled; |
| 492 | + } |
| 493 | + } |
476 | 494 |
|
477 |
| - // Check non-disabled form elements for fieldset[disabled] ancestors |
478 |
| - "form" in elem && elem.disabled === false && ( |
479 |
| - // Support: IE6-11+ |
480 |
| - // Ancestry is covered for us |
481 |
| - elem.isDisabled === disabled || |
| 495 | + // Support: IE 6 - 11 |
| 496 | + // Use the isDisabled shortcut property to check for disabled fieldset ancestors |
| 497 | + return elem.isDisabled === disabled || |
482 | 498 |
|
483 |
| - // Otherwise, assume any non-<option> under fieldset[disabled] is disabled |
484 |
| - /* jshint -W018 */ |
485 |
| - elem.isDisabled !== !disabled && |
486 |
| - ("label" in elem || !disabledAncestor( elem )) !== disabled |
487 |
| - ); |
| 499 | + // Where there is no isDisabled, check manually |
| 500 | + /* jshint -W018 */ |
| 501 | + elem.isDisabled !== !disabled && |
| 502 | + disabledAncestor( elem ) === disabled; |
| 503 | + } |
| 504 | + |
| 505 | + return elem.disabled === disabled; |
| 506 | + |
| 507 | + // Try to winnow out elements that can't be disabled before trusting the disabled property. |
| 508 | + // Some victims get caught in our net (label, legend, menu, track), but it shouldn't |
| 509 | + // even exist on them, let alone have a boolean value. |
| 510 | + } else if ( "label" in elem ) { |
| 511 | + return elem.disabled === disabled; |
| 512 | + } |
| 513 | + |
| 514 | + // Remaining elements are neither :enabled nor :disabled |
| 515 | + return false; |
488 | 516 | };
|
489 | 517 | }
|
490 | 518 |
|
@@ -1693,6 +1721,7 @@ function addCombinator( matcher, combinator, base ) {
|
1693 | 1721 | return matcher( elem, context, xml );
|
1694 | 1722 | }
|
1695 | 1723 | }
|
| 1724 | + return false; |
1696 | 1725 | } :
|
1697 | 1726 |
|
1698 | 1727 | // Check against all ancestor/preceding elements
|
@@ -1737,6 +1766,7 @@ function addCombinator( matcher, combinator, base ) {
|
1737 | 1766 | }
|
1738 | 1767 | }
|
1739 | 1768 | }
|
| 1769 | + return false; |
1740 | 1770 | };
|
1741 | 1771 | }
|
1742 | 1772 |
|
|
0 commit comments