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
b920f0ae
Commit
b920f0ae
authored
Sep 05, 2010
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Broke more of the property-specific CSS logic out of the jQuery.css() function.
parent
920099b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
30 deletions
+34
-30
css.js
src/css.js
+34
-30
No files found.
src/css.js
View file @
b920f0ae
// exclude the following css properties to add px
var
ralpha
=
/alpha
\([^
)
]
*
\)
/
,
var
rexclude
=
/z-
?
index|font-
?
weight|opacity|zoom|line-
?
height/i
,
ralpha
=
/alpha
\([^
)
]
*
\)
/
,
ropacity
=
/opacity=
([^
)
]
*
)
/
,
ropacity
=
/opacity=
([^
)
]
*
)
/
,
rfloat
=
/float/i
,
rdashAlpha
=
/-
([
a-z
])
/ig
,
rdashAlpha
=
/-
([
a-z
])
/ig
,
rupper
=
/
([
A-Z
])
/g
,
rupper
=
/
([
A-Z
])
/g
,
rnumpx
=
/^-
?\d
+
(?:
px
)?
$/i
,
rnumpx
=
/^-
?\d
+
(?:
px
)?
$/i
,
rnum
=
/^-
?\d
/
,
rnum
=
/^-
?\d
/
,
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssShow
=
{
position
:
"absolute"
,
visibility
:
"hidden"
,
display
:
"block"
},
cssWidth
=
[
"Left"
,
"Right"
],
cssWidth
=
[
"Left"
,
"Right"
],
cssHeight
=
[
"Top"
,
"Bottom"
],
cssHeight
=
[
"Top"
,
"Bottom"
],
curCSS
,
curCSS
,
// cache check for defaultView.getComputedStyle
// cache check for defaultView.getComputedStyle
getComputedStyle
=
document
.
defaultView
&&
document
.
defaultView
.
getComputedStyle
,
getComputedStyle
=
document
.
defaultView
&&
document
.
defaultView
.
getComputedStyle
,
// normalize float css property
styleFloat
=
jQuery
.
support
.
cssFloat
?
"cssFloat"
:
"styleFloat"
,
fcamelCase
=
function
(
all
,
letter
)
{
fcamelCase
=
function
(
all
,
letter
)
{
return
letter
.
toUpperCase
();
return
letter
.
toUpperCase
();
};
};
...
@@ -28,7 +24,29 @@ jQuery.fn.css = function( name, value ) {
...
@@ -28,7 +24,29 @@ jQuery.fn.css = function( name, value ) {
};
};
jQuery
.
extend
({
jQuery
.
extend
({
cssHooks
:
{},
cssHooks
:
{
opacity
:
{
get
:
function
(
elem
)
{
// We should always get a number back from opacity
var
ret
=
curCSS
(
elem
,
"opacity"
,
"opacity"
);
return
ret
===
""
?
"1"
:
ret
;
}
}
},
// exclude the following css properties to add px
cssNumber
:
{
"zIndex"
:
true
,
"fontWeight"
:
true
,
"opacity"
:
true
,
"zoom"
:
true
,
"lineHeight"
:
true
},
cssProps
:
{
// normalize float css property
"float"
:
jQuery
.
support
.
cssFloat
?
"cssFloat"
:
"styleFloat"
},
css
:
function
(
elem
,
name
,
value
,
force
,
extra
)
{
css
:
function
(
elem
,
name
,
value
,
force
,
extra
)
{
// don't set styles on text and comment nodes
// don't set styles on text and comment nodes
...
@@ -36,17 +54,13 @@ jQuery.extend({
...
@@ -36,17 +54,13 @@ jQuery.extend({
return
undefined
;
return
undefined
;
}
}
// Make sure we're using the right name for getting the float value
var
ret
,
origName
=
name
.
replace
(
rdashAlpha
,
fcamelCase
),
if
(
rfloat
.
test
(
name
)
)
{
style
=
elem
.
style
||
{},
hooks
=
jQuery
.
cssHooks
[
origName
]
||
{};
name
=
styleFloat
;
}
name
=
name
.
replace
(
rdashAlpha
,
fcamelCase
);
var
ret
,
style
=
elem
.
style
||
{},
hooks
=
jQuery
.
cssHooks
[
name
]
||
{}
;
name
=
jQuery
.
cssProps
[
origName
]
||
origName
;
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
if
(
typeof
value
===
"number"
&&
!
rexclude
.
test
(
name
)
)
{
if
(
typeof
value
===
"number"
&&
!
jQuery
.
cssNumber
[
origName
]
)
{
value
+=
"px"
;
value
+=
"px"
;
}
}
...
@@ -63,7 +77,7 @@ jQuery.extend({
...
@@ -63,7 +77,7 @@ jQuery.extend({
ret
=
style
[
name
];
ret
=
style
[
name
];
}
else
if
(
curCSS
)
{
}
else
if
(
curCSS
)
{
ret
=
curCSS
(
elem
,
name
);
ret
=
curCSS
(
elem
,
name
,
origName
);
}
}
return
ret
;
return
ret
;
...
@@ -104,7 +118,7 @@ jQuery.each(["height", "width"], function( i, name ) {
...
@@ -104,7 +118,7 @@ jQuery.each(["height", "width"], function( i, name ) {
set
:
function
(
elem
,
value
)
{
set
:
function
(
elem
,
value
)
{
// ignore negative width and height values #1599
// ignore negative width and height values #1599
elem
.
style
[
name
]
=
Math
.
max
(
parseFloat
(
value
),
0
);
elem
.
style
[
name
]
=
Math
.
max
(
parseFloat
(
value
),
0
)
+
"px"
;
}
}
};
};
});
});
...
@@ -140,29 +154,19 @@ if ( !jQuery.support.opacity ) {
...
@@ -140,29 +154,19 @@ if ( !jQuery.support.opacity ) {
}
}
if
(
getComputedStyle
)
{
if
(
getComputedStyle
)
{
curCSS
=
function
(
elem
,
name
)
{
curCSS
=
function
(
elem
,
n
ewName
,
n
ame
)
{
var
ret
,
defaultView
,
computedStyle
;
var
ret
,
defaultView
,
computedStyle
;
// Only "float" is needed here
if
(
rfloat
.
test
(
name
)
)
{
name
=
"float"
;
}
name
=
name
.
replace
(
rupper
,
"-$1"
).
toLowerCase
();
name
=
name
.
replace
(
rupper
,
"-$1"
).
toLowerCase
();
if
(
!
(
defaultView
=
elem
.
ownerDocument
.
defaultView
)
)
{
if
(
!
(
defaultView
=
elem
.
ownerDocument
.
defaultView
)
)
{
return
null
;
return
undefined
;
}
}
if
(
(
computedStyle
=
defaultView
.
getComputedStyle
(
elem
,
null
))
)
{
if
(
(
computedStyle
=
defaultView
.
getComputedStyle
(
elem
,
null
))
)
{
ret
=
computedStyle
.
getPropertyValue
(
name
);
ret
=
computedStyle
.
getPropertyValue
(
name
);
}
}
// We should always get a number back from opacity
if
(
name
===
"opacity"
&&
ret
===
""
)
{
ret
=
"1"
;
}
return
ret
;
return
ret
;
};
};
...
...
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