Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
1a393965
Commit
1a393965
authored
Apr 08, 2013
by
Oleg Gaidarenko
Committed by
Rick Waldron
Apr 08, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No ticket. Simplifies data methods and updates comments. Closes gh-1233
parent
ff3f83fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
17 deletions
+15
-17
data.js
src/data.js
+15
-17
No files found.
src/data.js
View file @
1a393965
...
@@ -49,7 +49,7 @@ Data.prototype = {
...
@@ -49,7 +49,7 @@ Data.prototype = {
descriptor
[
this
.
expando
]
=
{
value
:
unlock
};
descriptor
[
this
.
expando
]
=
{
value
:
unlock
};
Object
.
defineProperties
(
owner
,
descriptor
);
Object
.
defineProperties
(
owner
,
descriptor
);
// Support: Android
<
4
// Support: Android
<
4
// Fallback to a less secure definition
// Fallback to a less secure definition
}
catch
(
e
)
{
}
catch
(
e
)
{
descriptor
[
this
.
expando
]
=
unlock
;
descriptor
[
this
.
expando
]
=
unlock
;
...
@@ -92,8 +92,6 @@ Data.prototype = {
...
@@ -92,8 +92,6 @@ Data.prototype = {
}
}
}
}
}
}
return
this
;
},
},
get
:
function
(
owner
,
key
)
{
get
:
function
(
owner
,
key
)
{
// Either a valid cache is found, or will be created.
// Either a valid cache is found, or will be created.
...
@@ -136,11 +134,12 @@ Data.prototype = {
...
@@ -136,11 +134,12 @@ Data.prototype = {
},
},
remove
:
function
(
owner
,
key
)
{
remove
:
function
(
owner
,
key
)
{
var
i
,
name
,
var
i
,
name
,
unlock
=
this
.
key
(
owner
),
unlock
=
this
.
key
(
owner
),
cache
=
this
.
cache
[
unlock
];
cache
=
this
.
cache
[
unlock
];
if
(
key
===
undefined
)
{
if
(
key
===
undefined
)
{
this
.
cache
[
unlock
]
=
{};
this
.
cache
[
unlock
]
=
{};
}
else
{
}
else
{
// Support array or space separated string of keys
// Support array or space separated string of keys
if
(
jQuery
.
isArray
(
key
)
)
{
if
(
jQuery
.
isArray
(
key
)
)
{
...
@@ -166,7 +165,7 @@ Data.prototype = {
...
@@ -166,7 +165,7 @@ Data.prototype = {
i
=
name
.
length
;
i
=
name
.
length
;
while
(
i
--
)
{
while
(
i
--
)
{
delete
cache
[
name
[
i
]
];
delete
cache
[
name
[
i
]
];
}
}
}
}
},
},
...
@@ -210,7 +209,7 @@ jQuery.extend({
...
@@ -210,7 +209,7 @@ jQuery.extend({
},
},
removeData
:
function
(
elem
,
name
)
{
removeData
:
function
(
elem
,
name
)
{
return
data_user
.
remove
(
elem
,
name
);
data_user
.
remove
(
elem
,
name
);
},
},
// TODO: Replace all calls to _data and _removeData with direct
// TODO: Replace all calls to _data and _removeData with direct
...
@@ -225,14 +224,14 @@ jQuery.extend({
...
@@ -225,14 +224,14 @@ jQuery.extend({
},
},
_removeData
:
function
(
elem
,
name
)
{
_removeData
:
function
(
elem
,
name
)
{
return
data_priv
.
remove
(
elem
,
name
);
data_priv
.
remove
(
elem
,
name
);
}
}
});
});
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
data
:
function
(
key
,
value
)
{
data
:
function
(
key
,
value
)
{
var
attrs
,
name
,
var
attrs
,
name
,
elem
=
this
[
0
],
elem
=
this
[
0
],
i
=
0
,
i
=
0
,
data
=
null
;
data
=
null
;
...
@@ -244,7 +243,7 @@ jQuery.fn.extend({
...
@@ -244,7 +243,7 @@ jQuery.fn.extend({
if
(
elem
.
nodeType
===
1
&&
!
data_priv
.
get
(
elem
,
"hasDataAttrs"
)
)
{
if
(
elem
.
nodeType
===
1
&&
!
data_priv
.
get
(
elem
,
"hasDataAttrs"
)
)
{
attrs
=
elem
.
attributes
;
attrs
=
elem
.
attributes
;
for
(
;
i
<
attrs
.
length
;
i
++
)
{
for
(
;
i
<
attrs
.
length
;
i
++
)
{
name
=
attrs
[
i
].
name
;
name
=
attrs
[
i
].
name
;
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
name
=
jQuery
.
camelCase
(
name
.
substring
(
5
)
);
name
=
jQuery
.
camelCase
(
name
.
substring
(
5
)
);
...
@@ -267,12 +266,12 @@ jQuery.fn.extend({
...
@@ -267,12 +266,12 @@ jQuery.fn.extend({
return
jQuery
.
access
(
this
,
function
(
value
)
{
return
jQuery
.
access
(
this
,
function
(
value
)
{
var
data
,
var
data
,
camelKey
=
jQuery
.
camelCase
(
key
);
camelKey
=
jQuery
.
camelCase
(
key
);
// The calling jQuery object (element matches) is not empty
// The calling jQuery object (element matches) is not empty
// (and therefore has an element appears at this[
0
]) and the
// (and therefore has an element appears at this[
0
]) and the
// `value` parameter was not undefined. An empty jQuery object
// `value` parameter was not undefined. An empty jQuery object
// will result in `undefined` for elem = this[
0
] which will
// will result in `undefined` for elem = this[
0
] which will
// throw an exception if an attempt to read a data cache is made.
// throw an exception if an attempt to read a data cache is made.
if
(
elem
&&
value
===
undefined
)
{
if
(
elem
&&
value
===
undefined
)
{
// Attempt to get data from the cache
// Attempt to get data from the cache
...
@@ -297,7 +296,7 @@ jQuery.fn.extend({
...
@@ -297,7 +296,7 @@ jQuery.fn.extend({
}
}
// We tried really hard, but the data doesn't exist.
// We tried really hard, but the data doesn't exist.
return
undefined
;
return
;
}
}
// Set the data...
// Set the data...
...
@@ -311,10 +310,10 @@ jQuery.fn.extend({
...
@@ -311,10 +310,10 @@ jQuery.fn.extend({
// This might not apply to all properties...*
// This might not apply to all properties...*
data_user
.
set
(
this
,
camelKey
,
value
);
data_user
.
set
(
this
,
camelKey
,
value
);
// *... In the case of properties that might
ACTUALLY
// *... In the case of properties that might
_actually_
// have dashes, we need to also store a copy of that
// have dashes, we need to also store a copy of that
// unchanged property.
// unchanged property.
if
(
/-/
.
test
(
key
)
&&
data
!==
undefined
)
{
if
(
key
.
indexOf
(
"-"
)
!==
-
1
&&
data
!==
undefined
)
{
data_user
.
set
(
this
,
key
,
value
);
data_user
.
set
(
this
,
key
,
value
);
}
}
});
});
...
@@ -334,7 +333,6 @@ function dataAttr( elem, key, data ) {
...
@@ -334,7 +333,6 @@ function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
// data from the HTML5 data-* attribute
if
(
data
===
undefined
&&
elem
.
nodeType
===
1
)
{
if
(
data
===
undefined
&&
elem
.
nodeType
===
1
)
{
name
=
"data-"
+
key
.
replace
(
rmultiDash
,
"-$1"
).
toLowerCase
();
name
=
"data-"
+
key
.
replace
(
rmultiDash
,
"-$1"
).
toLowerCase
();
data
=
elem
.
getAttribute
(
name
);
data
=
elem
.
getAttribute
(
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment