diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2013-09-10 19:24:26 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2013-09-10 19:24:26 -0500 |
commit | 4ded9be72a724a79d764a4fc72ea9450322235a8 (patch) | |
tree | 45d17b78ba8b9f460f6ad09888aea3e594683fbf /src/offset.js | |
parent | 641492b7e198ebb3e4e564f245b54866a47fa060 (diff) | |
download | jquery-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/offset.js')
-rw-r--r-- | src/offset.js | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/src/offset.js b/src/offset.js index b53524b76..2663b4513 100644 --- a/src/offset.js +++ b/src/offset.js @@ -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; }); |