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
47c605f6
Commit
47c605f6
authored
Nov 06, 2011
by
Toby Brain
Committed by
Dave Methvin
Nov 06, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #10177. Pass correct index to function-parameter of `.wrap`
parent
90c019de
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
manipulation.js
src/manipulation.js
+4
-2
manipulation.js
test/unit/manipulation.js
+28
-1
No files found.
src/manipulation.js
View file @
47c605f6
...
@@ -117,8 +117,10 @@ jQuery.fn.extend({
...
@@ -117,8 +117,10 @@ jQuery.fn.extend({
},
},
wrap
:
function
(
html
)
{
wrap
:
function
(
html
)
{
return
this
.
each
(
function
()
{
var
isFunction
=
jQuery
.
isFunction
(
html
);
jQuery
(
this
).
wrapAll
(
html
);
return
this
.
each
(
function
(
i
)
{
jQuery
(
this
).
wrapAll
(
isFunction
?
html
.
call
(
this
,
i
)
:
html
);
});
});
},
},
...
...
test/unit/manipulation.js
View file @
47c605f6
...
@@ -135,7 +135,34 @@ test("wrap(String|Element)", function() {
...
@@ -135,7 +135,34 @@ test("wrap(String|Element)", function() {
test
(
"wrap(Function)"
,
function
()
{
test
(
"wrap(Function)"
,
function
()
{
testWrap
(
functionReturningObj
);
testWrap
(
functionReturningObj
);
})
});
test
(
"wrap(Function) with index (#10177)"
,
function
()
{
var
expectedIndex
=
0
,
targets
=
jQuery
(
"#qunit-fixture p"
);
expect
(
targets
.
length
);
targets
.
wrap
(
function
(
i
)
{
equal
(
i
,
expectedIndex
,
"Check if the provided index ("
+
i
+
") is as expected ("
+
expectedIndex
+
")"
);
expectedIndex
++
;
return
"<div id='wrap_index_'"
+
i
+
"'></div>"
;
});
});
test
(
"wrap(String) consecutive elements (#10177)"
,
function
()
{
var
targets
=
jQuery
(
"#qunit-fixture p"
);
expect
(
targets
.
length
*
2
);
targets
.
wrap
(
"<div class='wrapper'></div>"
);
targets
.
each
(
function
()
{
var
$this
=
jQuery
(
this
);
ok
(
$this
.
parent
().
is
(
'.wrapper'
),
"Check each elements parent is correct (.wrapper)"
);
equal
(
$this
.
siblings
().
length
,
0
,
"Each element should be wrapped individually"
);
});
});
var
testWrapAll
=
function
(
val
)
{
var
testWrapAll
=
function
(
val
)
{
expect
(
8
);
expect
(
8
);
...
...
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