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
bc7231e3
Commit
bc7231e3
authored
May 25, 2012
by
Richard Gibson
Committed by
Dave Methvin
May 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply a GibsonTransform(-55) to the #10877 fix. Closes gh-788.
parent
d5e5ce5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
110 deletions
+103
-110
css.js
src/css.js
+59
-48
dimensions.js
src/dimensions.js
+44
-62
No files found.
src/css.js
View file @
bc7231e3
...
...
@@ -112,7 +112,7 @@ jQuery.extend({
// convert relative number strings (+= or -=) to relative numbers. #7345
if
(
type
===
"string"
&&
(
ret
=
rrelNum
.
exec
(
value
))
)
{
value
=
(
+
(
ret
[
1
]
+
1
)
*
+
ret
[
2
]
)
+
parseFloat
(
jQuery
.
css
(
elem
,
name
)
);
value
=
(
ret
[
1
]
+
1
)
*
ret
[
2
]
+
parseFloat
(
jQuery
.
css
(
elem
,
name
)
);
// Fixes bug #9237
type
=
"number"
;
}
...
...
@@ -147,8 +147,8 @@ jQuery.extend({
}
},
css
:
function
(
elem
,
name
,
extra
)
{
var
ret
,
hooks
,
css
:
function
(
elem
,
name
,
numeric
,
extra
)
{
var
val
,
num
,
hooks
,
origName
=
jQuery
.
camelCase
(
name
);
// Make sure that we're working with the right name
...
...
@@ -164,13 +164,21 @@ jQuery.extend({
}
// If a hook was provided get the computed value from there
if
(
hooks
&&
"get"
in
hooks
&&
(
ret
=
hooks
.
get
(
elem
,
true
,
extra
))
!==
undefined
)
{
return
ret
;
if
(
hooks
&&
"get"
in
hooks
)
{
val
=
hooks
.
get
(
elem
,
true
,
extra
);
}
// Otherwise, if a way to get the computed value exists, use that
}
else
{
return
curCSS
(
elem
,
name
);
if
(
val
===
undefined
)
{
val
=
curCSS
(
elem
,
name
);
}
// Return, converting to number if forced or a qualifier was provided and val looks numeric
if
(
numeric
||
extra
)
{
num
=
parseFloat
(
val
);
return
numeric
||
jQuery
.
isNumeric
(
num
)
?
num
||
0
:
val
;
}
return
val
;
},
// A method for quickly swapping in/out CSS properties to get correct calculations
...
...
@@ -272,43 +280,45 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
function
setPositiveNumber
(
elem
,
value
,
subtract
)
{
var
matches
=
rnumsplit
.
exec
(
value
);
return
matches
?
Math
.
max
(
0
,
+
matches
[
1
]
-
(
subtract
||
0
)
)
+
(
matches
[
2
]
||
"px"
)
:
value
;
Math
.
max
(
0
,
matches
[
1
]
-
(
subtract
||
0
)
)
+
(
matches
[
2
]
||
"px"
)
:
value
;
}
function
augmentWidthOrHeight
(
name
,
elem
,
extra
,
isBorderBox
)
{
var
val
=
0
,
i
=
name
===
"width"
?
1
:
0
;
// if the measurement we need is already represented by the measurement
// there's no need to augment further
if
(
extra
!==
(
isBorderBox
?
"border"
:
"content"
)
)
{
for
(
;
i
<
4
;
i
+=
2
)
{
// both box models exclude margin, so add it if we want it
if
(
extra
===
"margin"
)
{
// we use jQuery.css instead of curCSS here
// because of the reliableMarginRight CSS hook!
val
+=
parseFloat
(
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
]
)
)
||
0
;
}
function
augmentWidthOrHeight
(
elem
,
name
,
extra
,
isBorderBox
)
{
var
i
=
extra
===
(
isBorderBox
?
"border"
:
"content"
)
?
// If we already have the right measurement, avoid augmentation
4
:
// Otherwise initialize for horizontal or vertical properties
name
===
"width"
?
1
:
0
,
val
=
0
;
for
(
;
i
<
4
;
i
+=
2
)
{
// both box models exclude margin, so add it if we want it
if
(
extra
===
"margin"
)
{
// we use jQuery.css instead of curCSS here
// because of the reliableMarginRight CSS hook!
val
+=
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
],
true
);
}
if
(
isBorderBox
)
{
// border-box includes padding, so remove it if we want content
if
(
extra
===
"content"
)
{
val
-=
parseFloat
(
curCSS
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
}
// From this point on we use curCSS for maximum performance (relevant in animations)
if
(
isBorderBox
)
{
// border-box includes padding, so remove it if we want content
if
(
extra
===
"content"
)
{
val
-=
parseFloat
(
curCSS
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
}
// at this point, extra isnt border nor margin, so remove border
if
(
extra
!==
"margin"
)
{
val
-=
parseFloat
(
curCSS
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
else
{
// at this point, extra isnt content, so add padding
val
+=
parseFloat
(
curCSS
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
// at this point, extra isnt border nor margin, so remove border
if
(
extra
!==
"margin"
)
{
val
-=
parseFloat
(
curCSS
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
else
{
// at this point, extra isnt content, so add padding
val
+=
parseFloat
(
curCSS
(
elem
,
"padding"
+
cssExpand
[
i
]
)
)
||
0
;
// at this point, extra isnt content nor padding, so add border
if
(
extra
!==
"padding"
)
{
val
+=
parseFloat
(
curCSS
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
// at this point, extra isnt content nor padding, so add border
if
(
extra
!==
"padding"
)
{
val
+=
parseFloat
(
curCSS
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
)
)
||
0
;
}
}
}
...
...
@@ -343,14 +353,15 @@ function getWidthOrHeight( elem, name, extra ) {
val
=
parseFloat
(
val
)
||
0
;
}
// determine which box-sizing width we're supposed to be getting
if
(
!
extra
)
{
extra
=
isBorderBox
?
"border"
:
"content"
;
}
val
+=
augmentWidthOrHeight
(
name
,
elem
,
extra
,
valueIsBorderBox
);
return
val
+
"px"
;
// use the active box-sizing model to add/subtract irrelevant styles
return
(
val
+
augmentWidthOrHeight
(
elem
,
name
,
extra
||
(
isBorderBox
?
"border"
:
"content"
),
valueIsBorderBox
)
)
+
"px"
;
}
jQuery
.
each
([
"height"
,
"width"
],
function
(
i
,
name
)
{
...
...
@@ -370,8 +381,8 @@ jQuery.each([ "height", "width" ], function( i, name ) {
set
:
function
(
elem
,
value
,
extra
)
{
return
setPositiveNumber
(
elem
,
value
,
extra
?
augmentWidthOrHeight
(
name
,
elem
,
name
,
extra
,
jQuery
.
support
.
boxSizing
&&
jQuery
.
css
(
elem
,
"boxSizing"
)
===
"border-box"
)
:
0
...
...
src/dimensions.js
View file @
bc7231e3
(
function
(
jQuery
)
{
// Create
width, height, innerHeight, innerW
idth, outerHeight and outerWidth methods
// Create
innerHeight, innerWidth, height, w
idth, outerHeight and outerWidth methods
jQuery
.
each
(
{
Height
:
"height"
,
Width
:
"width"
},
function
(
name
,
type
)
{
var
clientProp
=
"client"
+
name
,
scrollProp
=
"scroll"
+
name
,
offsetProp
=
"offset"
+
name
;
// height, width, innerHeight and innerWidth
jQuery
.
each
(
{
padding
:
"inner"
+
name
,
content
:
type
},
function
(
extra
,
funcName
)
{
jQuery
.
fn
[
funcName
]
=
function
(
value
)
{
var
args
=
[
type
,
extra
];
if
(
arguments
.
length
)
{
args
.
push
(
value
);
}
return
getDimension
.
apply
(
this
,
args
);
};
});
// outerHeight and outerWidth
jQuery
.
fn
[
"outer"
+
name
]
=
function
(
margin
,
value
)
{
var
args
=
[
type
,
(
margin
===
true
||
value
===
true
)
?
"margin"
:
"border"
];
if
(
arguments
.
length
&&
typeof
margin
!==
"boolean"
)
{
args
.
push
(
margin
);
}
return
getDimension
.
apply
(
this
,
args
);
};
function
getDimension
(
type
,
extra
,
value
)
{
return
jQuery
.
access
(
this
,
function
(
elem
,
type
,
value
)
{
var
doc
,
orig
,
ret
;
if
(
jQuery
.
isWindow
(
elem
)
)
{
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
// isn't a whole lot we can do. See pull request at this URL for discussion:
// https://github.com/jquery/jquery/pull/764
return
elem
.
document
.
documentElement
[
clientProp
];
}
// Get document width or height
if
(
elem
.
nodeType
===
9
)
{
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
doc
=
elem
.
documentElement
;
// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
// instead we use the correct client[Width/Height]
// support:IE6
if
(
doc
[
clientProp
]
>=
doc
[
scrollProp
]
)
{
return
doc
[
clientProp
];
jQuery
.
each
(
{
padding
:
"inner"
+
name
,
content
:
type
,
""
:
"outer"
+
name
},
function
(
defaultExtra
,
funcName
)
{
// margin is only for outerHeight, outerWidth
jQuery
.
fn
[
funcName
]
=
function
(
margin
,
value
)
{
var
clientProp
=
"client"
+
name
,
scrollProp
=
"scroll"
+
name
,
offsetProp
=
"offset"
+
name
,
chainable
=
arguments
.
length
&&
(
defaultExtra
||
typeof
margin
!==
"boolean"
),
extra
=
defaultExtra
||
(
margin
===
true
||
value
===
true
?
"margin"
:
"border"
);
return
jQuery
.
access
(
this
,
function
(
elem
,
type
,
value
)
{
var
doc
;
if
(
jQuery
.
isWindow
(
elem
)
)
{
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
// isn't a whole lot we can do. See pull request at this URL for discussion:
// https://github.com/jquery/jquery/pull/764
return
elem
.
document
.
documentElement
[
clientProp
];
}
return
Math
.
max
(
elem
.
body
[
scrollProp
],
doc
[
scrollProp
],
elem
.
body
[
offsetProp
],
doc
[
offsetProp
]
);
}
// Get document width or height
if
(
elem
.
nodeType
===
9
)
{
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
doc
=
elem
.
documentElement
;
// when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
// so we can't use max, as it'll choose the incorrect offset[Width/Height]
// instead we use the correct client[Width/Height]
// support:IE6
if
(
doc
[
clientProp
]
>=
doc
[
scrollProp
]
)
{
return
doc
[
clientProp
];
}
return
Math
.
max
(
elem
.
body
[
scrollProp
],
doc
[
scrollProp
],
elem
.
body
[
offsetProp
],
doc
[
offsetProp
]
);
}
// Get width or height on the element
if
(
value
===
undefined
)
{
orig
=
jQuery
.
css
(
elem
,
type
,
extra
);
ret
=
parseFloat
(
orig
);
return
jQuery
.
isNumeric
(
ret
)
?
ret
:
orig
;
}
return
value
===
undefined
?
// Get width or height on the element, requesting but not forcing parseFloat
jQuery
.
css
(
elem
,
type
,
value
,
extra
)
:
// Set the width or height on the element
jQuery
.
style
(
elem
,
type
,
value
,
extra
);
},
type
,
value
,
arguments
.
length
>
2
,
null
);
}
// Set width or height on the element
jQuery
.
style
(
elem
,
type
,
value
,
extra
);
},
type
,
chainable
?
margin
:
undefined
,
chainable
);
};
});
});
})(
jQuery
);
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