From c09baca6fde431e810fd01968b17a830dce6af01 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Fri, 10 Jun 2016 16:52:49 -0400 Subject: [PATCH] Make sure padding and margin can accept 0 to mean 0px. Resolves issue #244 --- lib/patch/jsdom.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/patch/jsdom.js b/lib/patch/jsdom.js index add83bd7..e88d8b9a 100644 --- a/lib/patch/jsdom.js +++ b/lib/patch/jsdom.js @@ -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) { @@ -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) { @@ -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") { @@ -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") { @@ -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(); }