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
8f5f1b2e
Commit
8f5f1b2e
authored
Dec 09, 2011
by
Mike Sherov
Committed by
Dave Methvin
Dec 09, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #8498. Add cssHooks[prop].expand for use by animate().
parent
7f6a9913
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
21 deletions
+127
-21
css.js
src/css.js
+43
-17
effects.js
src/effects.js
+17
-4
css.js
test/unit/css.js
+40
-0
effects.js
test/unit/effects.js
+27
-0
No files found.
src/css.js
View file @
8f5f1b2e
...
@@ -10,8 +10,10 @@ var ralpha = /alpha\([^)]*\)/i,
...
@@ -10,8 +10,10 @@ var ralpha = /alpha\([^)]*\)/i,
rmargin
=
/^margin/
,
rmargin
=
/^margin/
,
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssWidth
=
[
"Left"
,
"Right"
],
cssHeight
=
[
"Top"
,
"Bottom"
],
// order is important!
cssExpand
=
[
"Top"
,
"Right"
,
"Bottom"
,
"Left"
],
curCSS
,
curCSS
,
getComputedStyle
,
getComputedStyle
,
...
@@ -169,10 +171,10 @@ jQuery.each(["height", "width"], function( i, name ) {
...
@@ -169,10 +171,10 @@ jQuery.each(["height", "width"], function( i, name ) {
get
:
function
(
elem
,
computed
,
extra
)
{
get
:
function
(
elem
,
computed
,
extra
)
{
if
(
computed
)
{
if
(
computed
)
{
if
(
elem
.
offsetWidth
!==
0
)
{
if
(
elem
.
offsetWidth
!==
0
)
{
return
getW
H
(
elem
,
name
,
extra
);
return
getW
idthOrHeight
(
elem
,
name
,
extra
);
}
else
{
}
else
{
return
jQuery
.
swap
(
elem
,
cssShow
,
function
()
{
return
jQuery
.
swap
(
elem
,
cssShow
,
function
()
{
return
getW
H
(
elem
,
name
,
extra
);
return
getW
idthOrHeight
(
elem
,
name
,
extra
);
});
});
}
}
}
}
...
@@ -326,24 +328,23 @@ if ( document.documentElement.currentStyle ) {
...
@@ -326,24 +328,23 @@ if ( document.documentElement.currentStyle ) {
curCSS
=
getComputedStyle
||
currentStyle
;
curCSS
=
getComputedStyle
||
currentStyle
;
function
getW
H
(
elem
,
name
,
extra
)
{
function
getW
idthOrHeight
(
elem
,
name
,
extra
)
{
// Start with offset property
// Start with offset property
var
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
var
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
which
=
name
===
"width"
?
cssWidth
:
cssHeight
,
i
=
name
===
"width"
?
1
:
0
,
i
=
0
,
len
=
4
;
len
=
which
.
length
;
if
(
val
>
0
)
{
if
(
val
>
0
)
{
if
(
extra
!==
"border"
)
{
if
(
extra
!==
"border"
)
{
for
(
;
i
<
len
;
i
++
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
if
(
!
extra
)
{
if
(
!
extra
)
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
which
[
i
]
)
)
||
0
;
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
}
}
if
(
extra
===
"margin"
)
{
if
(
extra
===
"margin"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
which
[
i
]
)
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
else
{
}
else
{
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
which
[
i
]
+
"Width"
)
)
||
0
;
val
-=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
}
}
}
}
...
@@ -354,20 +355,20 @@ function getWH( elem, name, extra ) {
...
@@ -354,20 +355,20 @@ function getWH( elem, name, extra ) {
// Fall back to computed then uncomputed css if necessary
// Fall back to computed then uncomputed css if necessary
val
=
curCSS
(
elem
,
name
,
name
);
val
=
curCSS
(
elem
,
name
,
name
);
if
(
val
<
0
||
val
==
null
)
{
if
(
val
<
0
||
val
==
null
)
{
val
=
elem
.
style
[
name
]
||
0
;
val
=
elem
.
style
[
name
];
}
}
// Normalize "", auto, and prepare for extra
// Normalize "", auto, and prepare for extra
val
=
parseFloat
(
val
)
||
0
;
val
=
parseFloat
(
val
)
||
0
;
// Add padding, border, margin
// Add padding, border, margin
if
(
extra
)
{
if
(
extra
)
{
for
(
;
i
<
len
;
i
++
)
{
for
(
;
i
<
len
;
i
+=
2
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
which
[
i
]
)
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
if
(
extra
!==
"padding"
)
{
if
(
extra
!==
"padding"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
which
[
i
]
+
"Width"
)
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
if
(
extra
===
"margin"
)
{
if
(
extra
===
"margin"
)
{
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
which
[
i
]
)
)
||
0
;
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
}
}
}
}
}
...
@@ -388,4 +389,29 @@ if ( jQuery.expr && jQuery.expr.filters ) {
...
@@ -388,4 +389,29 @@ if ( jQuery.expr && jQuery.expr.filters ) {
};
};
}
}
// These hooks are used by animate to expand properties
jQuery
.
each
({
margin
:
""
,
padding
:
""
,
border
:
"Width"
},
function
(
prefix
,
suffix
)
{
jQuery
.
cssHooks
[
prefix
+
suffix
]
=
{
expand
:
function
(
value
)
{
var
i
,
// assumes a single number if not a string
parts
=
typeof
value
===
"string"
?
value
.
split
(
" "
)
:
[
value
],
expanded
=
{};
for
(
i
=
0
;
i
<
4
;
i
++
)
{
expanded
[
prefix
+
cssExpand
[
i
]
+
suffix
]
=
parts
[
i
]
||
parts
[
i
-
2
]
||
parts
[
0
];
}
return
expanded
;
}
};
});
})(
jQuery
);
})(
jQuery
);
src/effects.js
View file @
8f5f1b2e
...
@@ -142,24 +142,37 @@ jQuery.fn.extend({
...
@@ -142,24 +142,37 @@ jQuery.fn.extend({
var
opt
=
jQuery
.
extend
(
{},
optall
),
var
opt
=
jQuery
.
extend
(
{},
optall
),
isElement
=
this
.
nodeType
===
1
,
isElement
=
this
.
nodeType
===
1
,
hidden
=
isElement
&&
jQuery
(
this
).
is
(
":hidden"
),
hidden
=
isElement
&&
jQuery
(
this
).
is
(
":hidden"
),
name
,
val
,
p
,
e
,
name
,
val
,
p
,
e
,
hooks
,
replace
,
parts
,
start
,
end
,
unit
,
parts
,
start
,
end
,
unit
,
method
;
method
;
// will store per property easing and be used to determine when an animation is complete
// will store per property easing and be used to determine when an animation is complete
opt
.
animatedProperties
=
{};
opt
.
animatedProperties
=
{};
// first pass over propertys to expand / normalize
for
(
p
in
prop
)
{
for
(
p
in
prop
)
{
// property name normalization
name
=
jQuery
.
camelCase
(
p
);
name
=
jQuery
.
camelCase
(
p
);
if
(
p
!==
name
)
{
if
(
p
!==
name
)
{
prop
[
name
]
=
prop
[
p
];
prop
[
name
]
=
prop
[
p
];
delete
prop
[
p
];
delete
prop
[
p
];
}
}
if
(
(
hooks
=
jQuery
.
cssHooks
[
name
]
)
&&
"expand"
in
hooks
)
{
replace
=
hooks
.
expand
(
prop
[
name
]
);
delete
prop
[
name
];
// not quite $.extend, this wont overwrite keys already present.
// also - reusing 'p' from above because we have the correct "name"
for
(
p
in
replace
)
{
if
(
!
(
p
in
prop
)
)
{
prop
[
p
]
=
replace
[
p
];
}
}
}
}
for
(
name
in
prop
)
{
val
=
prop
[
name
];
val
=
prop
[
name
];
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
if
(
jQuery
.
isArray
(
val
)
)
{
if
(
jQuery
.
isArray
(
val
)
)
{
opt
.
animatedProperties
[
name
]
=
val
[
1
];
opt
.
animatedProperties
[
name
]
=
val
[
1
];
...
...
test/unit/css.js
View file @
8f5f1b2e
...
@@ -549,4 +549,44 @@ test("outerWidth(true) and css('margin') returning % instead of px in Webkit, se
...
@@ -549,4 +549,44 @@ test("outerWidth(true) and css('margin') returning % instead of px in Webkit, se
el
=
jQuery
(
"<div/>"
).
css
({
width
:
"50%"
,
marginRight
:
"50%"
}).
appendTo
(
container
);
el
=
jQuery
(
"<div/>"
).
css
({
width
:
"50%"
,
marginRight
:
"50%"
}).
appendTo
(
container
);
equal
(
el
.
outerWidth
(
true
),
400
,
"outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639"
);
equal
(
el
.
outerWidth
(
true
),
400
,
"outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639"
);
});
test
(
"cssHooks - expand"
,
function
()
{
expect
(
15
);
var
result
,
properties
=
{
margin
:
[
"marginTop"
,
"marginRight"
,
"marginBottom"
,
"marginLeft"
],
borderWidth
:
[
"borderTopWidth"
,
"borderRightWidth"
,
"borderBottomWidth"
,
"borderLeftWidth"
],
padding
:
[
"paddingTop"
,
"paddingRight"
,
"paddingBottom"
,
"paddingLeft"
]
};
jQuery
.
each
(
properties
,
function
(
property
,
keys
)
{
var
hook
=
jQuery
.
cssHooks
[
property
],
expected
=
{};
jQuery
.
each
(
keys
,
function
(
_
,
key
)
{
expected
[
key
]
=
10
;
});
result
=
hook
.
expand
(
10
);
deepEqual
(
result
,
expected
,
property
+
" expands properly with a number"
);
jQuery
.
each
(
keys
,
function
(
_
,
key
)
{
expected
[
key
]
=
"10px"
;
});
result
=
hook
.
expand
(
"10px"
);
deepEqual
(
result
,
expected
,
property
+
" expands properly with '10px'"
);
expected
[
keys
[
1
]
]
=
expected
[
keys
[
3
]
]
=
"20px"
;
result
=
hook
.
expand
(
"10px 20px"
);
deepEqual
(
result
,
expected
,
property
+
" expands properly with '10px 20px'"
);
expected
[
keys
[
2
]
]
=
"30px"
;
result
=
hook
.
expand
(
"10px 20px 30px"
);
deepEqual
(
result
,
expected
,
property
+
" expands properly with '10px 20px 30px'"
);
expected
[
keys
[
3
]
]
=
"40px"
;
result
=
hook
.
expand
(
"10px 20px 30px 40px"
);
deepEqual
(
result
,
expected
,
property
+
" expands properly with '10px 20px 30px 40px'"
);
});
});
});
\ No newline at end of file
test/unit/effects.js
View file @
8f5f1b2e
...
@@ -1271,3 +1271,30 @@ asyncTest( "callbacks that throw exceptions will be removed (#5684)", function()
...
@@ -1271,3 +1271,30 @@ asyncTest( "callbacks that throw exceptions will be removed (#5684)", function()
start
();
start
();
},
1
);
},
1
);
});
});
test
(
"animate will scale margin properties individually"
,
function
()
{
expect
(
2
);
stop
();
var
foo
=
jQuery
(
"#foo"
).
css
({
margin
:
0
,
marginLeft
:
100
});
ok
(
foo
.
css
(
"marginLeft"
)
!==
foo
.
css
(
"marginRight"
),
"Sanity Check"
);
foo
.
animate
({
margin
:
200
}).
stop
();
ok
(
foo
.
css
(
"marginLeft"
)
!==
foo
.
css
(
"marginRight"
),
"The margin properties are different"
);
// clean up for next test
foo
.
css
({
marginLeft
:
''
,
marginRight
:
''
,
marginTop
:
''
,
marginBottom
:
''
});
start
();
});
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