aboutsummaryrefslogtreecommitdiffstats
path: root/src/css
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-09-10 19:24:26 -0500
committerTimmy Willison <timmywillisn@gmail.com>2013-09-10 20:08:54 -0500
commit5bd074dd46afed1a66adaa01621a2fe7397d7ab5 (patch)
tree3fd9c1a37ed87204ea2d632709d3f0cc515e68d6 /src/css
parentf7111fb0e521b063250a09dd116d970a3d6556fd (diff)
downloadjquery-5bd074dd46afed1a66adaa01621a2fe7397d7ab5.tar.gz
jquery-5bd074dd46afed1a66adaa01621a2fe7397d7ab5.zip
Remove offset dependency from css. Move curCSS and getStyles to their own module.
Diffstat (limited to 'src/css')
-rw-r--r--src/css/curCSS.js110
-rw-r--r--src/css/var/getStyles.js5
-rw-r--r--src/css/var/rmargin.js3
-rw-r--r--src/css/var/rnumnonpx.js5
4 files changed, 123 insertions, 0 deletions
diff --git a/src/css/curCSS.js b/src/css/curCSS.js
new file mode 100644
index 000000000..9b010f56b
--- /dev/null
+++ b/src/css/curCSS.js
@@ -0,0 +1,110 @@
+define([
+ "exports",
+ "../core",
+ "./var/rnumnonpx",
+ "./var/rmargin",
+ "../css", // Circular, but needs jQuery.style
+ "../selector" // contains
+], function( exports, jQuery, rnumnonpx, rmargin ) {
+
+var getStyles, curCSS,
+ rposition = /^(top|right|bottom|left)$/;
+
+if ( window.getComputedStyle ) {
+ getStyles = function( elem ) {
+ return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+ };
+
+ curCSS = function( elem, name, computed ) {
+ var width, minWidth, maxWidth, ret,
+ style = elem.style;
+
+ computed = computed || getStyles( elem ),
+
+ // getPropertyValue is only needed for .css('filter') in IE9, see #12537
+ ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
+
+ if ( computed ) {
+
+ if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
+ ret = jQuery.style( elem, name );
+ }
+
+ // A tribute to the "awesome hack by Dean Edwards"
+ // Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right
+ // Safari 5.1.7 (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;
+ };
+} else if ( document.documentElement.currentStyle ) {
+ getStyles = function( elem ) {
+ return elem.currentStyle;
+ };
+
+ curCSS = function( elem, name, computed ) {
+ var left, rs, rsLeft, ret,
+ style = elem.style;
+
+ computed = computed || getStyles( elem );
+ ret = computed ? computed[ name ] : undefined;
+
+ // Avoid setting ret to empty string here
+ // so we don't default to auto
+ if ( ret == null && style && style[ name ] ) {
+ ret = style[ name ];
+ }
+
+ // From the awesome hack by Dean Edwards
+ // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
+
+ // If we're not dealing with a regular pixel number
+ // but a number that has a weird ending, we need to convert it to pixels
+ // but not position css attributes, as those are proportional to the parent element instead
+ // and we can't measure the parent instead because it might trigger a "stacking dolls" problem
+ if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
+
+ // Remember the original values
+ left = style.left;
+ rs = elem.runtimeStyle;
+ rsLeft = rs && rs.left;
+
+ // Put in the new values to get a computed value out
+ if ( rsLeft ) {
+ rs.left = elem.currentStyle.left;
+ }
+ style.left = name === "fontSize" ? "1em" : ret;
+ ret = style.pixelLeft + "px";
+
+ // Revert the changed values
+ style.left = left;
+ if ( rsLeft ) {
+ rs.left = rsLeft;
+ }
+ }
+
+ return ret === "" ? "auto" : ret;
+ };
+}
+
+exports.getStyles = getStyles;
+exports.curCSS = curCSS;
+
+});
diff --git a/src/css/var/getStyles.js b/src/css/var/getStyles.js
new file mode 100644
index 000000000..bcbd22017
--- /dev/null
+++ b/src/css/var/getStyles.js
@@ -0,0 +1,5 @@
+define(function() {
+ return function( elem ) {
+ return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+ };
+}); \ No newline at end of file
diff --git a/src/css/var/rmargin.js b/src/css/var/rmargin.js
new file mode 100644
index 000000000..7597cd311
--- /dev/null
+++ b/src/css/var/rmargin.js
@@ -0,0 +1,3 @@
+define(function() {
+ return (/^margin/);
+}); \ No newline at end of file
diff --git a/src/css/var/rnumnonpx.js b/src/css/var/rnumnonpx.js
new file mode 100644
index 000000000..ec4fd615c
--- /dev/null
+++ b/src/css/var/rnumnonpx.js
@@ -0,0 +1,5 @@
+define([
+ "../../var/pnum"
+], function( pnum ) {
+ return new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
+}); \ No newline at end of file