Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(jqLite): .css() retrieves computed style also #8161

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,20 @@ forEach({
if (val === '') val = 'auto';
}

val = val || element.style[name];
var contains = function (a, b){
// jshint bitwise: false
return a.contains ?
a != b && a.contains(b) :
!!(a.compareDocumentPosition(b) & 16);
};

var elementWindow = element.ownerDocument.defaultView || element.ownerDocument.parentWindow;
// if browser supports getComputedStyle and element attached to body
if (isDefined(elementWindow.getComputedStyle) && contains(element.ownerDocument, element)) {
val = val || elementWindow.getComputedStyle(element, null)[name];
} else {
val = val || element.style[name];
}

if (msie <= 8) {
// jquery weirdness :-/
Expand Down
13 changes: 13 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,19 @@ describe('jqLite', function() {
}
});

it('should get computed styles', function() {
if (window.getComputedStyle) { // browser should support of computed styles
a.id = 'elementA';
var jqA = jqLite(a);
jqLite(document).find('body').append(jqA);

var style = document.createElement('style');
style.appendChild(document.createTextNode('#elementA { width: 25px; }'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to ensure that this style gets removed via finally or afterEach

jqLite(document).find('head').append(style);

expect(jqA.css('width')).toBe('25px');
}
});

it('should set a bunch of css properties specified via an object', function() {
if (msie <= 8) {
Expand Down