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
4fd6e8e7
Commit
4fd6e8e7
authored
Sep 09, 2013
by
Timmy Willison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorder css.js logically
parent
1b3c0c00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
177 additions
and
177 deletions
+177
-177
css.js
src/css.js
+177
-177
No files found.
src/css.js
View file @
4fd6e8e7
...
@@ -12,7 +12,7 @@ define([
...
@@ -12,7 +12,7 @@ define([
// Optional
// Optional
"./offset"
"./offset"
],
function
(
jQuery
,
pnum
,
cssExpand
,
isHidden
,
support
,
defaultDisplay
,
data_priv
)
{
],
function
(
jQuery
,
pnum
,
cssExpand
,
isHidden
,
support
,
defaultDisplay
,
data_priv
)
{
var
curCSS
,
var
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
rdisplayswap
=
/^
(
none|table
(?!
-c
[
ea
])
.+
)
/
,
rdisplayswap
=
/^
(
none|table
(?!
-c
[
ea
])
.+
)
/
,
...
@@ -58,6 +58,138 @@ function getStyles( elem ) {
...
@@ -58,6 +58,138 @@ function getStyles( elem ) {
return
elem
.
ownerDocument
.
defaultView
.
getComputedStyle
(
elem
,
null
);
return
elem
.
ownerDocument
.
defaultView
.
getComputedStyle
(
elem
,
null
);
}
}
function
curCSS
(
elem
,
name
,
_computed
)
{
var
width
,
minWidth
,
maxWidth
,
computed
=
_computed
||
getStyles
(
elem
),
// Support: IE9
// getPropertyValue is only needed for .css('filter') in IE9, see #12537
ret
=
computed
?
computed
.
getPropertyValue
(
name
)
||
computed
[
name
]
:
undefined
,
style
=
elem
.
style
;
if
(
computed
)
{
if
(
ret
===
""
&&
!
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
)
)
{
ret
=
jQuery
.
style
(
elem
,
name
);
}
// Support: iOS < 6
// A tribute to the "awesome hack by Dean Edwards"
// iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
// this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
if
(
rnumnonpx
.
test
(
ret
)
&&
rmargin
.
test
(
name
)
)
{
// Remember the original values
width
=
style
.
width
;
minWidth
=
style
.
minWidth
;
maxWidth
=
style
.
maxWidth
;
// Put in the new values to get a computed value out
style
.
minWidth
=
style
.
maxWidth
=
style
.
width
=
ret
;
ret
=
computed
.
width
;
// Revert the changed values
style
.
width
=
width
;
style
.
minWidth
=
minWidth
;
style
.
maxWidth
=
maxWidth
;
}
}
return
ret
;
}
function
setPositiveNumber
(
elem
,
value
,
subtract
)
{
var
matches
=
rnumsplit
.
exec
(
value
);
return
matches
?
// Guard against undefined "subtract", e.g., when used as in cssHooks
Math
.
max
(
0
,
matches
[
1
]
-
(
subtract
||
0
)
)
+
(
matches
[
2
]
||
"px"
)
:
value
;
}
function
augmentWidthOrHeight
(
elem
,
name
,
extra
,
isBorderBox
,
styles
)
{
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"
)
{
val
+=
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
],
true
,
styles
);
}
if
(
isBorderBox
)
{
// border-box includes padding, so remove it if we want content
if
(
extra
===
"content"
)
{
val
-=
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
],
true
,
styles
);
}
// at this point, extra isn't border nor margin, so remove border
if
(
extra
!==
"margin"
)
{
val
-=
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
,
true
,
styles
);
}
}
else
{
// at this point, extra isn't content, so add padding
val
+=
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
],
true
,
styles
);
// at this point, extra isn't content nor padding, so add border
if
(
extra
!==
"padding"
)
{
val
+=
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
,
true
,
styles
);
}
}
}
return
val
;
}
function
getWidthOrHeight
(
elem
,
name
,
extra
)
{
// Start with offset property, which is equivalent to the border-box value
var
valueIsBorderBox
=
true
,
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
styles
=
getStyles
(
elem
),
isBorderBox
=
jQuery
.
css
(
elem
,
"boxSizing"
,
false
,
styles
)
===
"border-box"
;
// some non-html elements return undefined for offsetWidth, so check for null/undefined
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
if
(
val
<=
0
||
val
==
null
)
{
// Fall back to computed then uncomputed css if necessary
val
=
curCSS
(
elem
,
name
,
styles
);
if
(
val
<
0
||
val
==
null
)
{
val
=
elem
.
style
[
name
];
}
// Computed unit is not pixels. Stop here and return.
if
(
rnumnonpx
.
test
(
val
)
)
{
return
val
;
}
// we need the check for style in case a browser which returns unreliable values
// for getComputedStyle silently falls back to the reliable elem.style
valueIsBorderBox
=
isBorderBox
&&
(
support
.
boxSizingReliable
()
||
val
===
elem
.
style
[
name
]
);
// Normalize "", auto, and prepare for extra
val
=
parseFloat
(
val
)
||
0
;
}
// use the active box-sizing model to add/subtract irrelevant styles
return
(
val
+
augmentWidthOrHeight
(
elem
,
name
,
extra
||
(
isBorderBox
?
"border"
:
"content"
),
valueIsBorderBox
,
styles
)
)
+
"px"
;
}
function
showHide
(
elements
,
show
)
{
function
showHide
(
elements
,
show
)
{
var
display
,
elem
,
hidden
,
var
display
,
elem
,
hidden
,
values
=
[],
values
=
[],
...
@@ -112,50 +244,6 @@ function showHide( elements, show ) {
...
@@ -112,50 +244,6 @@ function showHide( elements, show ) {
return
elements
;
return
elements
;
}
}
jQuery
.
fn
.
extend
({
css
:
function
(
name
,
value
)
{
return
jQuery
.
access
(
this
,
function
(
elem
,
name
,
value
)
{
var
styles
,
len
,
map
=
{},
i
=
0
;
if
(
jQuery
.
isArray
(
name
)
)
{
styles
=
getStyles
(
elem
);
len
=
name
.
length
;
for
(
;
i
<
len
;
i
++
)
{
map
[
name
[
i
]
]
=
jQuery
.
css
(
elem
,
name
[
i
],
false
,
styles
);
}
return
map
;
}
return
value
!==
undefined
?
jQuery
.
style
(
elem
,
name
,
value
)
:
jQuery
.
css
(
elem
,
name
);
},
name
,
value
,
arguments
.
length
>
1
);
},
show
:
function
()
{
return
showHide
(
this
,
true
);
},
hide
:
function
()
{
return
showHide
(
this
);
},
toggle
:
function
(
state
)
{
if
(
typeof
state
===
"boolean"
)
{
return
state
?
this
.
show
()
:
this
.
hide
();
}
return
this
.
each
(
function
()
{
if
(
isHidden
(
this
)
)
{
jQuery
(
this
).
show
();
}
else
{
jQuery
(
this
).
hide
();
}
});
}
});
jQuery
.
extend
({
jQuery
.
extend
({
// Add in style property hooks for overriding the default
// Add in style property hooks for overriding the default
// behavior of getting and setting a style property
// behavior of getting and setting a style property
...
@@ -288,138 +376,6 @@ jQuery.extend({
...
@@ -288,138 +376,6 @@ jQuery.extend({
}
}
});
});
curCSS
=
function
(
elem
,
name
,
_computed
)
{
var
width
,
minWidth
,
maxWidth
,
computed
=
_computed
||
getStyles
(
elem
),
// Support: IE9
// getPropertyValue is only needed for .css('filter') in IE9, see #12537
ret
=
computed
?
computed
.
getPropertyValue
(
name
)
||
computed
[
name
]
:
undefined
,
style
=
elem
.
style
;
if
(
computed
)
{
if
(
ret
===
""
&&
!
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
)
)
{
ret
=
jQuery
.
style
(
elem
,
name
);
}
// Support: iOS < 6
// A tribute to the "awesome hack by Dean Edwards"
// iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
// this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
if
(
rnumnonpx
.
test
(
ret
)
&&
rmargin
.
test
(
name
)
)
{
// Remember the original values
width
=
style
.
width
;
minWidth
=
style
.
minWidth
;
maxWidth
=
style
.
maxWidth
;
// Put in the new values to get a computed value out
style
.
minWidth
=
style
.
maxWidth
=
style
.
width
=
ret
;
ret
=
computed
.
width
;
// Revert the changed values
style
.
width
=
width
;
style
.
minWidth
=
minWidth
;
style
.
maxWidth
=
maxWidth
;
}
}
return
ret
;
};
function
setPositiveNumber
(
elem
,
value
,
subtract
)
{
var
matches
=
rnumsplit
.
exec
(
value
);
return
matches
?
// Guard against undefined "subtract", e.g., when used as in cssHooks
Math
.
max
(
0
,
matches
[
1
]
-
(
subtract
||
0
)
)
+
(
matches
[
2
]
||
"px"
)
:
value
;
}
function
augmentWidthOrHeight
(
elem
,
name
,
extra
,
isBorderBox
,
styles
)
{
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"
)
{
val
+=
jQuery
.
css
(
elem
,
extra
+
cssExpand
[
i
],
true
,
styles
);
}
if
(
isBorderBox
)
{
// border-box includes padding, so remove it if we want content
if
(
extra
===
"content"
)
{
val
-=
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
],
true
,
styles
);
}
// at this point, extra isn't border nor margin, so remove border
if
(
extra
!==
"margin"
)
{
val
-=
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
,
true
,
styles
);
}
}
else
{
// at this point, extra isn't content, so add padding
val
+=
jQuery
.
css
(
elem
,
"padding"
+
cssExpand
[
i
],
true
,
styles
);
// at this point, extra isn't content nor padding, so add border
if
(
extra
!==
"padding"
)
{
val
+=
jQuery
.
css
(
elem
,
"border"
+
cssExpand
[
i
]
+
"Width"
,
true
,
styles
);
}
}
}
return
val
;
}
function
getWidthOrHeight
(
elem
,
name
,
extra
)
{
// Start with offset property, which is equivalent to the border-box value
var
valueIsBorderBox
=
true
,
val
=
name
===
"width"
?
elem
.
offsetWidth
:
elem
.
offsetHeight
,
styles
=
getStyles
(
elem
),
isBorderBox
=
jQuery
.
css
(
elem
,
"boxSizing"
,
false
,
styles
)
===
"border-box"
;
// some non-html elements return undefined for offsetWidth, so check for null/undefined
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
if
(
val
<=
0
||
val
==
null
)
{
// Fall back to computed then uncomputed css if necessary
val
=
curCSS
(
elem
,
name
,
styles
);
if
(
val
<
0
||
val
==
null
)
{
val
=
elem
.
style
[
name
];
}
// Computed unit is not pixels. Stop here and return.
if
(
rnumnonpx
.
test
(
val
)
)
{
return
val
;
}
// we need the check for style in case a browser which returns unreliable values
// for getComputedStyle silently falls back to the reliable elem.style
valueIsBorderBox
=
isBorderBox
&&
(
support
.
boxSizingReliable
()
||
val
===
elem
.
style
[
name
]
);
// Normalize "", auto, and prepare for extra
val
=
parseFloat
(
val
)
||
0
;
}
// use the active box-sizing model to add/subtract irrelevant styles
return
(
val
+
augmentWidthOrHeight
(
elem
,
name
,
extra
||
(
isBorderBox
?
"border"
:
"content"
),
valueIsBorderBox
,
styles
)
)
+
"px"
;
}
jQuery
.
each
([
"height"
,
"width"
],
function
(
i
,
name
)
{
jQuery
.
each
([
"height"
,
"width"
],
function
(
i
,
name
)
{
jQuery
.
cssHooks
[
name
]
=
{
jQuery
.
cssHooks
[
name
]
=
{
get
:
function
(
elem
,
computed
,
extra
)
{
get
:
function
(
elem
,
computed
,
extra
)
{
...
@@ -529,5 +485,49 @@ jQuery.each({
...
@@ -529,5 +485,49 @@ jQuery.each({
}
}
});
});
jQuery
.
fn
.
extend
({
css
:
function
(
name
,
value
)
{
return
jQuery
.
access
(
this
,
function
(
elem
,
name
,
value
)
{
var
styles
,
len
,
map
=
{},
i
=
0
;
if
(
jQuery
.
isArray
(
name
)
)
{
styles
=
getStyles
(
elem
);
len
=
name
.
length
;
for
(
;
i
<
len
;
i
++
)
{
map
[
name
[
i
]
]
=
jQuery
.
css
(
elem
,
name
[
i
],
false
,
styles
);
}
return
map
;
}
return
value
!==
undefined
?
jQuery
.
style
(
elem
,
name
,
value
)
:
jQuery
.
css
(
elem
,
name
);
},
name
,
value
,
arguments
.
length
>
1
);
},
show
:
function
()
{
return
showHide
(
this
,
true
);
},
hide
:
function
()
{
return
showHide
(
this
);
},
toggle
:
function
(
state
)
{
if
(
typeof
state
===
"boolean"
)
{
return
state
?
this
.
show
()
:
this
.
hide
();
}
return
this
.
each
(
function
()
{
if
(
isHidden
(
this
)
)
{
jQuery
(
this
).
show
();
}
else
{
jQuery
(
this
).
hide
();
}
});
}
});
return
jQuery
;
return
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