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
fb2e0a0c
Commit
fb2e0a0c
authored
Oct 30, 2013
by
Chris Antaki
Committed by
Richard Gibson
Nov 05, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #11809: Update text without creating DOM nodes. Close gh-1412.
parent
19c1b610
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
manipulation.js
src/manipulation.js
+5
-1
manipulation.js
test/unit/manipulation.js
+20
-2
No files found.
src/manipulation.js
View file @
fb2e0a0c
...
@@ -314,7 +314,11 @@ jQuery.fn.extend({
...
@@ -314,7 +314,11 @@ jQuery.fn.extend({
return
access
(
this
,
function
(
value
)
{
return
access
(
this
,
function
(
value
)
{
return
value
===
undefined
?
return
value
===
undefined
?
jQuery
.
text
(
this
)
:
jQuery
.
text
(
this
)
:
this
.
empty
().
append
(
(
this
[
0
]
&&
this
[
0
].
ownerDocument
||
document
).
createTextNode
(
value
)
);
this
.
empty
().
each
(
function
()
{
if
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
||
this
.
nodeType
===
9
)
{
this
.
textContent
=
value
;
}
});
},
null
,
value
,
arguments
.
length
);
},
null
,
value
,
arguments
.
length
);
},
},
...
...
test/unit/manipulation.js
View file @
fb2e0a0c
...
@@ -64,9 +64,9 @@ test( "text(undefined)", function() {
...
@@ -64,9 +64,9 @@ test( "text(undefined)", function() {
function
testText
(
valueObj
)
{
function
testText
(
valueObj
)
{
expect
(
4
);
expect
(
7
);
var
val
,
j
;
var
val
,
j
,
expected
,
$multipleElements
,
$parentDiv
,
$childDiv
;
val
=
valueObj
(
"<div><b>Hello</b> cruel world!</div>"
);
val
=
valueObj
(
"<div><b>Hello</b> cruel world!</div>"
);
equal
(
jQuery
(
"#foo"
).
text
(
val
)[
0
].
innerHTML
.
replace
(
/>/g
,
">"
),
"<div><b>Hello</b> cruel world!</div>"
,
"Check escaped text"
);
equal
(
jQuery
(
"#foo"
).
text
(
val
)[
0
].
innerHTML
.
replace
(
/>/g
,
">"
),
"<div><b>Hello</b> cruel world!</div>"
,
"Check escaped text"
);
...
@@ -79,6 +79,24 @@ function testText( valueObj ) {
...
@@ -79,6 +79,24 @@ function testText( valueObj ) {
// Blackberry 4.6 doesn't maintain comments in the DOM
// Blackberry 4.6 doesn't maintain comments in the DOM
equal
(
jQuery
(
"#nonnodes"
)[
0
].
childNodes
.
length
<
3
?
8
:
j
[
2
].
nodeType
,
8
,
"Check node,textnode,comment with text()"
);
equal
(
jQuery
(
"#nonnodes"
)[
0
].
childNodes
.
length
<
3
?
8
:
j
[
2
].
nodeType
,
8
,
"Check node,textnode,comment with text()"
);
// Update multiple elements #11809
expected
=
"New"
;
$multipleElements
=
jQuery
(
"<div>Hello</div>"
).
add
(
"<div>World</div>"
);
$multipleElements
.
text
(
expected
);
equal
(
$multipleElements
.
eq
(
0
).
text
(),
expected
,
"text() updates multiple elements (#11809)"
);
equal
(
$multipleElements
.
eq
(
1
).
text
(),
expected
,
"text() updates multiple elements (#11809)"
);
// Prevent memory leaks #11809
$childDiv
=
jQuery
(
"<div/>"
);
$childDiv
.
data
(
"leak"
,
true
);
$parentDiv
=
jQuery
(
"<div/>"
);
$parentDiv
.
append
(
$childDiv
);
$parentDiv
.
text
(
"Dry off"
);
equal
(
$childDiv
.
data
(
"leak"
),
undefined
,
"Check for leaks (#11809)"
);
}
}
test
(
"text(String)"
,
function
()
{
test
(
"text(String)"
,
function
()
{
...
...
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