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
f8baea8f
Commit
f8baea8f
authored
Jul 06, 2012
by
Richard Gibson
Committed by
Dave Methvin
Jul 06, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY out removeData/cleanData, closes gh-838.
parent
7532bd7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
74 deletions
+63
-74
data.js
src/data.js
+14
-38
manipulation.js
src/manipulation.js
+49
-36
No files found.
src/data.js
View file @
f8baea8f
...
...
@@ -128,16 +128,11 @@ jQuery.extend({
var
thisCache
,
i
,
l
,
// Reference to internal data cache key
internalKey
=
jQuery
.
expando
,
isNode
=
elem
.
nodeType
,
// See jQuery.data for more information
cache
=
isNode
?
jQuery
.
cache
:
elem
,
// See jQuery.data for more information
id
=
isNode
?
elem
[
internalKey
]
:
internalKey
;
id
=
isNode
?
elem
[
jQuery
.
expando
]
:
jQuery
.
expando
;
// If there is already no cache entry for this object, there is no
// purpose in continuing
...
...
@@ -164,7 +159,7 @@ jQuery.extend({
if
(
name
in
thisCache
)
{
name
=
[
name
];
}
else
{
name
=
name
.
split
(
" "
);
name
=
name
.
split
(
" "
);
}
}
}
...
...
@@ -187,37 +182,23 @@ jQuery.extend({
// Don't destroy the parent cache unless the internal data object
// had been the only thing left in it
if
(
!
isEmptyDataObject
(
cache
[
id
]
)
)
{
if
(
!
isEmptyDataObject
(
cache
[
id
]
)
)
{
return
;
}
}
// Browsers that fail expando deletion also refuse to delete expandos on
// the window, but it will allow it on all other JS objects; other browsers
// don't care
// Ensure that `cache` is not a window object #10080
if
(
jQuery
.
support
.
deleteExpando
||
!
cache
.
setInterval
)
{
// Destroy the cache
if
(
isNode
)
{
jQuery
.
cleanData
(
[
elem
],
true
);
// Use delete when supported for expandos or `cache` is not a window per isWindow (#10080)
}
else
if
(
jQuery
.
support
.
deleteExpando
||
cache
!=
cache
.
window
)
{
delete
cache
[
id
];
// When all else fails, null
}
else
{
cache
[
id
]
=
null
;
}
// We destroyed the cache and need to eliminate the expando on the node to avoid
// false lookups in the cache for entries that no longer exist
if
(
isNode
)
{
jQuery
.
deletedIds
.
push
(
id
);
// IE does not allow us to delete expando properties from nodes,
// nor does it have a removeAttribute function on Document nodes;
// we must handle all of these cases
if
(
jQuery
.
support
.
deleteExpando
)
{
delete
elem
[
internalKey
];
}
else
if
(
elem
.
removeAttribute
)
{
elem
.
removeAttribute
(
internalKey
);
}
else
{
elem
[
internalKey
]
=
null
;
}
}
},
// For internal use only.
...
...
@@ -227,15 +208,10 @@ jQuery.extend({
// A method for determining if a DOM node can handle the data expando
acceptData
:
function
(
elem
)
{
if
(
elem
.
nodeName
)
{
var
match
=
jQuery
.
noData
[
elem
.
nodeName
.
toLowerCase
()
];
if
(
match
)
{
return
!
(
match
===
true
||
elem
.
getAttribute
(
"classid"
)
!==
match
);
}
}
var
noData
=
elem
.
nodeName
&&
jQuery
.
noData
[
elem
.
nodeName
.
toLowerCase
()
];
return
true
;
// nodes accept data unless otherwise specified; rejection can be conditional
return
!
noData
||
noData
!==
true
&&
elem
.
getAttribute
(
"classid"
)
===
noData
;
}
});
...
...
src/manipulation.js
View file @
f8baea8f
...
...
@@ -347,14 +347,18 @@ jQuery.fn.extend({
if
(
scripts
.
length
)
{
jQuery
.
each
(
scripts
,
function
(
i
,
elem
)
{
if
(
elem
.
src
)
{
jQuery
.
ajax
?
jQuery
.
ajax
({
url
:
elem
.
src
,
type
:
"GET"
,
dataType
:
"script"
,
async
:
false
,
global
:
false
,
throws
:
true
})
:
jQuery
.
error
(
"no ajax"
);
if
(
jQuery
.
ajax
)
{
jQuery
.
ajax
({
url
:
elem
.
src
,
type
:
"GET"
,
dataType
:
"script"
,
async
:
false
,
global
:
false
,
throws
:
true
});
}
else
{
jQuery
.
error
(
"no ajax"
);
}
}
else
{
jQuery
.
globalEval
(
(
elem
.
text
||
elem
.
textContent
||
elem
.
innerHTML
||
""
).
replace
(
rcleanScript
,
""
)
);
}
...
...
@@ -760,45 +764,54 @@ jQuery.extend({
return
ret
;
},
cleanData
:
function
(
elems
)
{
var
data
,
id
,
cleanData
:
function
(
elems
,
/* internal */
acceptData
)
{
var
data
,
id
,
elem
,
type
,
i
=
0
,
internalKey
=
jQuery
.
expando
,
cache
=
jQuery
.
cache
,
special
=
jQuery
.
event
.
special
,
deleteExpando
=
jQuery
.
support
.
deleteExpando
;
deleteExpando
=
jQuery
.
support
.
deleteExpando
,
special
=
jQuery
.
event
.
special
;
for
(
var
i
=
0
,
elem
;
(
elem
=
elems
[
i
])
!=
null
;
i
++
)
{
if
(
elem
.
nodeName
&&
jQuery
.
noData
[
elem
.
nodeName
.
toLowerCase
()]
)
{
continue
;
}
for
(
;
(
elem
=
elems
[
i
])
!=
null
;
i
++
)
{
i
d
=
elem
[
jQuery
.
expando
];
i
f
(
acceptData
||
jQuery
.
acceptData
(
elem
)
)
{
if
(
id
)
{
data
=
cache
[
id
];
id
=
elem
[
internalKey
];
data
=
id
&&
cache
[
id
];
if
(
data
&&
data
.
events
)
{
for
(
var
type
in
data
.
events
)
{
if
(
special
[
type
]
)
{
jQuery
.
event
.
remove
(
elem
,
type
);
if
(
data
)
{
if
(
data
.
events
)
{
for
(
type
in
data
.
events
)
{
if
(
special
[
type
]
)
{
jQuery
.
event
.
remove
(
elem
,
type
);
// This is a shortcut to avoid jQuery.event.remove's overhead
}
else
{
jQuery
.
removeEvent
(
elem
,
type
,
data
.
handle
);
// This is a shortcut to avoid jQuery.event.remove's overhead
}
else
{
jQuery
.
removeEvent
(
elem
,
type
,
data
.
handle
);
}
}
}
}
// Remove cache only if jQuery.event.remove was not removed it before
if
(
cache
[
id
]
)
{
if
(
deleteExpando
)
{
delete
elem
[
jQuery
.
expando
];
// Remove cache only if it was not already removed by jQuery.event.remove
if
(
cache
[
id
]
)
{
}
else
if
(
elem
.
removeAttribute
)
{
elem
.
removeAttribute
(
jQuery
.
expando
);
}
delete
cache
[
id
];
// IE does not allow us to delete expando properties from nodes,
// nor does it have a removeAttribute function on Document nodes;
// we must handle all of these cases
if
(
deleteExpando
)
{
delete
elem
[
internalKey
];
jQuery
.
deletedIds
.
push
(
id
);
delete
cache
[
id
];
}
else
if
(
elem
.
removeAttribute
)
{
elem
.
removeAttribute
(
internalKey
);
}
else
{
elem
[
internalKey
]
=
null
;
}
jQuery
.
deletedIds
.
push
(
id
);
}
}
}
}
...
...
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