]> source.dussan.org Git - jquery-ui.git/commitdiff
Position: Refactor css parse calls
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 12 Apr 2012 15:10:51 +0000 (17:10 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 12 Apr 2012 15:10:51 +0000 (17:10 +0200)
ui/jquery.ui.position.js

index bdc23eaecd2bc4b031221cb889e245f9e7e0971d..c87e1d105caf0d4ce90a60411175f6fabef9db79 100644 (file)
@@ -56,6 +56,9 @@ $.position = {
                        parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
                        parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
                ];
+       },
+       parseCss: function( element, property ) {
+               return parseInt( $.css( element, property ), 10 ) || 0;
        }
 };
 
@@ -157,12 +160,10 @@ $.fn.position = function( options ) {
                var elem = $( this ),
                        elemWidth = elem.outerWidth(),
                        elemHeight = elem.outerHeight(),
-                       marginLeft = parseInt( $.css( this, "marginLeft" ), 10 ) || 0,
-                       marginTop = parseInt( $.css( this, "marginTop" ), 10 ) || 0,
-                       collisionWidth = elemWidth + marginLeft +
-                               ( parseInt( $.css( this, "marginRight" ), 10 ) || 0 ) + scrollInfo.width,
-                       collisionHeight = elemHeight + marginTop +
-                               ( parseInt( $.css( this, "marginBottom" ), 10 ) || 0 ) + scrollInfo.height,
+                       marginLeft = $.position.parseCss( this, "marginLeft" ),
+                       marginTop = $.position.parseCss( this, "marginTop" ),
+                       collisionWidth = elemWidth + marginLeft + $.position.parseCss( this, "marginRight" ) + scrollInfo.width,
+                       collisionHeight = elemHeight + marginTop + $.position.parseCss( this, "marginBottom" ) + scrollInfo.height,
                        position = $.extend( {}, basePosition ),
                        myOffset = $.position.getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() ),
                        collisionPosition,