Skip to content

Commit 8fcbe50

Browse files
committed
Core: Check if jQuery supports inner/outer/Width/Height setters.
(cherry picked from commit 033f83f) Conflicts: ui/jquery.ui.core.js
1 parent b892b72 commit 8fcbe50

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

ui/jquery.ui.core.js

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -131,49 +131,52 @@ $.fn.extend({
131131
}
132132
});
133133

134-
$.each( [ "Width", "Height" ], function( i, name ) {
135-
var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
136-
type = name.toLowerCase(),
137-
orig = {
138-
innerWidth: $.fn.innerWidth,
139-
innerHeight: $.fn.innerHeight,
140-
outerWidth: $.fn.outerWidth,
141-
outerHeight: $.fn.outerHeight
142-
};
143-
144-
function reduce( elem, size, border, margin ) {
145-
$.each( side, function() {
146-
size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
147-
if ( border ) {
148-
size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
149-
}
150-
if ( margin ) {
151-
size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
152-
}
153-
});
154-
return size;
155-
}
134+
// support: jQuery <1.8
135+
if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
136+
$.each( [ "Width", "Height" ], function( i, name ) {
137+
var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
138+
type = name.toLowerCase(),
139+
orig = {
140+
innerWidth: $.fn.innerWidth,
141+
innerHeight: $.fn.innerHeight,
142+
outerWidth: $.fn.outerWidth,
143+
outerHeight: $.fn.outerHeight
144+
};
156145

157-
$.fn[ "inner" + name ] = function( size ) {
158-
if ( size === undefined ) {
159-
return orig[ "inner" + name ].call( this );
146+
function reduce( elem, size, border, margin ) {
147+
$.each( side, function() {
148+
size -= parseFloat( $.curCSS( elem, "padding" + this, true) ) || 0;
149+
if ( border ) {
150+
size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true) ) || 0;
151+
}
152+
if ( margin ) {
153+
size -= parseFloat( $.curCSS( elem, "margin" + this, true) ) || 0;
154+
}
155+
});
156+
return size;
160157
}
161158

162-
return this.each(function() {
163-
$( this ).css( type, reduce( this, size ) + "px" );
164-
});
165-
};
159+
$.fn[ "inner" + name ] = function( size ) {
160+
if ( size === undefined ) {
161+
return orig[ "inner" + name ].call( this );
162+
}
163+
164+
return this.each(function() {
165+
$( this ).css( type, reduce( this, size ) + "px" );
166+
});
167+
};
166168

167-
$.fn[ "outer" + name] = function( size, margin ) {
168-
if ( typeof size !== "number" ) {
169-
return orig[ "outer" + name ].call( this, size );
170-
}
169+
$.fn[ "outer" + name] = function( size, margin ) {
170+
if ( typeof size !== "number" ) {
171+
return orig[ "outer" + name ].call( this, size );
172+
}
171173

172-
return this.each(function() {
173-
$( this).css( type, reduce( this, size, true, margin ) + "px" );
174-
});
175-
};
176-
});
174+
return this.each(function() {
175+
$( this).css( type, reduce( this, size, true, margin ) + "px" );
176+
});
177+
};
178+
});
179+
}
177180

178181
// selectors
179182
function focusable( element, isTabIndexNotNaN ) {

0 commit comments

Comments
 (0)