Skip to content

Commit e50cfbc

Browse files
dpvcpkra
authored andcommitted
Make sure padding and margin can accept 0 to mean 0px. Resolves issue #244
1 parent 728ccab commit e50cfbc

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

lib/patch/jsdom.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var PADDING = (function () {
4949

5050
var isValid = function (v) {
5151
var type = parsers.valueType(v);
52-
return type === TYPES.LENGTH || type === TYPES.PERCENT;
52+
return type === TYPES.LENGTH || type === TYPES.PERCENT || type === TYPES.INTEGER;
5353
};
5454

5555
var parser = function (v) {
@@ -101,7 +101,7 @@ var MARGIN = (function () {
101101
var isValid = function (v) {
102102
if (v.toLowerCase() === "auto") return true;
103103
var type = parsers.valueType(v);
104-
return type === TYPES.LENGTH || type === TYPES.PERCENT;
104+
return type === TYPES.LENGTH || type === TYPES.PERCENT || type === TYPES.INTEGER;
105105
};
106106

107107
var parser = function (v) {
@@ -311,9 +311,14 @@ exports.patch = function (jsdom) {
311311
nodeName: {get: function() {return this.name}}
312312
});
313313
}
314+
314315
//
315316
// Fix CSSStyleDeclaration properties that are broken (padding, margin, width)
316317
//
318+
319+
//
320+
// Check if padding resets paddingTop
321+
//
317322
div.style.paddingTop = "10px";
318323
div.style.padding = "1px";
319324
if (div.style.paddingTop !== "1px") {
@@ -323,6 +328,21 @@ exports.patch = function (jsdom) {
323328
margin: MARGIN.definition
324329
});
325330
}
331+
//
332+
// Check if pixels without "px" are OK
333+
//
334+
div.style.padding = "";
335+
div.style.padding = "1px 2 3px 4";
336+
if (div.style.padding !== "1px 2 3px 4") {
337+
var core = require("jsdom/lib/jsdom/level1/core");
338+
Object.defineProperties(core.CSSStyleDeclaration.prototype,{
339+
padding: PADDING.definition,
340+
margin: MARGIN.definition
341+
});
342+
}
343+
//
344+
// Check if paddingTop sets padding
345+
//
326346
div.style.padding = "1px 2px 3px 4px";
327347
div.style.paddingTop = "10px";
328348
if (div.style.padding !== "10px 2px 3px 4px") {
@@ -378,11 +398,17 @@ exports.patch = function (jsdom) {
378398
}
379399
});
380400
}
401+
//
402+
// Check if width can be "auto"
403+
//
381404
div.style.width = "auto";
382405
if (div.style.width !== "auto") {
383406
var core = require("jsdom/lib/jsdom/level1/core");
384407
Object.defineProperties(core.CSSStyleDeclaration.prototype,{width: WIDTH});
385408
}
409+
//
410+
// Check if units of ex are allowed
411+
//
386412
div.style.marginTop = "3ex";
387413
if (div.style.marginTop !== "3ex") FixValueType();
388414
}

0 commit comments

Comments
 (0)