[Pkg-javascript-commits] [node-cssstyle] 17/39: good basis for implicit and shorthand properties. background and border ones done

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Sep 20 20:22:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository node-cssstyle.

commit 6677caee2de2699ce948059bcb2c8f56c3a066ca
Author: Chad Walker <chad at chad-cat-lore-eddie.com>
Date:   Sat Feb 9 20:30:24 2013 -0800

    good basis for implicit and shorthand properties. background and border ones done
---
 lib/parsers.js                      | 142 +++++++++++++++++++++++++++++++++++-
 lib/properties/background.js        |  61 +++-------------
 lib/properties/border.js            |  22 ++++--
 lib/properties/borderBottom.js      |  19 +++++
 lib/properties/borderBottomColor.js |   6 +-
 lib/properties/borderBottomStyle.js |   6 +-
 lib/properties/borderBottomWidth.js |   6 +-
 lib/properties/borderCollapse.js    |  15 +++-
 lib/properties/borderColor.js       |  11 ++-
 lib/properties/borderLeft.js        |  19 +++++
 lib/properties/borderLeftColor.js   |   6 +-
 lib/properties/borderLeftStyle.js   |   6 +-
 lib/properties/borderLeftWidth.js   |   6 +-
 lib/properties/borderRight.js       |  19 +++++
 lib/properties/borderRightColor.js  |   6 +-
 lib/properties/borderRightStyle.js  |   6 +-
 lib/properties/borderRightWidth.js  |   6 +-
 lib/properties/borderSpacing.js     |  29 +++++++-
 lib/properties/borderStyle.js       |  13 +++-
 lib/properties/borderTop.js         |  19 +++++
 lib/properties/borderTopColor.js    |   6 +-
 lib/properties/borderTopStyle.js    |   6 +-
 lib/properties/borderTopWidth.js    |   6 +-
 lib/properties/borderWidth.js       |  15 +++-
 24 files changed, 371 insertions(+), 85 deletions(-)

diff --git a/lib/parsers.js b/lib/parsers.js
index 97cfc94..3707270 100644
--- a/lib/parsers.js
+++ b/lib/parsers.js
@@ -321,4 +321,144 @@ exports.parseAngle = function parseAngle(val) {
         flt -= 360;
     }
     return flt + 'deg';
-};
\ No newline at end of file
+};
+
+// utility to translate from border-width to borderWidth
+var dashedToCamelCase = function (dashed) {
+    var i;
+    var camel = '';
+    var nextCap = false;
+    for (i = 0; i < dashed.length; i++) {
+        if (dashed[i] !== '-') {
+            camel += nextCap ? dashed[i].toUpperCase() : dashed[i];
+            nextCap = false;
+        } else {
+            nextCap = true;
+        }
+    }
+    return camel;
+};
+
+/*
+ * this either returns undefined meaning that it isn't valid
+ * or returns an object where the keys are dashed short
+ * hand properties and the values are the values to set
+ * on them
+ */
+exports.shorthandParser = function parse(v, shorthand_for) {
+    if (v.toLowerCase() === 'inherit') {
+        return {};
+    }
+    var parts = v.split(/\s+/);
+    var valid = true;
+    var obj = {};
+    parts.forEach(function (part) {
+        var part_valid = false;
+        Object.keys(shorthand_for).forEach(function (property) {
+            if (shorthand_for[property].isValid(part)) {
+                part_valid = true;
+                obj[property] = part;
+            }
+        });
+        valid = valid && part_valid;
+    });
+    if (!valid) {
+        return undefined;
+    }
+    return obj;
+};
+
+exports.shorthandSetter = function (property, shorthand_for) {
+    return function (v) {
+        var obj = exports.shorthandParser(v, shorthand_for);
+        if (obj === undefined) {
+            return;
+        }
+        Object.keys(obj).forEach(function (subprop) {
+            // in case subprop is an implicit property, this will clear
+            // *its* subpropertiesX
+            var camel = dashedToCamelCase(subprop);
+            this[camel] = obj[subprop];
+            this.removeProperty(subprop);
+            this._values[subprop] = obj[subprop];
+        }, this);
+        Object.keys(shorthand_for).forEach(function (subprop) {
+            if (!obj.hasOwnProperty(subprop)) {
+                this.removeProperty(subprop);
+                delete this._values[subprop];
+            }
+        }, this);
+        this.setProperty(property, v);
+    };
+};
+
+exports.shorthandGetter = function (property, shorthand_for) {
+    return function () {
+        if (this._values[property] !== undefined) {
+            return this.getPropertyValue(property);
+        }
+        return Object.keys(shorthand_for).map(function (subprop) {
+            return this.getPropertyValue(subprop);
+        }, this).filter(function (value) {
+            return value !== '';
+        }).join(' ');
+    };
+};
+
+// isValid(){1,4} | inherit
+// if one, it applies to all
+// if two, the first applies to the top and bottom, and the second to left and right
+// if three, the first applies to the top, the second to left and right, the third bottom
+// if four, top, right, bottom, left
+exports.implicitSetter = function (property_before, property_after, isValid) {
+    property_after = property_after || '';
+    if (property_after !== '') {
+        property_after = '-' + property_after;
+    }
+    return function (v) {
+        if (v.toLowerCase() === 'inherit') {
+            return this.setProperty(property_before + property_after, v);
+        }
+        var parts = v.split(/\s+/);
+        if (parts.length < 1 || parts.length > 4) {
+            return undefined;
+        }
+
+        if (!parts.every(isValid)) {
+            return undefined;
+        }
+
+        this.setProperty(property_before + property_after, v);
+
+        this.removeProperty(property_before + '-top' + property_after);
+        this.removeProperty(property_before + '-right' + property_after);
+        this.removeProperty(property_before + '-bottom' + property_after);
+        this.removeProperty(property_before + '-left' + property_after);
+        switch (parts.length) {
+        case 1:
+            this._values[property_before + '-top' + property_after] = parts[0];
+            this._values[property_before + '-right' + property_after] = parts[0];
+            this._values[property_before + '-bottom' + property_after] = parts[0];
+            this._values[property_before + '-left' + property_after] = parts[0];
+            return v;
+        case 2:
+            this._values[property_before + '-top' + property_after] = parts[0];
+            this._values[property_before + '-right' + property_after] = parts[1];
+            this._values[property_before + '-bottom' + property_after] = parts[0];
+            this._values[property_before + '-left' + property_after] = parts[1];
+            return v;
+        case 3:
+            this._values[property_before + '-top' + property_after] = parts[0];
+            this._values[property_before + '-right' + property_after] = parts[1];
+            this._values[property_before + '-bottom' + property_after] = parts[2];
+            this._values[property_before + '-left' + property_after] = parts[1];
+            return v;
+        case 4:
+            this._values[property_before + '-top' + property_after] = parts[0];
+            this._values[property_before + '-right' + property_after] = parts[1];
+            this._values[property_before + '-bottom' + property_after] = parts[2];
+            this._values[property_before + '-left' + property_after] = parts[3];
+            return v;
+        }
+    };
+};
diff --git a/lib/properties/background.js b/lib/properties/background.js
index 4961825..fe5592a 100644
--- a/lib/properties/background.js
+++ b/lib/properties/background.js
@@ -1,62 +1,23 @@
 'use strict';
 
-var parsers = require('../parsers');
+var shorthandParser = require('../parsers').shorthandParser;
+var shorthandSetter = require('../parsers').shorthandSetter;
+var shorthandGetter = require('../parsers').shorthandGetter;
 
 var shorthand_for = {
-    backgroundColor: 'background-color',
-    backgroundImage: 'background-image',
-    backgroundRepeat: 'background-repeat',
-    backgroundAttachment: 'background-attachment',
-    backgroundPosition: 'background-position'
-};
-
-/*
- * this either returns undefined meaning that it isn't valid
- * or returns an object where the keys are dashed short
- * hand properties and the values are the values to set
- * on them
- */
-var parse = function parse(v) {
-    if (v.toLowerCase() === 'inherit') {
-        return {};
-    }
-    var parts = v.split(/\s+/);
-    var valid = true;
-    var obj = {};
-    parts.forEach(function (part) {
-        var part_valid = false;
-        Object.keys(shorthand_for).forEach(function (property) {
-            if (require('./' + property).isValid(part)) {
-                part_valid = true;
-                obj[shorthand_for[property]] = part;
-            }
-        });
-        valid = valid && part_valid;
-    });
-    if (!valid) {
-        return undefined;
-    }
-    return obj;
+    'background-color': require('./backgroundColor'),
+    'background-image': require('./backgroundImage'),
+    'background-repeat': require('./backgroundRepeat'),
+    'background-attachment': require('./backgroundAttachment'),
+    'background-position': require('./backgroundPosition')
 };
 
 module.exports.isValid = function isValid(v) {
-    return parse(v) !== undefined;
+    return shorthandParser(v, shorthand_for) !== undefined;
 };
 
 module.exports.definition = {
-    set: function (v) {
-        var parsed = parse(v);
-        if (parsed === undefined) {
-            return;
-        }
-        this.setProperty('background', v);
-        // these don't get set
-        Object.keys(parsed).forEach(function (property) {
-            this._values[property] = parsed[property];
-        }, this);
-    },
-    get: function () {
-        return this.getPropertyValue('background');
-    },
+    set: shorthandSetter('background', shorthand_for),
+    get: shorthandGetter('background', shorthand_for),
     enumerable: true
 };
diff --git a/lib/properties/border.js b/lib/properties/border.js
index 9cce130..6466e9c 100644
--- a/lib/properties/border.js
+++ b/lib/properties/border.js
@@ -1,11 +1,21 @@
 'use strict';
 
+var shorthandParser = require('../parsers').shorthandParser;
+var shorthandSetter = require('../parsers').shorthandSetter;
+var shorthandGetter = require('../parsers').shorthandGetter;
+
+var shorthand_for = {
+    'border-width': require('./borderWidth'),
+    'border-style': require('./borderStyle'),
+    'border-color': require('./borderColor')
+};
+
+var isValid = module.exports.isValid = function isValid(v) {
+    return shorthandParser(v, shorthand_for) !== undefined;
+};
+
 module.exports.definition = {
-    set: function (v) {
-        this.setProperty('border', v);
-    },
-    get: function () {
-        return this.getPropertyValue('border');
-    },
+    set: shorthandSetter('border', shorthand_for),
+    get: shorthandGetter('border', shorthand_for),
     enumerable: true
 };
diff --git a/lib/properties/borderBottom.js b/lib/properties/borderBottom.js
index 2e6bed6..54cff74 100644
--- a/lib/properties/borderBottom.js
+++ b/lib/properties/borderBottom.js
@@ -1,7 +1,26 @@
 'use strict';
 
+var shorthandParser = require('../parsers').shorthandParser;
+
+var shorthand_for = {
+    borderBottomWidth: require('./borderBottomWidth'),
+    borderBottomStyle: require('./borderBottomStyle'),
+    borderBottomColor: require('./borderBottomColor')
+};
+
+var isValid = module.exports.isValid = function isValid(v) {
+    return shorthandParser(v, shorthand_for) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
+        var obj = shorthandParser(v, shorthand_for);
+        if (obj === undefined) {
+            return;
+        }
+        Object.keys(obj).forEach(function (property) {
+            this._values[property] = obj[property];
+        }, this);
         this.setProperty('border-bottom', v);
     },
     get: function () {
diff --git a/lib/properties/borderBottomColor.js b/lib/properties/borderBottomColor.js
index 4a87177..a3ec3f6 100644
--- a/lib/properties/borderBottomColor.js
+++ b/lib/properties/borderBottomColor.js
@@ -1,10 +1,12 @@
 'use strict';
 
-var parseColor = require('../parsers').parseColor;
+var isValid = module.exports.isValid = require('./borderColor').isValid;
 
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-bottom-color', parseColor(v));
+        if (isValid(v)) {
+            this.setProperty('border-bottom-color', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-bottom-color');
diff --git a/lib/properties/borderBottomStyle.js b/lib/properties/borderBottomStyle.js
index 9adf71c..0087fec 100644
--- a/lib/properties/borderBottomStyle.js
+++ b/lib/properties/borderBottomStyle.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderStyle').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-bottom-style', v);
+        if (isValid(v)) {
+            this.setProperty('border-bottom-style', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-bottom-style');
diff --git a/lib/properties/borderBottomWidth.js b/lib/properties/borderBottomWidth.js
index 435f71b..e82443a 100644
--- a/lib/properties/borderBottomWidth.js
+++ b/lib/properties/borderBottomWidth.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderWidth').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-bottom-width', v);
+        if (isValid(v)) {
+            this.setProperty('border-bottom-width', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-bottom-width');
diff --git a/lib/properties/borderCollapse.js b/lib/properties/borderCollapse.js
index 205e174..33af8ba 100644
--- a/lib/properties/borderCollapse.js
+++ b/lib/properties/borderCollapse.js
@@ -1,8 +1,21 @@
 'use strict';
 
+var parsers = require('../parsers');
+
+var parse = function parse(v) {
+    if (parsers.valueType(v) === parsers.TYPES.KEYWORD && (v.toLowerCase() === 'collapse' || v.toLowerCase() === 'separate' || v.toLowerCase() === 'inherit')) {
+        return v;
+    }
+    return undefined;
+};
+
+module.exports.isValid = function isValid(v) {
+    return parse(v) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-collapse', v);
+        this.setProperty('border-collapse', parse(v));
     },
     get: function () {
         return this.getPropertyValue('border-collapse');
diff --git a/lib/properties/borderColor.js b/lib/properties/borderColor.js
index 9fff30c..9448178 100644
--- a/lib/properties/borderColor.js
+++ b/lib/properties/borderColor.js
@@ -1,11 +1,14 @@
 'use strict';
 
-var parseColor = require('../parsers').parseColor;
+var parsers = require('../parsers');
+var implicitSetter = require('../parsers').implicitSetter;
+
+var isValid = module.exports.isValid = function parse(v) {
+    return (v.toLowerCase() === 'transparent' || parsers.valueType(v) === parsers.TYPES.COLOR);
+};
 
 module.exports.definition = {
-    set: function (v) {
-        this.setProperty('border-color', parseColor(v));
-    },
+    set: implicitSetter('border', 'color', isValid),
     get: function () {
         return this.getPropertyValue('border-color');
     },
diff --git a/lib/properties/borderLeft.js b/lib/properties/borderLeft.js
index de79cea..47687db 100644
--- a/lib/properties/borderLeft.js
+++ b/lib/properties/borderLeft.js
@@ -1,7 +1,26 @@
 'use strict';
 
+var shorthandParser = require('../parsers').shorthandParser;
+
+var shorthand_for = {
+    borderLeftWidth: require('./borderLeftWidth'),
+    borderLeftStyle: require('./borderLeftStyle'),
+    borderLeftColor: require('./borderLeftColor')
+};
+
+var isValid = module.exports.isValid = function isValid(v) {
+    return shorthandParser(v, shorthand_for) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
+        var obj = shorthandParser(v, shorthand_for);
+        if (obj === undefined) {
+            return;
+        }
+        Object.keys(obj).forEach(function (property) {
+            this._values[property] = obj[property];
+        }, this);
         this.setProperty('border-left', v);
     },
     get: function () {
diff --git a/lib/properties/borderLeftColor.js b/lib/properties/borderLeftColor.js
index 0ae6014..7002ee9 100644
--- a/lib/properties/borderLeftColor.js
+++ b/lib/properties/borderLeftColor.js
@@ -1,10 +1,12 @@
 'use strict';
 
-var parseColor = require('../parsers').parseColor;
+var isValid = module.exports.isValid = require('./borderColor').isValid;
 
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-left-color', parseColor(v));
+        if (isValid(v)) {
+            this.setProperty('border-left-color', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-left-color');
diff --git a/lib/properties/borderLeftStyle.js b/lib/properties/borderLeftStyle.js
index a6d26b9..a6eb666 100644
--- a/lib/properties/borderLeftStyle.js
+++ b/lib/properties/borderLeftStyle.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderStyle').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-left-style', v);
+        if (isValid(v)) {
+            this.setProperty('border-left-style', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-left-style');
diff --git a/lib/properties/borderLeftWidth.js b/lib/properties/borderLeftWidth.js
index 910f26a..a7027a0 100644
--- a/lib/properties/borderLeftWidth.js
+++ b/lib/properties/borderLeftWidth.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderWidth').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-left-width', v);
+        if (isValid(v)) {
+            this.setProperty('border-left-width', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-left-width');
diff --git a/lib/properties/borderRight.js b/lib/properties/borderRight.js
index 167d7fc..e919035 100644
--- a/lib/properties/borderRight.js
+++ b/lib/properties/borderRight.js
@@ -1,7 +1,26 @@
 'use strict';
 
+var shorthandParser = require('../parsers').shorthandParser;
+
+var shorthand_for = {
+    borderRightWidth: require('./borderRightWidth'),
+    borderRightStyle: require('./borderRightStyle'),
+    borderRightColor: require('./borderRightColor')
+};
+
+var isValid = module.exports.isValid = function isValid(v) {
+    return shorthandParser(v, shorthand_for) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
+        var obj = shorthandParser(v, shorthand_for);
+        if (obj === undefined) {
+            return;
+        }
+        Object.keys(obj).forEach(function (property) {
+            this._values[property] = obj[property];
+        }, this);
         this.setProperty('border-right', v);
     },
     get: function () {
diff --git a/lib/properties/borderRightColor.js b/lib/properties/borderRightColor.js
index e7bdebb..343fee1 100644
--- a/lib/properties/borderRightColor.js
+++ b/lib/properties/borderRightColor.js
@@ -1,10 +1,12 @@
 'use strict';
 
-var parseColor = require('../parsers').parseColor;
+var isValid = module.exports.isValid = require('./borderColor').isValid;
 
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-right-color', parseColor(v));
+        if (isValid(v)) {
+            this.setProperty('border-right-color', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-right-color');
diff --git a/lib/properties/borderRightStyle.js b/lib/properties/borderRightStyle.js
index 2c1f6dc..e417adb 100644
--- a/lib/properties/borderRightStyle.js
+++ b/lib/properties/borderRightStyle.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderStyle').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-right-style', v);
+        if (isValid(v)) {
+            this.setProperty('border-right-style', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-right-style');
diff --git a/lib/properties/borderRightWidth.js b/lib/properties/borderRightWidth.js
index f48a1d6..6fbfe5d 100644
--- a/lib/properties/borderRightWidth.js
+++ b/lib/properties/borderRightWidth.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderWidth').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-right-width', v);
+        if (isValid(v)) {
+            this.setProperty('border-right-width', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-right-width');
diff --git a/lib/properties/borderSpacing.js b/lib/properties/borderSpacing.js
index 292e690..e5e582a 100644
--- a/lib/properties/borderSpacing.js
+++ b/lib/properties/borderSpacing.js
@@ -1,8 +1,35 @@
 'use strict';
 
+var parsers = require('../parsers');
+
+// <length> <length>? | inherit
+// if one, it applies to both horizontal and verical spacing
+// if two, the first applies to the horizontal and the second applies to vertical spacing
+
+var parse = function parse(v) {
+    if (v.toLowerCase() === 'inherit') {
+        return v;
+    }
+    var parts = v.split(/\s+/);
+    if (parts.length !== 1 && parts.length !== 2) {
+        return undefined;
+    }
+    parts.forEach(function (part) {
+        if (parsers.valueType(part) !== parsers.TYPES.LENGTH) {
+            return undefined;
+        }
+    });
+
+    return v;
+};
+
+module.exports.isValid = function isValid(v) {
+    return parse(v) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-spacing', v);
+        this.setProperty('border-spacing', parse(v));
     },
     get: function () {
         return this.getPropertyValue('border-spacing');
diff --git a/lib/properties/borderStyle.js b/lib/properties/borderStyle.js
index b46ef6c..955cdbd 100644
--- a/lib/properties/borderStyle.js
+++ b/lib/properties/borderStyle.js
@@ -1,9 +1,16 @@
 'use strict';
 
+var implicitSetter = require('../parsers').implicitSetter;
+
+// the valid border-styles:
+var styles = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
+
+var isValid = module.exports.isValid = function parse(v) {
+    return styles.indexOf(v) !== -1;
+};
+
 module.exports.definition = {
-    set: function (v) {
-        this.setProperty('border-style', v);
-    },
+    set: implicitSetter('border', 'style', isValid),
     get: function () {
         return this.getPropertyValue('border-style');
     },
diff --git a/lib/properties/borderTop.js b/lib/properties/borderTop.js
index 91fe6d6..2e25d13 100644
--- a/lib/properties/borderTop.js
+++ b/lib/properties/borderTop.js
@@ -1,7 +1,26 @@
 'use strict';
 
+var shorthandParser = require('../parsers').shorthandParser;
+
+var shorthand_for = {
+    borderTopWidth: require('./borderTopWidth'),
+    borderTopStyle: require('./borderTopStyle'),
+    borderTopColor: require('./borderTopColor')
+};
+
+var isValid = module.exports.isValid = function isValid(v) {
+    return shorthandParser(v, shorthand_for) !== undefined;
+};
+
 module.exports.definition = {
     set: function (v) {
+        var obj = shorthandParser(v, shorthand_for);
+        if (obj === undefined) {
+            return;
+        }
+        Object.keys(obj).forEach(function (property) {
+            this._values[property] = obj[property];
+        }, this);
         this.setProperty('border-top', v);
     },
     get: function () {
diff --git a/lib/properties/borderTopColor.js b/lib/properties/borderTopColor.js
index 649d771..0dad0ae 100644
--- a/lib/properties/borderTopColor.js
+++ b/lib/properties/borderTopColor.js
@@ -1,10 +1,12 @@
 'use strict';
 
-var parseColor = require('../parsers').parseColor;
+var isValid = module.exports.isValid = require('./borderColor').isValid;
 
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-top-color', parseColor(v));
+        if (isValid(v)) {
+            this.setProperty('border-top-color', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-top-color');
diff --git a/lib/properties/borderTopStyle.js b/lib/properties/borderTopStyle.js
index f02a363..316145d 100644
--- a/lib/properties/borderTopStyle.js
+++ b/lib/properties/borderTopStyle.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderStyle').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-top-style', v);
+        if (isValid(v)) {
+            this.setProperty('border-top-style', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-top-style');
diff --git a/lib/properties/borderTopWidth.js b/lib/properties/borderTopWidth.js
index e1dfd9e..659f61e 100644
--- a/lib/properties/borderTopWidth.js
+++ b/lib/properties/borderTopWidth.js
@@ -1,8 +1,12 @@
 'use strict';
 
+var isValid = module.exports.isValid = require('./borderWidth').isValid;
+
 module.exports.definition = {
     set: function (v) {
-        this.setProperty('border-top-width', v);
+        if (isValid(v)) {
+            this.setProperty('border-top-width', v);
+        }
     },
     get: function () {
         return this.getPropertyValue('border-top-width');
diff --git a/lib/properties/borderWidth.js b/lib/properties/borderWidth.js
index fade76f..2fbbd75 100644
--- a/lib/properties/borderWidth.js
+++ b/lib/properties/borderWidth.js
@@ -1,9 +1,18 @@
 'use strict';
 
+var parsers = require('../parsers');
+var parsers = require('../parsers');
+var implicitSetter = require('../parsers').implicitSetter;
+
+// the valid border-widths:
+var widths = ['thin', 'medium', 'thick'];
+
+var isValid = module.exports.isValid = function parse(v) {
+    return (widths.indexOf(v.toLowerCase()) !== -1) || parsers.parseLength(v);
+};
+
 module.exports.definition = {
-    set: function (v) {
-        this.setProperty('border-width', v);
-    },
+    set: implicitSetter('border', 'width', isValid),
     get: function () {
         return this.getPropertyValue('border-width');
     },

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cssstyle.git



More information about the Pkg-javascript-commits mailing list