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
6c2a501d
Commit
6c2a501d
authored
Dec 06, 2011
by
Richard Gibson
Committed by
Dave Methvin
Dec 06, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #5571. Setters should treat `undefined` as a no-op and be chainable.
parent
d511613d
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
248 additions
and
229 deletions
+248
-229
attributes.js
src/attributes.js
+2
-2
core.js
src/core.js
+40
-16
css.js
src/css.js
+2
-7
data.js
src/data.js
+35
-28
dimensions.js
src/dimensions.js
+32
-41
manipulation.js
src/manipulation.js
+39
-47
offset.js
src/offset.js
+42
-67
queue.js
src/queue.js
+13
-7
attributes.js
test/unit/attributes.js
+7
-1
data.js
test/unit/data.js
+1
-2
dimensions.js
test/unit/dimensions.js
+14
-4
manipulation.js
test/unit/manipulation.js
+10
-0
offset.js
test/unit/offset.js
+7
-5
queue.js
test/unit/queue.js
+4
-2
No files found.
src/attributes.js
View file @
6c2a501d
...
@@ -12,7 +12,7 @@ var rclass = /[\n\t\r]/g,
...
@@ -12,7 +12,7 @@ var rclass = /[\n\t\r]/g,
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
attr
:
function
(
name
,
value
)
{
attr
:
function
(
name
,
value
)
{
return
jQuery
.
access
(
this
,
name
,
value
,
true
,
jQuery
.
attr
);
return
jQuery
.
access
(
this
,
jQuery
.
attr
,
name
,
value
,
arguments
.
length
>
1
);
},
},
removeAttr
:
function
(
name
)
{
removeAttr
:
function
(
name
)
{
...
@@ -22,7 +22,7 @@ jQuery.fn.extend({
...
@@ -22,7 +22,7 @@ jQuery.fn.extend({
},
},
prop
:
function
(
name
,
value
)
{
prop
:
function
(
name
,
value
)
{
return
jQuery
.
access
(
this
,
name
,
value
,
true
,
jQuery
.
prop
);
return
jQuery
.
access
(
this
,
jQuery
.
prop
,
name
,
value
,
arguments
.
length
>
1
);
},
},
removeProp
:
function
(
name
)
{
removeProp
:
function
(
name
)
{
...
...
src/core.js
View file @
6c2a501d
...
@@ -801,31 +801,55 @@ jQuery.extend({
...
@@ -801,31 +801,55 @@ jQuery.extend({
// Mutifunctional method to get and set values to a collection
// Mutifunctional method to get and set values to a collection
// The value/s can optionally be executed if it's a function
// The value/s can optionally be executed if it's a function
access
:
function
(
elems
,
key
,
value
,
exec
,
fn
,
pass
)
{
access
:
function
(
elems
,
fn
,
key
,
value
,
chainable
,
emptyGet
,
pass
)
{
var
length
=
elems
.
length
;
var
exec
,
bulk
=
key
==
null
,
i
=
0
,
length
=
elems
.
length
;
// Set
ting many attribut
es
// Set
s many valu
es
if
(
typeof
key
===
"object"
)
{
if
(
key
&&
typeof
key
===
"object"
)
{
for
(
var
k
in
key
)
{
for
(
i
in
key
)
{
jQuery
.
access
(
elems
,
k
,
key
[
k
],
exec
,
fn
,
value
);
jQuery
.
access
(
elems
,
fn
,
i
,
key
[
i
],
1
,
emptyGet
,
value
);
}
}
return
elems
;
chainable
=
1
;
}
// Set
ting one attribut
e
// Set
s one valu
e
if
(
value
!==
undefined
)
{
}
else
if
(
value
!==
undefined
)
{
// Optionally, function values get executed if exec is true
// Optionally, function values get executed if exec is true
exec
=
!
pass
&&
exec
&&
jQuery
.
isFunction
(
value
);
exec
=
pass
===
undefined
&&
jQuery
.
isFunction
(
value
);
if
(
bulk
)
{
// Bulk operations only iterate when executing function values
if
(
exec
)
{
exec
=
fn
;
fn
=
function
(
elem
,
key
,
value
)
{
return
exec
.
call
(
jQuery
(
elem
),
value
);
};
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
// Otherwise they run against the entire set
fn
(
elems
[
i
],
key
,
exec
?
value
.
call
(
elems
[
i
],
i
,
fn
(
elems
[
i
],
key
)
)
:
value
,
pass
);
}
else
{
fn
.
call
(
elems
,
value
);
fn
=
null
;
}
}
}
return
elems
;
if
(
fn
)
{
for
(;
i
<
length
;
i
++
)
{
fn
(
elems
[
i
],
key
,
exec
?
value
.
call
(
elems
[
i
],
i
,
fn
(
elems
[
i
],
key
)
)
:
value
,
pass
);
}
}
chainable
=
1
;
}
}
// Getting an attribute
return
chainable
?
return
length
?
fn
(
elems
[
0
],
key
)
:
undefined
;
elems
:
// Gets
bulk
?
fn
.
call
(
elems
)
:
length
?
fn
(
elems
[
0
],
key
)
:
emptyGet
;
},
},
now
:
function
()
{
now
:
function
()
{
...
...
src/css.js
View file @
6c2a501d
...
@@ -17,16 +17,11 @@ var ralpha = /alpha\([^)]*\)/i,
...
@@ -17,16 +17,11 @@ var ralpha = /alpha\([^)]*\)/i,
currentStyle
;
currentStyle
;
jQuery
.
fn
.
css
=
function
(
name
,
value
)
{
jQuery
.
fn
.
css
=
function
(
name
,
value
)
{
// Setting 'undefined' is a no-op
return
jQuery
.
access
(
this
,
function
(
elem
,
name
,
value
)
{
if
(
arguments
.
length
===
2
&&
value
===
undefined
)
{
return
this
;
}
return
jQuery
.
access
(
this
,
name
,
value
,
true
,
function
(
elem
,
name
,
value
)
{
return
value
!==
undefined
?
return
value
!==
undefined
?
jQuery
.
style
(
elem
,
name
,
value
)
:
jQuery
.
style
(
elem
,
name
,
value
)
:
jQuery
.
css
(
elem
,
name
);
jQuery
.
css
(
elem
,
name
);
});
}
,
name
,
value
,
arguments
.
length
>
1
);
};
};
jQuery
.
extend
({
jQuery
.
extend
({
...
...
src/data.js
View file @
6c2a501d
...
@@ -246,62 +246,69 @@ jQuery.extend({
...
@@ -246,62 +246,69 @@ jQuery.extend({
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
data
:
function
(
key
,
value
)
{
data
:
function
(
key
,
value
)
{
var
parts
,
attr
,
name
,
var
parts
,
part
,
attr
,
name
,
l
,
elem
=
this
[
0
],
i
=
0
,
data
=
null
;
data
=
null
;
if
(
typeof
key
===
"undefined"
)
{
// Gets all values
if
(
key
===
undefined
)
{
if
(
this
.
length
)
{
if
(
this
.
length
)
{
data
=
jQuery
.
data
(
this
[
0
]
);
data
=
jQuery
.
data
(
elem
);
if
(
this
[
0
].
nodeType
===
1
&&
!
jQuery
.
_data
(
this
[
0
]
,
"parsedAttrs"
)
)
{
if
(
elem
.
nodeType
===
1
&&
!
jQuery
.
_data
(
elem
,
"parsedAttrs"
)
)
{
attr
=
this
[
0
]
.
attributes
;
attr
=
elem
.
attributes
;
for
(
var
i
=
0
,
l
=
attr
.
length
;
i
<
l
;
i
++
)
{
for
(
l
=
attr
.
length
;
i
<
l
;
i
++
)
{
name
=
attr
[
i
].
name
;
name
=
attr
[
i
].
name
;
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
if
(
name
.
indexOf
(
"data-"
)
===
0
)
{
name
=
jQuery
.
camelCase
(
name
.
substring
(
5
)
);
name
=
jQuery
.
camelCase
(
name
.
substring
(
5
)
);
dataAttr
(
this
[
0
]
,
name
,
data
[
name
]
);
dataAttr
(
elem
,
name
,
data
[
name
]
);
}
}
}
}
jQuery
.
_data
(
this
[
0
]
,
"parsedAttrs"
,
true
);
jQuery
.
_data
(
elem
,
"parsedAttrs"
,
true
);
}
}
}
}
return
data
;
return
data
;
}
}
else
if
(
typeof
key
===
"object"
)
{
// Sets multiple values
if
(
typeof
key
===
"object"
)
{
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
jQuery
.
data
(
this
,
key
);
jQuery
.
data
(
this
,
key
);
});
});
}
}
parts
=
key
.
split
(
"."
);
return
jQuery
.
access
(
this
,
function
(
value
)
{
parts
[
1
]
=
parts
[
1
]
?
"."
+
parts
[
1
]
:
""
;
parts
=
key
.
split
(
"."
,
2
),
parts
[
1
]
=
parts
[
1
]
?
"."
+
parts
[
1
]
:
""
;
part
=
parts
[
1
]
+
"!"
;
if
(
value
===
undefined
)
{
if
(
value
===
undefined
)
{
data
=
this
.
triggerHandler
(
"getData"
+
parts
[
1
]
+
"!"
,
[
parts
[
0
]]
);
data
=
this
.
triggerHandler
(
"getData"
+
part
,
[
parts
[
0
]
]
);
// Try to fetch any internally stored data first
// Try to fetch any internally stored data first
if
(
data
===
undefined
&&
this
.
length
)
{
if
(
data
===
undefined
&&
elem
)
{
data
=
jQuery
.
data
(
this
[
0
]
,
key
);
data
=
jQuery
.
data
(
elem
,
key
);
data
=
dataAttr
(
this
[
0
]
,
key
,
data
);
data
=
dataAttr
(
elem
,
key
,
data
);
}
}
return
data
===
undefined
&&
parts
[
1
]
?
return
data
===
undefined
&&
parts
[
1
]
?
this
.
data
(
parts
[
0
]
)
:
this
.
data
(
parts
[
0
]
)
:
data
;
data
;
}
}
else
{
parts
[
1
]
=
value
;
return
this
.
each
(
function
()
{
this
.
each
(
function
()
{
var
self
=
jQuery
(
this
),
var
self
=
jQuery
(
this
);
args
=
[
parts
[
0
],
value
];
self
.
triggerHandler
(
"setData"
+
part
s
[
1
]
+
"!"
,
arg
s
);
self
.
triggerHandler
(
"setData"
+
part
,
part
s
);
jQuery
.
data
(
this
,
key
,
value
);
jQuery
.
data
(
this
,
key
,
value
);
self
.
triggerHandler
(
"changeData"
+
part
s
[
1
]
+
"!"
,
arg
s
);
self
.
triggerHandler
(
"changeData"
+
part
,
part
s
);
});
});
}
}
,
null
,
value
,
arguments
.
length
>
1
,
null
,
false
);
},
},
removeData
:
function
(
key
)
{
removeData
:
function
(
key
)
{
...
...
src/dimensions.js
View file @
6c2a501d
(
function
(
jQuery
)
{
(
function
(
jQuery
)
{
// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
jQuery
.
each
([
"Height"
,
"Width"
],
function
(
i
,
name
)
{
jQuery
.
each
(
{
Height
:
"height"
,
Width
:
"width"
},
function
(
name
,
type
)
{
var
clientProp
=
"client"
+
name
,
var
type
=
name
.
toLowerCase
();
scrollProp
=
"scroll"
+
name
,
offsetProp
=
"offset"
+
name
;
// innerHeight and innerWidth
// innerHeight and innerWidth
jQuery
.
fn
[
"inner"
+
name
]
=
function
()
{
jQuery
.
fn
[
"inner"
+
name
]
=
function
()
{
...
@@ -25,50 +26,40 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
...
@@ -25,50 +26,40 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
null
;
null
;
};
};
jQuery
.
fn
[
type
]
=
function
(
size
)
{
jQuery
.
fn
[
type
]
=
function
(
value
)
{
// Get window width or height
return
jQuery
.
access
(
this
,
function
(
elem
,
type
,
value
)
{
var
elem
=
this
[
0
];
var
doc
,
docElemProp
,
orig
,
ret
;
if
(
!
elem
)
{
return
size
==
null
?
null
:
this
;
}
if
(
jQuery
.
isFunction
(
size
)
)
{
return
this
.
each
(
function
(
i
)
{
var
self
=
jQuery
(
this
);
self
[
type
](
size
.
call
(
this
,
i
,
self
[
type
]()
)
);
});
}
if
(
jQuery
.
isWindow
(
elem
)
)
{
if
(
jQuery
.
isWindow
(
elem
)
)
{
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
// 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
// 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
doc
=
elem
.
document
;
var
docElemProp
=
elem
.
document
.
documentElement
[
"client"
+
name
],
docElemProp
=
doc
.
documentElement
[
clientProp
];
body
=
elem
.
document
.
body
;
return
doc
.
compatMode
===
"CSS1Compat"
&&
docElemProp
||
return
elem
.
document
.
compatMode
===
"CSS1Compat"
&&
docElemProp
||
doc
.
body
&&
doc
.
body
[
clientProp
]
||
docElemProp
;
body
&&
body
[
"client"
+
name
]
||
docElemProp
;
}
// Get document width or height
// Get document width or height
}
else
if
(
elem
.
nodeType
===
9
)
{
if
(
elem
.
nodeType
===
9
)
{
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
return
Math
.
max
(
doc
=
elem
.
documentElement
;
elem
.
documentElement
[
"client"
+
name
],
return
Math
.
max
(
elem
.
body
[
"scroll"
+
name
],
elem
.
documentElement
[
"scroll"
+
name
],
doc
[
clientProp
],
elem
.
body
[
"offset"
+
name
],
elem
.
documentElement
[
"offset"
+
name
]
elem
.
body
[
scrollProp
],
doc
[
scrollProp
],
);
elem
.
body
[
offsetProp
],
doc
[
offsetProp
]
);
}
// Get or s
et width or height on the element
// G
et width or height on the element
}
else
if
(
siz
e
===
undefined
)
{
if
(
valu
e
===
undefined
)
{
var
orig
=
jQuery
.
css
(
elem
,
type
),
orig
=
jQuery
.
css
(
elem
,
type
);
ret
=
parseFloat
(
orig
);
ret
=
parseFloat
(
orig
);
return
jQuery
.
isNumeric
(
ret
)
?
ret
:
orig
;
}
return
jQuery
.
isNumeric
(
ret
)
?
ret
:
orig
;
// Set the width or height on the element
jQuery
(
elem
).
css
(
type
,
value
);
// Set the width or height on the element (default to pixels if value is unitless)
},
type
,
value
,
arguments
.
length
,
null
);
}
else
{
return
this
.
css
(
type
,
typeof
size
===
"string"
?
size
:
size
+
"px"
);
}
};
};
});
});
})(
jQuery
);
})(
jQuery
);
src/manipulation.js
View file @
6c2a501d
...
@@ -51,20 +51,12 @@ if ( !jQuery.support.htmlSerialize ) {
...
@@ -51,20 +51,12 @@ if ( !jQuery.support.htmlSerialize ) {
}
}
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
text
:
function
(
text
)
{
text
:
function
(
value
)
{
if
(
jQuery
.
isFunction
(
text
)
)
{
return
jQuery
.
access
(
this
,
function
(
value
)
{
return
this
.
each
(
function
(
i
)
{
return
value
===
undefined
?
var
self
=
jQuery
(
this
);
jQuery
.
text
(
this
)
:
this
.
empty
().
append
(
(
this
[
0
]
&&
this
[
0
].
ownerDocument
||
document
).
createTextNode
(
value
)
);
self
.
text
(
text
.
call
(
this
,
i
,
self
.
text
())
);
},
null
,
value
,
arguments
.
length
);
});
}
if
(
typeof
text
!==
"object"
&&
text
!==
undefined
)
{
return
this
.
empty
().
append
(
(
this
[
0
]
&&
this
[
0
].
ownerDocument
||
document
).
createTextNode
(
text
)
);
}
return
jQuery
.
text
(
this
);
},
},
wrapAll
:
function
(
html
)
{
wrapAll
:
function
(
html
)
{
...
@@ -216,44 +208,44 @@ jQuery.fn.extend({
...
@@ -216,44 +208,44 @@ jQuery.fn.extend({
},
},
html
:
function
(
value
)
{
html
:
function
(
value
)
{
if
(
value
===
undefined
)
{
return
jQuery
.
access
(
this
,
function
(
value
)
{
return
this
[
0
]
&&
this
[
0
].
nodeType
===
1
?
var
elem
=
this
[
0
]
||
{},
this
[
0
].
innerHTML
.
replace
(
rinlinejQuery
,
""
)
:
i
=
0
,
null
;
l
=
this
.
length
;
// See if we can take a shortcut and just use innerHTML
if
(
value
===
undefined
)
{
}
else
if
(
typeof
value
===
"string"
&&
!
rnoInnerhtml
.
test
(
value
)
&&
return
elem
.
nodeType
===
1
?
(
jQuery
.
support
.
leadingWhitespace
||
!
rleadingWhitespace
.
test
(
value
))
&&
elem
.
innerHTML
.
replace
(
rinlinejQuery
,
""
)
:
!
wrapMap
[
(
rtagName
.
exec
(
value
)
||
[
""
,
""
])[
1
].
toLowerCase
()
]
)
{
null
;
value
=
value
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
try
{
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
// Remove element nodes and prevent memory leaks
if
(
this
[
i
].
nodeType
===
1
)
{
jQuery
.
cleanData
(
this
[
i
].
getElementsByTagName
(
"*"
)
);
this
[
i
].
innerHTML
=
value
;
}
}
// If using innerHTML throws an exception, use the fallback method
}
catch
(
e
)
{
this
.
empty
().
append
(
value
);
}
}
}
else
if
(
jQuery
.
isFunction
(
value
)
)
{
this
.
each
(
function
(
i
){
var
self
=
jQuery
(
this
);
self
.
html
(
value
.
call
(
this
,
i
,
self
.
html
())
);
if
(
typeof
value
===
"string"
&&
!
rnoInnerhtml
.
test
(
value
)
&&
});
(
jQuery
.
support
.
leadingWhitespace
||
!
rleadingWhitespace
.
test
(
value
)
)
&&
!
wrapMap
[
(
rtagName
.
exec
(
value
)
||
[
""
,
""
]
)[
1
].
toLowerCase
()
]
)
{
}
else
{
value
=
value
.
replace
(
rxhtmlTag
,
"<$1></$2>"
);
this
.
empty
().
append
(
value
);
}
return
this
;
try
{
for
(;
i
<
l
;
i
++
)
{
// Remove element nodes and prevent memory leaks
elem
=
this
[
i
]
||
{};
if
(
elem
.
nodeType
===
1
)
{
jQuery
.
cleanData
(
elem
.
getElementsByTagName
(
"*"
)
);
elem
.
innerHTML
=
value
;
}
}
elem
=
0
;
// If using innerHTML throws an exception, use the fallback method
}
catch
(
e
)
{}
}
if
(
elem
)
{
this
.
empty
().
append
(
value
);
}
},
null
,
value
,
arguments
.
length
);
},
},
replaceWith
:
function
(
value
)
{
replaceWith
:
function
(
value
)
{
...
...
src/offset.js
View file @
6c2a501d
(
function
(
jQuery
)
{
(
function
(
jQuery
)
{
var
rtable
=
/^t
(?:
able|d|h
)
$/i
,
var
getOffset
,
rtable
=
/^t
(?:
able|d|h
)
$/i
,
rroot
=
/^
(?:
body|html
)
$/i
;
rroot
=
/^
(?:
body|html
)
$/i
;
if
(
"getBoundingClientRect"
in
document
.
documentElement
)
{
if
(
"getBoundingClientRect"
in
document
.
documentElement
)
{
jQuery
.
fn
.
offset
=
function
(
options
)
{
getOffset
=
function
(
elem
,
doc
,
docElem
,
box
)
{
var
elem
=
this
[
0
],
box
;
if
(
options
)
{
return
this
.
each
(
function
(
i
)
{
jQuery
.
offset
.
setOffset
(
this
,
options
,
i
);
});
}
if
(
!
elem
||
!
elem
.
ownerDocument
)
{
return
null
;
}
if
(
elem
===
elem
.
ownerDocument
.
body
)
{
return
jQuery
.
offset
.
bodyOffset
(
elem
);
}
try
{
try
{
box
=
elem
.
getBoundingClientRect
();
box
=
elem
.
getBoundingClientRect
();
}
catch
(
e
)
{}
}
catch
(
e
)
{}
var
doc
=
elem
.
ownerDocument
,
docElem
=
doc
.
documentElement
;
// Make sure we're not dealing with a disconnected DOM node
// Make sure we're not dealing with a disconnected DOM node
if
(
!
box
||
!
jQuery
.
contains
(
docElem
,
elem
)
)
{
if
(
!
box
||
!
jQuery
.
contains
(
docElem
,
elem
)
)
{
return
box
?
{
top
:
box
.
top
,
left
:
box
.
left
}
:
{
top
:
0
,
left
:
0
};
return
box
?
{
top
:
box
.
top
,
left
:
box
.
left
}
:
{
top
:
0
,
left
:
0
};
}
}
var
body
=
doc
.
body
,
var
body
=
doc
.
body
,
win
=
getWindow
(
doc
),
win
=
getWindow
(
doc
),
clientTop
=
docElem
.
clientTop
||
body
.
clientTop
||
0
,
clientTop
=
docElem
.
clientTop
||
body
.
clientTop
||
0
,
clientLeft
=
docElem
.
clientLeft
||
body
.
clientLeft
||
0
,
clientLeft
=
docElem
.
clientLeft
||
body
.
clientLeft
||
0
,
scrollTop
=
win
.
pageYOffset
||
jQuery
.
support
.
boxModel
&&
docElem
.
scrollTop
||
body
.
scrollTop
,
scrollTop
=
win
.
pageYOffset
||
jQuery
.
support
.
boxModel
&&
docElem
.
scrollTop
||
body
.
scrollTop
,
...
@@ -46,28 +28,10 @@ if ( "getBoundingClientRect" in document.documentElement ) {
...
@@ -46,28 +28,10 @@ if ( "getBoundingClientRect" in document.documentElement ) {
};
};
}
else
{
}
else
{
jQuery
.
fn
.
offset
=
function
(
options
)
{
getOffset
=
function
(
elem
,
doc
,
docElem
)
{
var
elem
=
this
[
0
];
if
(
options
)
{
return
this
.
each
(
function
(
i
)
{
jQuery
.
offset
.
setOffset
(
this
,
options
,
i
);
});
}
if
(
!
elem
||
!
elem
.
ownerDocument
)
{
return
null
;
}
if
(
elem
===
elem
.
ownerDocument
.
body
)
{
return
jQuery
.
offset
.
bodyOffset
(
elem
);
}
var
computedStyle
,
var
computedStyle
,
offsetParent
=
elem
.
offsetParent
,
offsetParent
=
elem
.
offsetParent
,
prevOffsetParent
=
elem
,
prevOffsetParent
=
elem
,
doc
=
elem
.
ownerDocument
,
docElem
=
doc
.
documentElement
,
body
=
doc
.
body
,
body
=
doc
.
body
,
defaultView
=
doc
.
defaultView
,
defaultView
=
doc
.
defaultView
,
prevComputedStyle
=
defaultView
?
defaultView
.
getComputedStyle
(
elem
,
null
)
:
elem
.
currentStyle
,
prevComputedStyle
=
defaultView
?
defaultView
.
getComputedStyle
(
elem
,
null
)
:
elem
.
currentStyle
,
...
@@ -118,6 +82,29 @@ if ( "getBoundingClientRect" in document.documentElement ) {
...
@@ -118,6 +82,29 @@ if ( "getBoundingClientRect" in document.documentElement ) {
};
};
}
}
jQuery
.
fn
.
offset
=
function
(
options
)
{
if
(
arguments
.
length
)
{
return
options
===
undefined
?
this
:
this
.
each
(
function
(
i
)
{
jQuery
.
offset
.
setOffset
(
this
,
options
,
i
);
});
}
var
elem
=
this
[
0
],
doc
=
elem
&&
elem
.
ownerDocument
;
if
(
!
doc
)
{
return
null
;
}
if
(
elem
===
doc
.
body
)
{
return
jQuery
.
offset
.
bodyOffset
(
elem
);
}
return
getOffset
(
elem
,
doc
,
doc
.
documentElement
);
};
jQuery
.
offset
=
{
jQuery
.
offset
=
{
bodyOffset
:
function
(
body
)
{
bodyOffset
:
function
(
body
)
{
...
@@ -223,42 +210,30 @@ jQuery.fn.extend({
...
@@ -223,42 +210,30 @@ jQuery.fn.extend({
// Create scrollLeft and scrollTop methods
// Create scrollLeft and scrollTop methods
jQuery
.
each
(
[
"Left"
,
"Top"
],
function
(
i
,
name
)
{
jQuery
.
each
(
{
scrollLeft
:
"pageXOffset"
,
scrollTop
:
"pageYOffset"
},
function
(
method
,
prop
)
{
var
method
=
"scroll"
+
name
;
var
top
=
/Y/
.
test
(
prop
)
;
jQuery
.
fn
[
method
]
=
function
(
val
)
{
jQuery
.
fn
[
method
]
=
function
(
val
)
{
var
elem
,
win
;
return
jQuery
.
access
(
this
,
function
(
elem
,
method
,
val
)
{
var
win
=
getWindow
(
elem
);
if
(
val
===
undefined
)
{
elem
=
this
[
0
];
if
(
val
===
undefined
)
{
return
win
?
(
prop
in
win
)
?
win
[
prop
]
:
if
(
!
elem
)
{
jQuery
.
support
.
boxModel
&&
win
.
document
.
documentElement
[
method
]
||
return
null
;
win
.
document
.
body
[
method
]
:
elem
[
method
];
}
}
win
=
getWindow
(
elem
);
// Return the scroll offset
return
win
?
(
"pageXOffset"
in
win
)
?
win
[
i
?
"pageYOffset"
:
"pageXOffset"
]
:
jQuery
.
support
.
boxModel
&&
win
.
document
.
documentElement
[
method
]
||
win
.
document
.
body
[
method
]
:
elem
[
method
];
}
// Set the scroll offset
return
this
.
each
(
function
()
{
win
=
getWindow
(
this
);
if
(
win
)
{
if
(
win
)
{
win
.
scrollTo
(
win
.
scrollTo
(
!
i
?
val
:
jQuery
(
win
).
scrollLeft
(),
!
top
?
val
:
jQuery
(
win
).
scrollLeft
(),
i
?
val
:
jQuery
(
win
).
scrollTop
()
top
?
val
:
jQuery
(
win
).
scrollTop
()
);
);
}
else
{
}
else
{
this
[
method
]
=
val
;
elem
[
method
]
=
val
;
}
}
});
}
,
method
,
val
,
arguments
.
length
,
null
);
};
};
});
});
...
...
src/queue.js
View file @
6c2a501d
...
@@ -100,21 +100,27 @@ jQuery.extend({
...
@@ -100,21 +100,27 @@ jQuery.extend({
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
queue
:
function
(
type
,
data
)
{
queue
:
function
(
type
,
data
)
{
var
setter
=
2
;
if
(
typeof
type
!==
"string"
)
{
if
(
typeof
type
!==
"string"
)
{
data
=
type
;
data
=
type
;
type
=
"fx"
;
type
=
"fx"
;
setter
--
;
}
}
if
(
data
===
undefined
)
{
if
(
arguments
.
length
<
setter
)
{
return
jQuery
.
queue
(
this
[
0
],
type
);
return
jQuery
.
queue
(
this
[
0
],
type
);
}
}
return
this
.
each
(
function
()
{
var
queue
=
jQuery
.
queue
(
this
,
type
,
data
);
if
(
type
===
"fx"
&&
queue
[
0
]
!==
"inprogress"
)
{
return
data
===
undefined
?
jQuery
.
dequeue
(
this
,
type
);
this
:
}
this
.
each
(
function
()
{
});
var
queue
=
jQuery
.
queue
(
this
,
type
,
data
);
if
(
type
===
"fx"
&&
queue
[
0
]
!==
"inprogress"
)
{
jQuery
.
dequeue
(
this
,
type
);
}
});
},
},
dequeue
:
function
(
type
)
{
dequeue
:
function
(
type
)
{
return
this
.
each
(
function
()
{
return
this
.
each
(
function
()
{
...
...
test/unit/attributes.js
View file @
6c2a501d
...
@@ -158,7 +158,7 @@ test("attr(Hash)", function() {
...
@@ -158,7 +158,7 @@ test("attr(Hash)", function() {
});
});
test
(
"attr(String, Object)"
,
function
()
{
test
(
"attr(String, Object)"
,
function
()
{
expect
(
78
);
expect
(
81
);
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
var
div
=
jQuery
(
"div"
).
attr
(
"foo"
,
"bar"
),
fail
=
false
;
fail
=
false
;
...
@@ -353,6 +353,12 @@ test("attr(String, Object)", function() {
...
@@ -353,6 +353,12 @@ test("attr(String, Object)", function() {
+
"</svg>"
).
appendTo
(
"body"
);
+
"</svg>"
).
appendTo
(
"body"
);
equal
(
$svg
.
attr
(
"cx"
,
100
).
attr
(
"cx"
),
"100"
,
"Set attribute on svg element"
);
equal
(
$svg
.
attr
(
"cx"
,
100
).
attr
(
"cx"
),
"100"
,
"Set attribute on svg element"
);
$svg
.
remove
();
$svg
.
remove
();
// undefined values are chainable
jQuery
(
"#name"
).
attr
(
"maxlength"
,
"5"
).
removeAttr
(
"nonexisting"
);
equal
(
typeof
jQuery
(
"#name"
).
attr
(
"maxlength"
,
undefined
),
"object"
,
".attr('attribute', undefined) is chainable (#5571)"
);
equal
(
jQuery
(
"#name"
).
attr
(
"maxlength"
,
undefined
).
attr
(
"maxlength"
),
"5"
,
".attr('attribute', undefined) does not change value (#5571)"
);
equal
(
jQuery
(
"#name"
).
attr
(
"nonexisting"
,
undefined
).
attr
(
"nonexisting"
),
undefined
,
".attr('attribute', undefined) does not create attribute (#5571)"
);
});
});
test
(
"attr(jquery_method)"
,
function
(){
test
(
"attr(jquery_method)"
,
function
(){
...
...
test/unit/data.js
View file @
6c2a501d
...
@@ -222,8 +222,7 @@ test(".data(String) and .data(String, Object)", function() {
...
@@ -222,8 +222,7 @@ test(".data(String) and .data(String, Object)", function() {
div
.
data
(
"test"
,
"overwritten"
);
div
.
data
(
"test"
,
"overwritten"
);
equal
(
div
.
data
(
"test"
),
"overwritten"
,
"Check for overwritten data"
);
equal
(
div
.
data
(
"test"
),
"overwritten"
,
"Check for overwritten data"
);
div
.
data
(
"test"
,
undefined
);
equal
(
div
.
data
(
"test"
,
undefined
).
data
(
"test"
),
"overwritten"
,
"Check that .data('key',undefined) does nothing but is chainable (#5571)"
);
equal
(
div
.
data
(
"test"
),
"overwritten"
,
"Check that data wasn't removed"
);
div
.
data
(
"test"
,
null
);
div
.
data
(
"test"
,
null
);
ok
(
div
.
data
(
"test"
)
===
null
,
"Check for null data"
);
ok
(
div
.
data
(
"test"
)
===
null
,
"Check for null data"
);
...
...
test/unit/dimensions.js
View file @
6c2a501d
...
@@ -41,11 +41,16 @@ test("width()", function() {
...
@@ -41,11 +41,16 @@ test("width()", function() {
testWidth
(
pass
);
testWidth
(
pass
);
});
});
test
(
"width() with function"
,
function
()
{
test
(
"width(undefined)"
,
function
()
{
expect
(
1
);
equal
(
jQuery
(
"#nothiddendiv"
).
width
(
30
).
width
(
undefined
).
width
(),
30
,
".width(undefined) is chainable (#5571)"
);
});
test
(
"width(Function)"
,
function
()
{
testWidth
(
fn
);
testWidth
(
fn
);
});
});
test
(
"width(
) with function args
"
,
function
()
{
test
(
"width(
Function(args))
"
,
function
()
{
expect
(
2
);
expect
(
2
);
var
$div
=
jQuery
(
"#nothiddendiv"
);
var
$div
=
jQuery
(
"#nothiddendiv"
);
...
@@ -90,11 +95,16 @@ test("height()", function() {
...
@@ -90,11 +95,16 @@ test("height()", function() {
testHeight
(
pass
);
testHeight
(
pass
);
});
});
test
(
"height() with function"
,
function
()
{
test
(
"height(undefined)"
,
function
()
{
expect
(
1
);
equal
(
jQuery
(
"#nothiddendiv"
).
height
(
30
).
height
(
undefined
).
height
(),
30
,
".height(undefined) is chainable (#5571)"
);
});
test
(
"height(Function)"
,
function
()
{
testHeight
(
fn
);
testHeight
(
fn
);
});
});
test
(
"height(
) with function args
"
,
function
()
{
test
(
"height(
Function(args))
"
,
function
()
{
expect
(
2
);
expect
(
2
);
var
$div
=
jQuery
(
"#nothiddendiv"
);
var
$div
=
jQuery
(
"#nothiddendiv"
);
...
...
test/unit/manipulation.js
View file @
6c2a501d
...
@@ -16,6 +16,11 @@ test("text()", function() {
...
@@ -16,6 +16,11 @@ test("text()", function() {
notEqual
(
jQuery
(
document
).
text
(),
""
,
"Retrieving text for the document retrieves all text (#10724)."
);
notEqual
(
jQuery
(
document
).
text
(),
""
,
"Retrieving text for the document retrieves all text (#10724)."
);
});
});
test
(
"text(undefined)"
,
function
()
{
expect
(
1
);
equal
(
jQuery
(
"#foo"
).
text
(
"<div"
).
text
(
undefined
)[
0
].
innerHTML
,
"<div"
,
".text(undefined) is chainable (#5571)"
);
});
var
testText
=
function
(
valueObj
)
{
var
testText
=
function
(
valueObj
)
{
expect
(
4
);
expect
(
4
);
var
val
=
valueObj
(
"<div><b>Hello</b> cruel world!</div>"
);
var
val
=
valueObj
(
"<div><b>Hello</b> cruel world!</div>"
);
...
@@ -1207,6 +1212,11 @@ test("clone() on XML nodes", function() {
...
@@ -1207,6 +1212,11 @@ test("clone() on XML nodes", function() {
});
});
}
}
test
(
"html(undefined)"
,
function
()
{
expect
(
1
);
equal
(
jQuery
(
"#foo"
).
html
(
"<i>test</i>"
).
html
(
undefined
).
html
().
toLowerCase
(),
"<i>test</i>"
,
".html(undefined) is chainable (#5571)"
);
});
var
testHtml
=
function
(
valueObj
)
{
var
testHtml
=
function
(
valueObj
)
{
expect
(
34
);
expect
(
34
);
...
...
test/unit/offset.js
View file @
6c2a501d
...
@@ -342,7 +342,7 @@ testoffset("table", function( jQuery ) {
...
@@ -342,7 +342,7 @@ testoffset("table", function( jQuery ) {
});
});
testoffset
(
"scroll"
,
function
(
jQuery
,
win
)
{
testoffset
(
"scroll"
,
function
(
jQuery
,
win
)
{
expect
(
2
2
);
expect
(
2
4
);
var
ie
=
jQuery
.
browser
.
msie
&&
parseInt
(
jQuery
.
browser
.
version
,
10
)
<
8
;
var
ie
=
jQuery
.
browser
.
msie
&&
parseInt
(
jQuery
.
browser
.
version
,
10
)
<
8
;
...
@@ -362,8 +362,9 @@ testoffset("scroll", function( jQuery, win ) {
...
@@ -362,8 +362,9 @@ testoffset("scroll", function( jQuery, win ) {
equal
(
jQuery
(
"#scroll-1-1"
).
scrollTop
(),
0
,
"jQuery('#scroll-1-1').scrollTop()"
);
equal
(
jQuery
(
"#scroll-1-1"
).
scrollTop
(),
0
,
"jQuery('#scroll-1-1').scrollTop()"
);
equal
(
jQuery
(
"#scroll-1-1"
).
scrollLeft
(),
0
,
"jQuery('#scroll-1-1').scrollLeft()"
);
equal
(
jQuery
(
"#scroll-1-1"
).
scrollLeft
(),
0
,
"jQuery('#scroll-1-1').scrollLeft()"
);
// equal( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" );
// scroll method chaining
// equal( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" );
equal
(
jQuery
(
"#scroll-1"
).
scrollTop
(
undefined
).
scrollTop
(),
5
,
".scrollTop(undefined) is chainable (#5571)"
);
equal
(
jQuery
(
"#scroll-1"
).
scrollLeft
(
undefined
).
scrollLeft
(),
5
,
".scrollLeft(undefined) is chainable (#5571)"
);
win
.
name
=
"test"
;
win
.
name
=
"test"
;
...
@@ -405,11 +406,12 @@ testoffset("body", function( jQuery ) {
...
@@ -405,11 +406,12 @@ testoffset("body", function( jQuery ) {
equal
(
jQuery
(
"body"
).
offset
().
left
,
1
,
"jQuery('#body').offset().left"
);
equal
(
jQuery
(
"body"
).
offset
().
left
,
1
,
"jQuery('#body').offset().left"
);
});
});
test
(
"
Chaining offset(coords) returns jQuery object
"
,
function
()
{
test
(
"
chaining
"
,
function
()
{
expect
(
2
);
expect
(
3
);
var
coords
=
{
top
:
1
,
left
:
1
};
var
coords
=
{
top
:
1
,
left
:
1
};
equal
(
jQuery
(
"#absolute-1"
).
offset
(
coords
).
selector
,
"#absolute-1"
,
"offset(coords) returns jQuery object"
);
equal
(
jQuery
(
"#absolute-1"
).
offset
(
coords
).
selector
,
"#absolute-1"
,
"offset(coords) returns jQuery object"
);
equal
(
jQuery
(
"#non-existent"
).
offset
(
coords
).
selector
,
"#non-existent"
,
"offset(coords) with empty jQuery set returns jQuery object"
);
equal
(
jQuery
(
"#non-existent"
).
offset
(
coords
).
selector
,
"#non-existent"
,
"offset(coords) with empty jQuery set returns jQuery object"
);
equal
(
jQuery
(
"#absolute-1"
).
offset
(
undefined
).
selector
,
"#absolute-1"
,
"offset(undefined) returns jQuery object (#5571)"
);
});
});
test
(
"offsetParent"
,
function
(){
test
(
"offsetParent"
,
function
(){
...
...
test/unit/queue.js
View file @
6c2a501d
module
(
"queue"
,
{
teardown
:
moduleTeardown
});
module
(
"queue"
,
{
teardown
:
moduleTeardown
});
test
(
"queue() with other types"
,
function
()
{
test
(
"queue() with other types"
,
function
()
{
expect
(
1
1
);
expect
(
1
2
);
var
counter
=
0
;
var
counter
=
0
;
stop
();
stop
();
...
@@ -36,6 +36,8 @@ test("queue() with other types",function() {
...
@@ -36,6 +36,8 @@ test("queue() with other types",function() {
equal
(
$div
.
queue
(
"foo"
).
length
,
4
,
"Testing queue length"
);
equal
(
$div
.
queue
(
"foo"
).
length
,
4
,
"Testing queue length"
);
equal
(
$div
.
queue
(
"foo"
,
undefined
).
queue
(
"foo"
).
length
,
4
,
".queue('name',undefined) does nothing but is chainable (#5571)"
);
$div
.
dequeue
(
"foo"
);
$div
.
dequeue
(
"foo"
);
equal
(
counter
,
3
,
"Testing previous call to dequeue"
);
equal
(
counter
,
3
,
"Testing previous call to dequeue"
);
...
@@ -289,4 +291,4 @@ test("promise()", function() {
...
@@ -289,4 +291,4 @@ test("promise()", function() {
jQuery
.
each
(
objects
,
function
()
{
jQuery
.
each
(
objects
,
function
()
{
this
.
dequeue
();
this
.
dequeue
();
});
});
});
});
\ No newline at end of file
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