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
ef1ee513
Commit
ef1ee513
authored
Nov 30, 2006
by
Jörn Zaefferer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug #344 (tests, implementation, docs)
parent
68313e77
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3669 additions
and
3636 deletions
+3669
-3636
coreTest.js
src/jquery/coreTest.js
+566
-550
jquery.js
src/jquery/jquery.js
+3103
-3086
No files found.
src/jquery/coreTest.js
View file @
ef1ee513
...
@@ -319,6 +319,22 @@ test("$.extend(Object, Object)", function() {
...
@@ -319,6 +319,22 @@ test("$.extend(Object, Object)", function() {
isSet
(
options
,
optionsCopy
,
"Check if not modified: options must not be modified"
);
isSet
(
options
,
optionsCopy
,
"Check if not modified: options must not be modified"
);
});
});
test
(
"$.extend(Object, Object, Object, Object)"
,
function
()
{
expect
(
4
);
var
defaults
=
{
xnumber1
:
5
,
xnumber2
:
7
,
xstring1
:
"peter"
,
xstring2
:
"pan"
},
defaultsCopy
=
{
xnumber1
:
5
,
xnumber2
:
7
,
xstring1
:
"peter"
,
xstring2
:
"pan"
},
options1
=
{
xnumber2
:
1
,
xstring2
:
"x"
},
options1Copy
=
{
xnumber2
:
1
,
xstring2
:
"x"
},
options2
=
{
xstring2
:
"xx"
,
xxx
:
"newstringx"
},
options2Copy
=
{
xstring2
:
"xx"
,
xxx
:
"newstringx"
},
merged
=
{
xnumber1
:
5
,
xnumber2
:
1
,
xstring1
:
"peter"
,
xstring2
:
"xx"
,
xxx
:
"newstringx"
};
var
settings
=
jQuery
.
extend
({},
defaults
,
options1
,
options2
);
isSet
(
settings
,
merged
,
"Check if extended: settings must be extended"
);
isSet
(
defaults
,
defaultsCopy
,
"Check if not modified: options1 must not be modified"
);
isSet
(
options1
,
options1Copy
,
"Check if not modified: options1 must not be modified"
);
isSet
(
options2
,
options2Copy
,
"Check if not modified: options2 must not be modified"
);
});
test
(
"expressions - element"
,
function
()
{
test
(
"expressions - element"
,
function
()
{
expect
(
5
);
expect
(
5
);
ok
(
$
(
"*"
).
size
()
>=
30
,
"Select all"
);
ok
(
$
(
"*"
).
size
()
>=
30
,
"Select all"
);
...
...
src/jquery/jquery.js
View file @
ef1ee513
...
@@ -1056,56 +1056,73 @@ jQuery.fn = jQuery.prototype = {
...
@@ -1056,56 +1056,73 @@ jQuery.fn = jQuery.prototype = {
};
};
/**
/**
* Extends the jQuery object itself. Can be used to add
both static
* Extends the jQuery object itself. Can be used to add
functions into
*
functions and plugin methods.
*
the jQuery namespace and to add plugin methods (plugins).
*
*
* @example
$.fn.extend({
* @example
jQuery.fn.extend({
* check: function() {
* check: function() {
*
this.each(function() { this.checked = true; });
*
return this.each(function() { this.checked = true; });
* ),
* ),
* uncheck: function() {
* uncheck: function() {
*
this.each(function() { this.checked = false; });
*
return this.each(function() { this.checked = false; });
* }
* }
* });
* });
* $("input[@type=checkbox]").check();
* $("input[@type=checkbox]").check();
* $("input[@type=radio]").uncheck();
* $("input[@type=radio]").uncheck();
* @desc Adds two plugin methods.
* @desc Adds two plugin methods.
*
*
* @private
* @example jQuery.extend({
* @name extend
* min: function(a, b) { return a < b ? a : b; },
* @param Object obj
* max: function(a, b) { return a > b ? a : b; }
* });
* @desc Adds two functions into the jQuery namespace
*
* @name $.extend
* @param Object prop The object that will be merged into the jQuery object
* @type Object
* @type Object
* @cat Core
* @cat Core
*/
*/
/**
/**
* Extend one object with
another, returning the original,
* Extend one object with
one or more others, returning the original,
* modified, object. This is a great utility for simple inheritance.
* modified, object. This is a great utility for simple inheritance.
*
*
* @example var settings = { validate: false, limit: 5, name: "foo" };
* @example var settings = { validate: false, limit: 5, name: "foo" };
* var options = { validate: true, name: "bar" };
* var options = { validate: true, name: "bar" };
* jQuery.extend(settings, options);
* jQuery.extend(settings, options);
* @result settings == { validate: true, limit: 5, name: "bar" }
* @result settings == { validate: true, limit: 5, name: "bar" }
* @desc Merge settings and options, modifying settings
*
* @example var defaults = { validate: false, limit: 5, name: "foo" };
* var options = { validate: true, name: "bar" };
* var settings = jQuery.extend({}, defaults, options);
* @result settings == { validate: true, limit: 5, name: "bar" }
* @desc Merge defaults and options, without modifying the defaults
*
*
* @name $.extend
* @name $.extend
* @param Object obj The object to extend
* @param Object target The object to extend
* @param Object prop The object that will be merged into the first.
* @param Object prop1 The object that will be merged into the first.
* @param Object propN (optional) More objects to merge into the first
* @type Object
* @type Object
* @cat Javascript
* @cat Javascript
*/
*/
jQuery
.
extend
=
jQuery
.
fn
.
extend
=
function
(
obj
,
prop
)
{
jQuery
.
extend
=
jQuery
.
fn
.
extend
=
function
()
{
// Watch for the case where null or undefined gets passed in by accident
// copy reference to target object
if
(
arguments
.
length
>
1
&&
(
prop
===
null
||
prop
==
undefined
)
)
var
target
=
arguments
[
0
],
return
obj
;
a
=
1
;
// If no property object was provided, then we're extending jQuery
if
(
!
prop
)
{
prop
=
obj
;
obj
=
this
;
}
// extend jQuery itself if only one argument is passed
if
(
arguments
.
length
==
1
)
{
target
=
this
;
a
=
0
;
}
var
prop
;
while
(
prop
=
arguments
[
a
++
])
// Extend the base object
// Extend the base object
for
(
var
i
in
prop
)
obj
[
i
]
=
prop
[
i
];
for
(
var
i
in
prop
)
target
[
i
]
=
prop
[
i
];
// Return the modified object
// Return the modified object
return
obj
;
return
target
;
};
};
jQuery
.
extend
({
jQuery
.
extend
({
...
...
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