Skip to content

Commit f7ee1f6

Browse files
committed
Update document.defaultView.getComputedStyle. Fixes #10373
1 parent ab542c1 commit f7ee1f6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/css.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,17 @@ jQuery.extend({
274274
}
275275
});
276276

277-
if ( document.defaultView && document.defaultView.getComputedStyle ) {
277+
// NOTE: To any future maintainer, we've used both window.getComputedStyle
278+
// and window.getComputedStyle here to produce a better gzip size
279+
if ( window.getComputedStyle ) {
278280
curCSS = function( elem, name ) {
279-
var ret, defaultView, computedStyle, width,
281+
var ret, width,
282+
computed = getComputedStyle( elem, null ),
280283
style = elem.style;
281284

282-
if ( (defaultView = elem.ownerDocument.defaultView) &&
283-
(computedStyle = defaultView.getComputedStyle( elem, null )) ) {
285+
if ( computed ) {
284286

285-
ret = computedStyle[ name ];
287+
ret = computed[ name ];
286288
if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
287289
ret = jQuery.style( elem, name );
288290
}
@@ -293,7 +295,7 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
293295
if ( !jQuery.support.pixelMargin && rmargin.test( name ) && rnumnonpx.test( ret ) ) {
294296
width = style.width;
295297
style.width = ret;
296-
ret = computedStyle.width;
298+
ret = computed.width;
297299
style.width = width;
298300
}
299301
}

src/support.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ jQuery.support = (function() {
210210
div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;";
211211
support.boxSizing = ( div.offsetWidth === 4 );
212212
support.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== 1 );
213+
214+
// NOTE: To any future maintainer, window.getComputedStyle was used here
215+
// instead of getComputedStyle because it gave a better gzip size.
216+
// The difference between window.getComputedStyle and getComputedStyle is
217+
// 7 bytes
213218
if ( window.getComputedStyle ) {
214219
support.pixelMargin = ( window.getComputedStyle( div, null ) || {} ).marginTop !== "1%";
215220
support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";

0 commit comments

Comments
 (0)