borderSpacing.js 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. var parsers = require('../parsers');
  3. // <length> <length>? | inherit
  4. // if one, it applies to both horizontal and verical spacing
  5. // if two, the first applies to the horizontal and the second applies to vertical spacing
  6. var parse = function parse(v) {
  7. if (v === '' || v === null) {
  8. return undefined;
  9. }
  10. if (v === 0) {
  11. return '0px';
  12. }
  13. if (v.toLowerCase() === 'inherit') {
  14. return v;
  15. }
  16. var parts = v.split(/\s+/);
  17. if (parts.length !== 1 && parts.length !== 2) {
  18. return undefined;
  19. }
  20. parts.forEach(function(part) {
  21. if (parsers.valueType(part) !== parsers.TYPES.LENGTH) {
  22. return undefined;
  23. }
  24. });
  25. return v;
  26. };
  27. module.exports.definition = {
  28. set: function(v) {
  29. this._setProperty('border-spacing', parse(v));
  30. },
  31. get: function() {
  32. return this.getPropertyValue('border-spacing');
  33. },
  34. enumerable: true,
  35. configurable: true,
  36. };