aboutsummaryrefslogtreecommitdiffstats
path: root/src/offset.js
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2013-09-11 02:45:11 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2013-09-11 02:45:11 +0200
commit0b9f0343824526c2b218c313aebeeab3d41d1c96 (patch)
tree1e1f63700f40202c14dec96c00efbdd2e5d1856c /src/offset.js
parent4ded9be72a724a79d764a4fc72ea9450322235a8 (diff)
downloadjquery-0b9f0343824526c2b218c313aebeeab3d41d1c96.tar.gz
jquery-0b9f0343824526c2b218c313aebeeab3d41d1c96.zip
No ticket. Abstract conditional hook definition.
Diffstat (limited to 'src/offset.js')
-rw-r--r--src/offset.js30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/offset.js b/src/offset.js
index 2663b4513..ee46717fd 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -6,6 +6,7 @@ var
access = require( "./core/access" ),
rnumnonpx = require( "./css/var/rnumnonpx" ),
curCSS = require( "./css/curCSS" ),
+ addGetHookIf = require( "./css/addGetHookIf" ),
support = require( "./css/support" ),
docElem = window.document.documentElement;
@@ -186,28 +187,17 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
// 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;
+ addGetHookIf( jQuery.cssHooks[ prop ], support.pixelPosition,
+ function ( elem, computed ) {
+ if ( computed ) {
+ computed = curCSS( elem, prop );
+ // if curCSS returns percentage, fallback to offset
+ return rnumnonpx.test( computed ) ?
+ jQuery( elem ).position()[ prop ] + "px" :
+ computed;
}
-
- 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;