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
590eff63
Commit
590eff63
authored
May 05, 2015
by
Timmy Willison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Manipulation: privatize internal domManip() function
Fixes gh-2225
parent
63c1414a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
101 deletions
+100
-101
manipulation.js
src/manipulation.js
+100
-101
No files found.
src/manipulation.js
View file @
590eff63
...
@@ -138,6 +138,101 @@ function fixCloneNodeIssues( src, dest ) {
...
@@ -138,6 +138,101 @@ function fixCloneNodeIssues( src, dest ) {
}
}
}
}
function
domManip
(
collection
,
args
,
callback
,
ignored
)
{
// Flatten any nested arrays
args
=
concat
.
apply
(
[],
args
);
var
first
,
node
,
hasScripts
,
scripts
,
doc
,
fragment
,
i
=
0
,
l
=
collection
.
length
,
iNoClone
=
l
-
1
,
value
=
args
[
0
],
isFunction
=
jQuery
.
isFunction
(
value
);
// We can't cloneNode fragments that contain checked, in WebKit
if
(
isFunction
||
(
l
>
1
&&
typeof
value
===
"string"
&&
!
support
.
checkClone
&&
rchecked
.
test
(
value
)
)
)
{
return
collection
.
each
(
function
(
index
)
{
var
self
=
collection
.
eq
(
index
);
if
(
isFunction
)
{
args
[
0
]
=
value
.
call
(
this
,
index
,
self
.
html
()
);
}
domManip
(
self
,
args
,
callback
,
ignored
);
});
}
if
(
l
)
{
fragment
=
buildFragment
(
args
,
collection
[
0
].
ownerDocument
,
false
,
collection
,
ignored
);
first
=
fragment
.
firstChild
;
if
(
fragment
.
childNodes
.
length
===
1
)
{
fragment
=
first
;
}
// Require either new content or an interest in ignored elements to invoke the callback
if
(
first
||
ignored
)
{
scripts
=
jQuery
.
map
(
getAll
(
fragment
,
"script"
),
disableScript
);
hasScripts
=
scripts
.
length
;
// Use the original fragment for the last item
// instead of the first because it can end up
// being emptied incorrectly in certain situations (#8070).
for
(
;
i
<
l
;
i
++
)
{
node
=
fragment
;
if
(
i
!==
iNoClone
)
{
node
=
jQuery
.
clone
(
node
,
true
,
true
);
// Keep references to cloned scripts for later restoration
if
(
hasScripts
)
{
// Support: Android<4.1, PhantomJS<2
// push.apply(_, arraylike) throws on ancient WebKit
jQuery
.
merge
(
scripts
,
getAll
(
node
,
"script"
)
);
}
}
callback
.
call
(
collection
[
i
],
node
,
i
);
}
if
(
hasScripts
)
{
doc
=
scripts
[
scripts
.
length
-
1
].
ownerDocument
;
// Reenable scripts
jQuery
.
map
(
scripts
,
restoreScript
);
// Evaluate executable scripts on first document insertion
for
(
i
=
0
;
i
<
hasScripts
;
i
++
)
{
node
=
scripts
[
i
];
if
(
rscriptType
.
test
(
node
.
type
||
""
)
&&
!
jQuery
.
_data
(
node
,
"globalEval"
)
&&
jQuery
.
contains
(
doc
,
node
)
)
{
if
(
node
.
src
)
{
// Optional AJAX dependency, but won't run scripts if not present
if
(
jQuery
.
_evalUrl
)
{
jQuery
.
_evalUrl
(
node
.
src
);
}
}
else
{
jQuery
.
globalEval
(
(
node
.
text
||
node
.
textContent
||
node
.
innerHTML
||
""
)
.
replace
(
rcleanScript
,
""
)
);
}
}
}
}
// Fix #11809: Avoid leaking memory
fragment
=
first
=
null
;
}
}
return
collection
;
}
jQuery
.
extend
({
jQuery
.
extend
({
htmlPrefilter
:
function
(
html
)
{
htmlPrefilter
:
function
(
html
)
{
return
html
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
return
html
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
...
@@ -266,7 +361,7 @@ jQuery.fn.extend({
...
@@ -266,7 +361,7 @@ jQuery.fn.extend({
},
},
append
:
function
()
{
append
:
function
()
{
return
this
.
domManip
(
arguments
,
function
(
elem
)
{
return
domManip
(
this
,
arguments
,
function
(
elem
)
{
if
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
||
this
.
nodeType
===
9
)
{
if
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
||
this
.
nodeType
===
9
)
{
var
target
=
manipulationTarget
(
this
,
elem
);
var
target
=
manipulationTarget
(
this
,
elem
);
target
.
appendChild
(
elem
);
target
.
appendChild
(
elem
);
...
@@ -275,7 +370,7 @@ jQuery.fn.extend({
...
@@ -275,7 +370,7 @@ jQuery.fn.extend({
},
},
prepend
:
function
()
{
prepend
:
function
()
{
return
this
.
domManip
(
arguments
,
function
(
elem
)
{
return
domManip
(
this
,
arguments
,
function
(
elem
)
{
if
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
||
this
.
nodeType
===
9
)
{
if
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
||
this
.
nodeType
===
9
)
{
var
target
=
manipulationTarget
(
this
,
elem
);
var
target
=
manipulationTarget
(
this
,
elem
);
target
.
insertBefore
(
elem
,
target
.
firstChild
);
target
.
insertBefore
(
elem
,
target
.
firstChild
);
...
@@ -284,7 +379,7 @@ jQuery.fn.extend({
...
@@ -284,7 +379,7 @@ jQuery.fn.extend({
},
},
before
:
function
()
{
before
:
function
()
{
return
this
.
domManip
(
arguments
,
function
(
elem
)
{
return
domManip
(
this
,
arguments
,
function
(
elem
)
{
if
(
this
.
parentNode
)
{
if
(
this
.
parentNode
)
{
this
.
parentNode
.
insertBefore
(
elem
,
this
);
this
.
parentNode
.
insertBefore
(
elem
,
this
);
}
}
...
@@ -292,7 +387,7 @@ jQuery.fn.extend({
...
@@ -292,7 +387,7 @@ jQuery.fn.extend({
},
},
after
:
function
()
{
after
:
function
()
{
return
this
.
domManip
(
arguments
,
function
(
elem
)
{
return
domManip
(
this
,
arguments
,
function
(
elem
)
{
if
(
this
.
parentNode
)
{
if
(
this
.
parentNode
)
{
this
.
parentNode
.
insertBefore
(
elem
,
this
.
nextSibling
);
this
.
parentNode
.
insertBefore
(
elem
,
this
.
nextSibling
);
}
}
...
@@ -401,7 +496,7 @@ jQuery.fn.extend({
...
@@ -401,7 +496,7 @@ jQuery.fn.extend({
var
ignored
=
[];
var
ignored
=
[];
// Make the changes, replacing each non-ignored context element with the new content
// Make the changes, replacing each non-ignored context element with the new content
return
this
.
domManip
(
arguments
,
function
(
elem
)
{
return
domManip
(
this
,
arguments
,
function
(
elem
)
{
var
parent
=
this
.
parentNode
;
var
parent
=
this
.
parentNode
;
if
(
jQuery
.
inArray
(
this
,
ignored
)
<
0
)
{
if
(
jQuery
.
inArray
(
this
,
ignored
)
<
0
)
{
...
@@ -417,102 +512,6 @@ jQuery.fn.extend({
...
@@ -417,102 +512,6 @@ jQuery.fn.extend({
detach
:
function
(
selector
)
{
detach
:
function
(
selector
)
{
return
this
.
remove
(
selector
,
true
);
return
this
.
remove
(
selector
,
true
);
},
domManip
:
function
(
args
,
callback
,
ignored
)
{
// Flatten any nested arrays
args
=
concat
.
apply
(
[],
args
);
var
first
,
node
,
hasScripts
,
scripts
,
doc
,
fragment
,
i
=
0
,
l
=
this
.
length
,
set
=
this
,
iNoClone
=
l
-
1
,
value
=
args
[
0
],
isFunction
=
jQuery
.
isFunction
(
value
);
// We can't cloneNode fragments that contain checked, in WebKit
if
(
isFunction
||
(
l
>
1
&&
typeof
value
===
"string"
&&
!
support
.
checkClone
&&
rchecked
.
test
(
value
)
)
)
{
return
this
.
each
(
function
(
index
)
{
var
self
=
set
.
eq
(
index
);
if
(
isFunction
)
{
args
[
0
]
=
value
.
call
(
this
,
index
,
self
.
html
()
);
}
self
.
domManip
(
args
,
callback
,
ignored
);
});
}
if
(
l
)
{
fragment
=
buildFragment
(
args
,
this
[
0
].
ownerDocument
,
false
,
this
,
ignored
);
first
=
fragment
.
firstChild
;
if
(
fragment
.
childNodes
.
length
===
1
)
{
fragment
=
first
;
}
// Require either new content or an interest in ignored elements to invoke the callback
if
(
first
||
ignored
)
{
scripts
=
jQuery
.
map
(
getAll
(
fragment
,
"script"
),
disableScript
);
hasScripts
=
scripts
.
length
;
// Use the original fragment for the last item
// instead of the first because it can end up
// being emptied incorrectly in certain situations (#8070).
for
(
;
i
<
l
;
i
++
)
{
node
=
fragment
;
if
(
i
!==
iNoClone
)
{
node
=
jQuery
.
clone
(
node
,
true
,
true
);
// Keep references to cloned scripts for later restoration
if
(
hasScripts
)
{
// Support: Android<4.1, PhantomJS<2
// push.apply(_, arraylike) throws on ancient WebKit
jQuery
.
merge
(
scripts
,
getAll
(
node
,
"script"
)
);
}
}
callback
.
call
(
this
[
i
],
node
,
i
);
}
if
(
hasScripts
)
{
doc
=
scripts
[
scripts
.
length
-
1
].
ownerDocument
;
// Reenable scripts
jQuery
.
map
(
scripts
,
restoreScript
);
// Evaluate executable scripts on first document insertion
for
(
i
=
0
;
i
<
hasScripts
;
i
++
)
{
node
=
scripts
[
i
];
if
(
rscriptType
.
test
(
node
.
type
||
""
)
&&
!
jQuery
.
_data
(
node
,
"globalEval"
)
&&
jQuery
.
contains
(
doc
,
node
)
)
{
if
(
node
.
src
)
{
// Optional AJAX dependency, but won't run scripts if not present
if
(
jQuery
.
_evalUrl
)
{
jQuery
.
_evalUrl
(
node
.
src
);
}
}
else
{
jQuery
.
globalEval
(
(
node
.
text
||
node
.
textContent
||
node
.
innerHTML
||
""
)
.
replace
(
rcleanScript
,
""
)
);
}
}
}
}
// Fix #11809: Avoid leaking memory
fragment
=
first
=
null
;
}
}
return
this
;
}
}
});
});
...
...
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