Comparing version 0.2.31 to 0.2.34
@@ -588,27 +588,68 @@ /********************************************************************* | ||
parts = parts.map(function (part) { | ||
parts = parts.map(function (part) { | ||
return parser(part); | ||
}); | ||
this._setProperty(property_before + property_after, parts.join(' ')); | ||
if (parts.length === 1) { | ||
if (parts.length === 1) { | ||
parts[1] = parts[0]; | ||
} | ||
if (parts.length === 2) { | ||
if (parts.length === 2) { | ||
parts[2] = parts[0]; | ||
} | ||
if (parts.length === 3) { | ||
if (parts.length === 3) { | ||
parts[3] = parts[1]; | ||
} | ||
for (var i = 0; i < 4; i++) { | ||
var property = property_before + "-" + part_names[i] + property_after; | ||
this.removeProperty(property); | ||
if (parts[i] !== '') { | ||
for (var i = 0; i < 4; i++) { | ||
var property = property_before + "-" + part_names[i] + property_after; | ||
this.removeProperty(property); | ||
if (parts[i] !== '') { | ||
this._values[property] = parts[i]; | ||
} | ||
} | ||
return v; | ||
} | ||
return v; | ||
}; | ||
}; | ||
// | ||
// Companion to implicitSetter, but for the individual parts. | ||
// This sets the individual value, and checks to see if all four | ||
// sub-parts are set. If so, it sets the shorthand version and removes | ||
// the individual parts from the cssText. | ||
// | ||
exports.subImplicitSetter = function (prefix, part, isValid, parser) { | ||
var property = prefix + '-' + part; | ||
var subparts = [prefix+"-top", prefix+"-right", prefix+"-bottom", prefix+"-left"]; | ||
return function (v) { | ||
if (typeof v === 'number') { | ||
v = v.toString(); | ||
} | ||
if (typeof v !== 'string') { | ||
return undefined; | ||
} | ||
if (!isValid(v)) { | ||
return undefined; | ||
} | ||
v = parser(v); | ||
this._setProperty(property,v); | ||
var parts = []; | ||
for (var i = 0; i < 4; i++) { | ||
if (this._values[subparts[i]] == null || this._values[subparts[i]] === '') { | ||
break; | ||
} | ||
parts.push(this._values[subparts[i]]); | ||
} | ||
if (parts.length === 4) { | ||
for (i = 0; i < 4; i++) { | ||
this.removeProperty(subparts[i]); | ||
this._values[subparts[i]] = parts[i]; | ||
} | ||
this._setProperty(prefix,parts.join(" ")); | ||
} | ||
return v; | ||
}; | ||
}; | ||
var camel_to_dashed = /[A-Z]/g; | ||
@@ -615,0 +656,0 @@ /*jslint regexp: true*/ |
@@ -11,3 +11,3 @@ 'use strict'; | ||
var type = parsers.valueType(v); | ||
return type === TYPES.LENGTH || type === TYPES.PERCENT; | ||
return type === TYPES.LENGTH || type === TYPES.PERCENT || (type === TYPES.INTEGER && (v === '0' || v === 0)); | ||
}; | ||
@@ -21,3 +21,3 @@ | ||
return parsers.parseMeasurement(v); | ||
} | ||
}; | ||
@@ -33,6 +33,6 @@ var mySetter = parsers.implicitSetter('margin', '', isValid, parser); | ||
set: function (v) { | ||
if (typeof v === "number") { | ||
if (typeof v === "number") { | ||
v = String(v); | ||
} | ||
if (typeof v !== "string") { | ||
if (typeof v !== "string") { | ||
return; | ||
@@ -60,1 +60,4 @@ } | ||
}; | ||
module.exports.isValid = isValid; | ||
module.exports.parser = parser; |
'use strict'; | ||
var margin = require('./margin.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('margin-bottom', v); | ||
}, | ||
set: parsers.subImplicitSetter('margin', 'bottom', margin.isValid, margin.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('margin-bottom'); |
'use strict'; | ||
var margin = require('./margin.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('margin-left', v); | ||
}, | ||
set: parsers.subImplicitSetter('margin', 'left', margin.isValid, margin.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('margin-left'); |
'use strict'; | ||
var margin = require('./margin.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('margin-right', v); | ||
}, | ||
set: parsers.subImplicitSetter('margin', 'right', margin.isValid, margin.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('margin-right'); |
'use strict'; | ||
var margin = require('./margin.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('margin-top', v); | ||
}, | ||
set: parsers.subImplicitSetter('margin', 'top', margin.isValid, margin.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('margin-top'); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var type = parsers.valueType(v); | ||
return type === TYPES.LENGTH || type === TYPES.PERCENT; | ||
return type === TYPES.LENGTH || type === TYPES.PERCENT || (type === TYPES.INTEGER && (v === '0' || v === 0)); | ||
}; | ||
@@ -14,3 +14,3 @@ | ||
return parsers.parseMeasurement(v); | ||
} | ||
}; | ||
@@ -26,6 +26,6 @@ var mySetter = parsers.implicitSetter('padding', '', isValid, parser); | ||
set: function (v) { | ||
if (typeof v === "number") { | ||
if (typeof v === "number") { | ||
v = String(v); | ||
} | ||
if (typeof v !== "string") { | ||
if (typeof v !== "string") { | ||
return; | ||
@@ -53,1 +53,4 @@ } | ||
}; | ||
module.exports.isValid = isValid; | ||
module.exports.parser = parser; |
'use strict'; | ||
var padding = require('./padding.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('padding-bottom', v); | ||
}, | ||
set: parsers.subImplicitSetter('padding', 'bottom', padding.isValid, padding.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('padding-bottom'); |
'use strict'; | ||
var padding = require('./padding.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('padding-left', v); | ||
}, | ||
set: parsers.subImplicitSetter('padding', 'left', padding.isValid, padding.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('padding-left'); |
'use strict'; | ||
var padding = require('./padding.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('padding-right', v); | ||
}, | ||
set: parsers.subImplicitSetter('padding', 'right', padding.isValid, padding.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('padding-right'); |
'use strict'; | ||
var padding = require('./padding.js'); | ||
var parsers = require('../parsers.js'); | ||
module.exports.definition = { | ||
set: function (v) { | ||
this._setProperty('padding-top', v); | ||
}, | ||
set: parsers.subImplicitSetter('padding', 'top', padding.isValid, padding.parser), | ||
get: function () { | ||
@@ -8,0 +9,0 @@ return this.getPropertyValue('padding-top'); |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["CSS", "CSSStyleDeclaration", "StyleSheet"], | ||
"version": "0.2.31", | ||
"version": "0.2.34", | ||
"homepage": "https://github.com/chad3814/CSSStyleDeclaration", | ||
@@ -8,0 +8,0 @@ "maintainers": [{ |
@@ -291,5 +291,5 @@ "use strict"; | ||
var part = name + parts[i]; | ||
test.ok(V[i] === style[part], part + ' is not "' + V[i] + '": ' + style[part]); | ||
test.equal(V[i],style[part], part + ' is not "' + V[i] + '": "' + style[part] + '"'); | ||
} | ||
test.ok(v === style[name], name + ' is not "' + v + '": ' + style[name]); | ||
test.equal(v,style[name], name + ' is not "' + v + '": "' + style[name] + '"'); | ||
style[name] = ""; | ||
@@ -312,2 +312,22 @@ }; | ||
}, | ||
'Padding and margin shorthands should set main properties': function (test) { | ||
var style = new cssstyle.CSSStyleDeclaration(); | ||
var parts = ["Top","Right","Bottom","Left"]; | ||
var testParts = function (name,v,V) { | ||
var expect; | ||
for (var i = 0; i < 4; i++) { | ||
style[name] = v; | ||
style[name+parts[i]] = V; | ||
expect = v.split(/ /); | ||
expect[i] = V; | ||
expect = expect.join(" "); | ||
test.equal(expect,style[name], name + ' is not "' + expect + '": "' + style[name] + '"'); | ||
} | ||
}; | ||
test.expect(12); | ||
testParts("padding","1px 2px 3px 4px","10px"); | ||
testParts("margin","1px 2px 3px 4px","10px"); | ||
testParts("margin","1px 2px 3px 4px","auto"); | ||
test.done(); | ||
}, | ||
'Setting a value to 0 should return the string value': function (test) { | ||
@@ -355,3 +375,13 @@ var style = new cssstyle.CSSStyleDeclaration(); | ||
test.done(); | ||
}, | ||
'Make sure setting 0 to a padding or margin works': function (test) { | ||
var style = new cssstyle.CSSStyleDeclaration(); | ||
test.expect(2); | ||
style.padding = 0; | ||
test.equal(style.cssText, 'padding: 0px;', 'padding is not 0px'); | ||
style.margin = '1em'; | ||
style.marginTop = '0' | ||
test.equal(style.marginTop, '0px', 'margin-top is not 0px'); | ||
test.done(); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266691
7261