Skip to content

Make sure padding and margin can accept 0 to mean 0px. #244 #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2016
Merged
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
30 changes: 28 additions & 2 deletions lib/patch/jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var PADDING = (function () {

var isValid = function (v) {
var type = parsers.valueType(v);
return type === TYPES.LENGTH || type === TYPES.PERCENT;
return type === TYPES.LENGTH || type === TYPES.PERCENT || type === TYPES.INTEGER;
};

var parser = function (v) {
Expand Down Expand Up @@ -101,7 +101,7 @@ var MARGIN = (function () {
var isValid = function (v) {
if (v.toLowerCase() === "auto") return true;
var type = parsers.valueType(v);
return type === TYPES.LENGTH || type === TYPES.PERCENT;
return type === TYPES.LENGTH || type === TYPES.PERCENT || type === TYPES.INTEGER;
};

var parser = function (v) {
Expand Down Expand Up @@ -311,9 +311,14 @@ exports.patch = function (jsdom) {
nodeName: {get: function() {return this.name}}
});
}

//
// Fix CSSStyleDeclaration properties that are broken (padding, margin, width)
//

//
// Check if padding resets paddingTop
//
div.style.paddingTop = "10px";
div.style.padding = "1px";
if (div.style.paddingTop !== "1px") {
Expand All @@ -323,6 +328,21 @@ exports.patch = function (jsdom) {
margin: MARGIN.definition
});
}
//
// Check if pixels without "px" are OK
//
div.style.padding = "";
div.style.padding = "1px 2 3px 4";
if (div.style.padding !== "1px 2 3px 4") {
var core = require("jsdom/lib/jsdom/level1/core");
Object.defineProperties(core.CSSStyleDeclaration.prototype,{
padding: PADDING.definition,
margin: MARGIN.definition
});
}
//
// Check if paddingTop sets padding
//
div.style.padding = "1px 2px 3px 4px";
div.style.paddingTop = "10px";
if (div.style.padding !== "10px 2px 3px 4px") {
Expand Down Expand Up @@ -378,11 +398,17 @@ exports.patch = function (jsdom) {
}
});
}
//
// Check if width can be "auto"
//
div.style.width = "auto";
if (div.style.width !== "auto") {
var core = require("jsdom/lib/jsdom/level1/core");
Object.defineProperties(core.CSSStyleDeclaration.prototype,{width: WIDTH});
}
//
// Check if units of ex are allowed
//
div.style.marginTop = "3ex";
if (div.style.marginTop !== "3ex") FixValueType();
}