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
132b8de6
Commit
132b8de6
authored
Dec 19, 2008
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switched to using DOM Fragments in domManip.
parent
2875460f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
50 deletions
+53
-50
core.js
src/core.js
+51
-48
core.js
test/unit/core.js
+2
-2
No files found.
src/core.js
View file @
132b8de6
...
@@ -243,27 +243,27 @@ jQuery.fn = jQuery.prototype = {
...
@@ -243,27 +243,27 @@ jQuery.fn = jQuery.prototype = {
},
},
append
:
function
()
{
append
:
function
()
{
return
this
.
domManip
(
arguments
,
true
,
f
alse
,
f
unction
(
elem
){
return
this
.
domManip
(
arguments
,
true
,
function
(
elem
){
if
(
this
.
nodeType
==
1
)
if
(
this
.
nodeType
==
1
)
this
.
appendChild
(
elem
);
this
.
appendChild
(
elem
);
});
});
},
},
prepend
:
function
()
{
prepend
:
function
()
{
return
this
.
domManip
(
arguments
,
true
,
true
,
function
(
elem
){
return
this
.
domManip
(
arguments
,
true
,
function
(
elem
){
if
(
this
.
nodeType
==
1
)
if
(
this
.
nodeType
==
1
)
this
.
insertBefore
(
elem
,
this
.
firstChild
);
this
.
insertBefore
(
elem
,
this
.
firstChild
);
});
});
},
},
before
:
function
()
{
before
:
function
()
{
return
this
.
domManip
(
arguments
,
false
,
f
alse
,
f
unction
(
elem
){
return
this
.
domManip
(
arguments
,
false
,
function
(
elem
){
this
.
parentNode
.
insertBefore
(
elem
,
this
);
this
.
parentNode
.
insertBefore
(
elem
,
this
);
});
});
},
},
after
:
function
()
{
after
:
function
()
{
return
this
.
domManip
(
arguments
,
false
,
true
,
function
(
elem
){
return
this
.
domManip
(
arguments
,
false
,
function
(
elem
){
this
.
parentNode
.
insertBefore
(
elem
,
this
.
nextSibling
);
this
.
parentNode
.
insertBefore
(
elem
,
this
.
nextSibling
);
});
});
},
},
...
@@ -497,44 +497,28 @@ jQuery.fn = jQuery.prototype = {
...
@@ -497,44 +497,28 @@ jQuery.fn = jQuery.prototype = {
});
});
},
},
domManip
:
function
(
args
,
table
,
reverse
,
callback
)
{
domManip
:
function
(
args
,
table
,
callback
)
{
var
clone
=
this
.
length
>
1
,
elems
;
if
(
this
[
0
]
)
{
var
fragment
=
document
.
createDocumentFragment
(),
return
this
.
each
(
function
(){
scripts
=
jQuery
.
clean
(
args
,
this
[
0
].
ownerDocument
,
fragment
),
if
(
!
elems
)
{
first
=
fragment
.
firstChild
;
elems
=
jQuery
.
clean
(
args
,
this
.
ownerDocument
);
if
(
first
)
if
(
reverse
)
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
elems
.
reverse
();
callback
.
call
(
root
(
this
[
i
],
first
),
this
.
length
>
1
?
fragment
.
cloneNode
(
true
)
:
fragment
);
}
if
(
scripts
)
var
obj
=
this
;
jQuery
.
each
(
scripts
,
evalScript
);
}
if
(
table
&&
jQuery
.
nodeName
(
this
,
"table"
)
&&
jQuery
.
nodeName
(
elems
[
0
],
"tr"
)
)
obj
=
this
.
getElementsByTagName
(
"tbody"
)[
0
]
||
this
.
appendChild
(
this
.
ownerDocument
.
createElement
(
"tbody"
)
);
var
scripts
=
jQuery
(
[]
);
jQuery
.
each
(
elems
,
function
(){
var
elem
=
clone
?
jQuery
(
this
).
clone
(
true
)[
0
]
:
this
;
// execute all scripts after the elements have been injected
if
(
jQuery
.
nodeName
(
elem
,
"script"
)
)
scripts
=
scripts
.
add
(
elem
);
else
{
// Remove any inner scripts for later evaluation
if
(
elem
.
nodeType
==
1
)
scripts
=
scripts
.
add
(
jQuery
(
"script"
,
elem
).
remove
()
);
// Inject the elements into the document
callback
.
call
(
obj
,
elem
);
}
});
scripts
.
each
(
evalScript
);
return
this
;
});
function
root
(
elem
,
cur
)
{
return
table
&&
jQuery
.
nodeName
(
elem
,
"table"
)
&&
jQuery
.
nodeName
(
cur
,
"tr"
)
?
(
elem
.
getElementsByTagName
(
"tbody"
)[
0
]
||
elem
.
appendChild
(
elem
.
ownerDocument
.
createElement
(
"tbody"
)))
:
elem
;
}
}
}
};
};
...
@@ -955,8 +939,8 @@ jQuery.extend({
...
@@ -955,8 +939,8 @@ jQuery.extend({
return
ret
;
return
ret
;
},
},
clean
:
function
(
elems
,
context
)
{
clean
:
function
(
elems
,
context
,
fragment
)
{
var
ret
=
[];
var
ret
=
[]
,
scripts
=
[]
;
context
=
context
||
document
;
context
=
context
||
document
;
// !context.createElement fails in IE with an error but returns typeof 'object'
// !context.createElement fails in IE with an error but returns typeof 'object'
...
@@ -1037,20 +1021,39 @@ jQuery.extend({
...
@@ -1037,20 +1021,39 @@ jQuery.extend({
div
.
insertBefore
(
context
.
createTextNode
(
elem
.
match
(
/^
\s
*/
)[
0
]
),
div
.
firstChild
);
div
.
insertBefore
(
context
.
createTextNode
(
elem
.
match
(
/^
\s
*/
)[
0
]
),
div
.
firstChild
);
}
}
if
(
fragment
)
{
var
found
=
div
.
getElementsByTagName
(
"script"
);
while
(
found
.
length
)
{
scripts
.
push
(
found
[
0
]
);
found
[
0
].
parentNode
.
removeChild
(
found
[
0
]
);
}
}
elem
=
jQuery
.
makeArray
(
div
.
childNodes
);
elem
=
jQuery
.
makeArray
(
div
.
childNodes
);
}
}
if
(
elem
.
length
===
0
&&
(
!
jQuery
.
nodeName
(
elem
,
"form"
)
&&
!
jQuery
.
nodeName
(
elem
,
"select"
))
)
if
(
elem
.
nodeType
)
return
;
if
(
elem
[
0
]
===
undefined
||
jQuery
.
nodeName
(
elem
,
"form"
)
||
elem
.
options
)
ret
.
push
(
elem
);
ret
.
push
(
elem
);
else
else
ret
=
jQuery
.
merge
(
ret
,
elem
);
ret
=
jQuery
.
merge
(
ret
,
elem
);
});
});
if
(
fragment
)
{
for
(
var
i
=
0
;
ret
[
i
];
i
++
)
{
if
(
jQuery
.
nodeName
(
ret
[
i
],
"script"
)
)
{
ret
[
i
].
parentNode
.
removeChild
(
ret
[
i
]
);
}
else
{
if
(
ret
[
i
].
nodeType
===
1
)
ret
=
jQuery
.
merge
(
ret
,
ret
[
i
].
getElementsByTagName
(
"script"
));
fragment
.
appendChild
(
ret
[
i
]
);
}
}
return
scripts
;
}
return
ret
;
return
ret
;
},
},
...
...
test/unit/core.js
View file @
132b8de6
...
@@ -258,10 +258,10 @@ test("jQuery('html')", function() {
...
@@ -258,10 +258,10 @@ test("jQuery('html')", function() {
reset
();
reset
();
foo
=
false
;
foo
=
false
;
var
s
=
jQuery
(
"<script>
var
foo='test';</script>"
)[
0
];
var
s
=
jQuery
(
"<script>foo='test';</script>"
)[
0
];
ok
(
s
,
"Creating a script"
);
ok
(
s
,
"Creating a script"
);
ok
(
!
foo
,
"Make sure the script wasn't executed prematurely"
);
ok
(
!
foo
,
"Make sure the script wasn't executed prematurely"
);
jQuery
(
"body"
).
append
(
s
);
jQuery
(
"body"
).
append
(
"<script>foo='test';</script>"
);
ok
(
foo
,
"Executing a scripts contents in the right context"
);
ok
(
foo
,
"Executing a scripts contents in the right context"
);
reset
();
reset
();
...
...
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