aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes/attr.js
Commit message (Collapse)AuthorAgeFilesLines
* Attributes: Make `.attr( name, false )` remove for all non-ARIA attrsMichał Gołębiowski-Owczarek2024-03-201-30/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The HTML spec defines boolean attributes: https://html.spec.whatwg.org/#boolean-attributes that often correlate with boolean properties. If the attribute is missing, it correlates with the `false` property value, if it's present - the `true` property value. The only valid values are an empty string or the attribute name. jQuery tried to be helpful here and treated boolean attributes in a special way in the `.attr()` API: 1. For the getter, as long as the attribute was present, it was returning the attribute name lowercased, ignoring the value. 2. For the setter, it was removing the attribute when `false` was passed; otherwise, it was ignoring the passed value and set the attribute - interestingly, in jQuery `>=3` not lowercased anymore. The problem is the spec occasionally converts boolean attributes into ones with additional attribute values with special behavior - one such example is the new `"until-found"` value for the `hidden` attribute. Our setter normalization means passing those values is impossible with jQuery. Also, new boolean attributes are introduced occasionally and jQuery cannot easily add them to the list without incurring breaking changes. This patch removes any special handling of boolean attributes - the getter returns the value as-is and the setter sets the provided value. To provide better backwards compatibility with the very frequent `false` value provided to remove the attribute, this patch makes `false` trigger attribute removal for ALL non-ARIA attributes. ARIA attributes are exempt from the rule since many of them recognize `"false"` as a valid value with semantics different than the attribute missing. To remove an ARIA attribute, use `.removeAttr()` or pass `null` as the value to `.attr()` which doesn't have this exception. Fixes gh-5388 Closes gh-5452 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
* Attributes: Shave off a couple of bytesMichał Gołębiowski-Owczarek2024-01-311-10/+3
| | | | | | | | | | | | | | | | | | The `attrHooks` entries for boolean attributes are only defined for jQuery 4+; jQuery 3.x used a separate mechanism - assigning them to `jQuery.expr.attrHandle`. That object used to be maintained by Sizzle, since jQuery 3.7.0 it's kept in the selector module. Because of that, the `isXMLDoc` check used to be require in this hook. Now that standard `attrHooks` are used, the `isXMLDoc` check already happens inside of `jQuery.attr` and there's no need to repeat it in the test. Note that this repetition is even incorrect - while Sizzle's `jQuery.find.attr` used to treat an `undefined` output of the hooks from `jQuery.expr.attrHandle` as a way to opt out of the hook, jQuery's `attrHooks` use `null` to opt out of a getter hook. Apart from the size, this patch also avoids unnecessary extra checks. Closes gh-5398
* Selector: Make `selector.js` module depend on `attributes/attr.js`Michał Gołębiowski-Owczarek2024-01-121-1/+9
| | | | | | | | | This fixes custom builds using the `--include` switch that don't include the `attributes` module. Fixes gh-5379 Closes gh-5384 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
* Selector: Eliminate `selector.js` depenencies from various modulesMichał Gołębiowski-Owczarek2024-01-041-2/+0
| | | | | | | | | There are two main reasons for why some of those dependencies are no longer needed: 1. `jQuery.contains` which is now a part of `core`. 2. `jQuery.find.attr` no longer exists, native `getAttribute` is used instead. Closes gh-5383 Ref gh-5379
* Core: Use named exports in `src/`Michał Gołębiowski-Owczarek2023-09-121-5/+5
| | | | | | | | | The `default` export is treated differently across tooling when transpiled to CommonJS - tools differ on whether `module.exports` represents the full module object or just its default export. Switch `src/` modules to named exports for tooling consistency. Fixes gh-5262 Closes gh-5292
* Attributes: Don't stringify attributes in the setterMichał Gołębiowski-Owczarek2021-11-011-1/+1
| | | | | | | | | | | | | Stringifying attributes in the setter was needed for IE <=9 but it breaks trusted types enforcement when setting a script `src` attribute. Note that this doesn't mean script execution works. Since jQuery disables all scripts by changing their type and then executes them by creating fresh script tags with proper `src` & possibly other attributes, this unwraps any trusted `src` wrappers, making the script not execute under strict CSP settings. We might try to fix it in the future in a separate change. Fixes gh-4948 Closes gh-4949
* Attributes: Don't set the type attr hook at all outside of IEMichał Gołębiowski-Owczarek2020-01-131-17/+18
| | | | | This removes a needless function call in modern browsers. Closes gh-4587
* Core: Migrate from AMD to ES modules 🎉Michał Gołębiowski-Owczarek2019-11-181-11/+6
| | | | | | | | | | | | | | | | | | | | | | Migrate all source AMD modules to ECMAScript modules. The final bundle is compiled by a custom build process that uses Rollup under the hood. Test files themselves are still loaded via RequireJS as that has to work in IE 11. Tests can now be run in "Load as modules" mode which replaces the previous "Load with AMD" option. That option of running tests doesn't work in IE and Edge as it requires support for dynamic imports. Some of the changes required by the migration: * check `typeof` of `noGlobal` instead of using the variable directly as it's not available when modules are used * change the nonce module to be an object as ECMASscript module exports are immutable * remove some unused exports * import `./core/parseHTML.js` directly in `jquery.js` so that it's not being cut out when the `ajax` module is excluded in a custom compilation Closes gh-4541
* Selector: Inline Sizzle into the selector moduleMichał Gołębiowski-Owczarek2019-07-291-34/+23
| | | | | | | | | | | | | | | | | | This commit removes Sizzle from jQuery, inlining its code & removing obsolete workarounds where applicable. The selector-native module has been removed. Further work on the selector module may decrease the size enough that it will no longer be necessary. If it turns out it's still useful, we'll reinstate it but the code will look different anyway as we'll want to share as much code as possible with the existing selector module. The Sizzle AUTHORS.txt file has been merged with the jQuery one - people are sorted by their first contributions to either of the two repositories. The commit reduces the gzipped jQuery size by 1460 bytes compared to master. Closes gh-4395
* Build: ESLint: forbid unused function parametersMichał Gołębiowski-Owczarek2019-05-131-1/+1
| | | | | | | | | | | | | This commit requires all function parameters to be used, not just the last one. In cases where that's not possible as we need to match an external API, there's an escape hatch of prefixing an unused argument with `_`. This change makes it easier to catch unused AMD dependencies and unused parameters in internal functions the API of which we may change at will, among other things. Unused AMD dependencies have been removed as part of this commit. Closes gh-4381
* Core: Remove IE-specific support tests, rely on document.documentModeMichał Gołębiowski-Owczarek2019-05-131-4/+6
| | | | | | | Also, update some tests to IE-sniff when deciding whether to skip a test. Fixes gh-4386 Closes gh-4387
* Core: Deprecate jQuery.nodeNamekaran-962017-03-011-2/+3
| | | | | Fixes gh-3475 Closes gh-3505
* Core: rnotwhite -> rhtmlnotwhite and jQuery.trim -> stripAndCollapseTimmy Willison2016-09-151-3/+6
| | | | | | | | | | | | - Renames and changes rnotwhite to focus on HTML whitespace chars - Change internal use of jQuery.trim to more accurate strip and collapse - Adds tests to ensure HTML space characters are retained where valid - Doesn't add tests where the difference is inconsequential and existing tests are adequate. Fixes gh-3003 Fixes gh-3072 Close gh-3316
* Attributes: Avoid infinite recursion on non-lowercase attribute gettersMichał Gołębiowski2016-06-031-5/+7
| | | | | | | | | | | | Attribute hooks are determined for the lowercase versions of attribute names but this has not been reflected in the bool attribute hooks. The code that temporarily removed a handler to avoid an infinite loop was removing an incorrect handler causing stack overflow. Fixes gh-3133 Refs gh-2914 Refs gh-2916 Closes gh-3134
* Docs: Fix an incorrect comment in the attributes moduleMichał Gołębiowski2016-06-031-1/+1
| | | | | Attributes are no longer always treated as lowercase, although hooks for them are. This commit fixes a no longer correct comment.
* Build: Put all AMD modules in "src/" in strict modeMichał Gołębiowski2016-04-251-0/+2
| | | | Fixes gh-3073
* Attributes: remove the lower-casing logic for attribute namesMichał Gołębiowski2016-02-171-10/+2
| | | | | | | | | | | | | | | jQuery used to lower-case the attribute names passed to the .attr setter to workaround an old IE issue. This is no longer in jQuery 3.0 and removing it may even "accidentally" make this API sort-of work on SVGs (see gh-2910) so why not. Manual lowercasing had to be added to the place where the proper attrHook is retrieved so that it works regardless of the casing of the provided name. A regular `toLowerCase()` is enough there as those few attributes don't contain any non-ASCII characters. Fixes gh-2914 Closes gh-2916
* Attributes: exclusively lowercase A-Z in attribute namesTimmy Willison2015-12-021-2/+9
| | | | | Fixes gh-2730 Close gh-2749
* Attributes: do not set properties to false when removing booleansTimmy Willison2015-10-211-10/+2
| | | | Fixes gh-1759
* Build: Update jscs and lint filesOleg Gaidarenko2015-09-071-10/+12
| | | | Fixes gh-2056
* Core: organize prop & attr code to be similarGilad Peleg2015-06-231-36/+34
| | | | Closes gh-2384
* Core: Align branches: remove an unused variable, add commentsMichał Gołębiowski2015-04-271-2/+2
| | | | Closes gh-2233
* Attributes: remove unnecessary element null checkBastian Buchholz2015-04-201-1/+1
| | | | Close gh-2201
* Attributes: revert returning null for non-existant attributesTimmy Willison2015-03-301-1/+6
| | | | Ref https://github.com/jquery/jquery/issues/2118
* Attributes: revert returning null for non-elementsTimmy Willison2015-03-161-1/+1
|
* Attributes: fix failing test for new return valueTimmy Willison2015-03-161-1/+1
|
* Attributes: return null when attribute does not existWinston Howes2015-03-161-6/+1
| | | | | Fixes gh-2118 Close gh-2129
* Attr: Use typeof check for getAttribute methodOleg Gaidarenko2014-09-021-1/+1
| | | | Ref 29838b6cab6f2e508f3e9692f32918c72b1a504b
* Core: Drop strundefined variableChris Antaki2014-09-021-3/+2
|
* Build: update grunt-jscs-checker and pass with the new rulesTimmy Willison2014-07-171-1/+3
|
* Support: clean up comments and Support notationDave Methvin2014-06-101-2/+0
| | | | Closes gh-1577
* Break jQuery.access out into its own module to separate it from core; Adjust ↵Timmy Willison2013-09-091-2/+3
| | | | CommonJS+AMD build support to include non-var dependencies. Convert modules with more than a few dependencies to use CJS+AMD syntax.
* Fix #10814. Make support tests lazy and broken out to components.Michał Gołębiowski2013-09-061-4/+5
|
* Fix for custom attr handles duck-punching the boolean attr handleTimmy Willison2013-08-281-18/+15
| | | | | Conflicts: src/attributes/attr.js
* Specify support as a dependency wherever it is used. Optimize module order ↵Timmy Willison2013-08-151-1/+2
| | | | to save 15 bytes.
* AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.Timmy Willison2013-08-151-0/+143