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 19:24:26 -0500
commit4ded9be72a724a79d764a4fc72ea9450322235a8 (patch)
tree45d17b78ba8b9f460f6ad09888aea3e594683fbf /src/css
parent641492b7e198ebb3e4e564f245b54866a47fa060 (diff)
downloadjquery-4ded9be72a724a79d764a4fc72ea9450322235a8.tar.gz
jquery-4ded9be72a724a79d764a4fc72ea9450322235a8.zip
Remove offset dependency from css. Move curCSS and getStyles to their own modules. -39 bytes. Close gh-1360.
Diffstat (limited to 'src/css')
-rw-r--r--src/css/curCSS.js52
-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, 65 insertions, 0 deletions
diff --git a/src/css/curCSS.js b/src/css/curCSS.js
new file mode 100644
index 000000000..21cf87112
--- /dev/null
+++ b/src/css/curCSS.js
@@ -0,0 +1,52 @@
+define([
+ "../core",
+ "./var/rnumnonpx",
+ "./var/rmargin",
+ "./var/getStyles",
+ "../css", // Circular, but needs jQuery.style
+ "../selector" // contains
+], function( jQuery, rnumnonpx, rmargin, getStyles ) {
+
+function curCSS( elem, name, computed ) {
+ var width, minWidth, maxWidth, ret,
+ style = elem.style;
+
+ 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;
+
+ 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;
+}
+
+return 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