aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-07-29 21:14:46 +0200
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-07-29 21:19:21 +0200
commit47835965bd100a3661d8299d8b769ceeb8b6ce48 (patch)
tree5ef322bc48cd27d5a5f004e6e3fcf955c67fc9eb /src/attributes
parent79b74e043a4ee737d44a95094ff1184e40bd5b16 (diff)
downloadjquery-47835965bd100a3661d8299d8b769ceeb8b6ce48.tar.gz
jquery-47835965bd100a3661d8299d8b769ceeb8b6ce48.zip
Selector: Inline Sizzle into the selector module
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
Diffstat (limited to 'src/attributes')
-rw-r--r--src/attributes/attr.js57
-rw-r--r--src/attributes/prop.js2
-rw-r--r--src/attributes/val.js2
3 files changed, 25 insertions, 36 deletions
diff --git a/src/attributes/attr.js b/src/attributes/attr.js
index 49d5e2550..afa4f5775 100644
--- a/src/attributes/attr.js
+++ b/src/attributes/attr.js
@@ -9,9 +9,6 @@ define( [
"use strict";
-var boolHook,
- attrHandle = jQuery.expr.attrHandle;
-
jQuery.fn.extend( {
attr: function( name, value ) {
return access( this, jQuery.attr, name, value, arguments.length > 1 );
@@ -42,8 +39,7 @@ jQuery.extend( {
// Attribute hooks are determined by the lowercase version
// Grab necessary hook if one is defined
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
- hooks = jQuery.attrHooks[ name.toLowerCase() ] ||
- ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );
+ hooks = jQuery.attrHooks[ name.toLowerCase() ];
}
if ( value !== undefined ) {
@@ -65,7 +61,7 @@ jQuery.extend( {
return ret;
}
- ret = jQuery.find.attr( elem, name );
+ ret = elem.getAttribute( name );
// Non-existent attributes return null, we normalize to undefined
return ret == null ? undefined : ret;
@@ -105,38 +101,31 @@ jQuery.extend( {
}
} );
-// Hooks for boolean attributes
-boolHook = {
- set: function( elem, value, name ) {
- if ( value === false ) {
-
- // Remove boolean attributes when set to false
- jQuery.removeAttr( elem, name );
- } else {
- elem.setAttribute( name, 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, handle,
- lowercaseName = name.toLowerCase();
+ jQuery.attrHooks[ name ] = {
+ get: function( elem ) {
+ var ret,
+ isXML = jQuery.isXMLDoc( elem ),
+ lowercaseName = name.toLowerCase();
+
+ if ( !isXML ) {
+ ret = elem.getAttribute( name ) != null ?
+ lowercaseName :
+ null;
+ }
+ return ret;
+ },
- if ( !isXML ) {
+ set: function( elem, value, name ) {
+ if ( value === false ) {
- // Avoid an infinite loop by temporarily removing this function from the getter
- handle = attrHandle[ lowercaseName ];
- attrHandle[ lowercaseName ] = ret;
- ret = getter( elem, name, isXML ) != null ?
- lowercaseName :
- null;
- attrHandle[ lowercaseName ] = handle;
+ // Remove boolean attributes when set to false
+ jQuery.removeAttr( elem, name );
+ } else {
+ elem.setAttribute( name, name );
+ }
+ return name;
}
- return ret;
};
} );
diff --git a/src/attributes/prop.js b/src/attributes/prop.js
index 71358aa92..651d9e215 100644
--- a/src/attributes/prop.js
+++ b/src/attributes/prop.js
@@ -64,7 +64,7 @@ jQuery.extend( {
// correct value when it hasn't been explicitly set
// https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
// Use proper attribute retrieval(#12072)
- var tabindex = jQuery.find.attr( elem, "tabindex" );
+ var tabindex = elem.getAttribute( "tabindex" );
if ( tabindex ) {
return parseInt( tabindex, 10 );
diff --git a/src/attributes/val.js b/src/attributes/val.js
index f7d6cf190..02559ffaa 100644
--- a/src/attributes/val.js
+++ b/src/attributes/val.js
@@ -84,7 +84,7 @@ jQuery.extend( {
option: {
get: function( elem ) {
- var val = jQuery.find.attr( elem, "value" );
+ var val = elem.getAttribute( "value" );
return val != null ?
val :