Remove offset dependency from css. Move curCSS and getStyles to their own modules. -39 bytes. Close gh-1360.

This commit is contained in:
Timmy Willison
2013-09-10 19:24:26 -05:00
parent 641492b7e1
commit 4ded9be72a
6 changed files with 111 additions and 85 deletions

View File

@@ -1,13 +1,17 @@
define([
"./core",
"./var/strundefined",
"./core/access",
"./core/init",
"./css",
"./selector" // contains
], function( jQuery, strundefined, access ) {
define(function( require ) {
var docElem = window.document.documentElement;
var
jQuery = require( "./core" ),
strundefined = require( "./var/strundefined" ),
access = require( "./core/access" ),
rnumnonpx = require( "./css/var/rnumnonpx" ),
curCSS = require( "./css/curCSS" ),
support = require( "./css/support" ),
docElem = window.document.documentElement;
require( "./core/init" );
require( "./css" );
require( "./selector" ); // contains
/**
* Gets a window from an element
@@ -177,5 +181,34 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
};
});
// Add the top/left cssHooks using jQuery.fn.position
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
// getComputedStyle returns percent when specified for top/left/bottom/right
// rather than make the css module depend on the offset module, we just check for it here
jQuery.each( [ "top", "left" ], function( i, prop ) {
jQuery.cssHooks[ prop ] = {
get: function( elem, computed ) {
if ( support.pixelPosition() ) {
// Hook not needed, remove it.
// Since there are no other hooks for prop, remove the whole object.
delete jQuery.cssHooks[ prop ];
return;
}
jQuery.cssHooks[ prop ].get = function ( i, prop ) {
if ( computed ) {
computed = curCSS( elem, prop );
// if curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :
computed;
}
};
return jQuery.cssHooks[ prop ].get( i, prop );
}
};
});
return jQuery;
});