You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.2 KiB

  1. 'use strict';
  2. var parsers = require('../parsers.js');
  3. var TYPES = parsers.TYPES;
  4. var isValid = function(v) {
  5. if (v.toLowerCase() === 'auto') {
  6. return true;
  7. }
  8. var type = parsers.valueType(v);
  9. return (
  10. type === TYPES.LENGTH ||
  11. type === TYPES.PERCENT ||
  12. (type === TYPES.INTEGER && (v === '0' || v === 0))
  13. );
  14. };
  15. var parser = function(v) {
  16. var V = v.toLowerCase();
  17. if (V === 'auto') {
  18. return V;
  19. }
  20. return parsers.parseMeasurement(v);
  21. };
  22. var mySetter = parsers.implicitSetter('margin', '', isValid, parser);
  23. var myGlobal = parsers.implicitSetter(
  24. 'margin',
  25. '',
  26. function() {
  27. return true;
  28. },
  29. function(v) {
  30. return v;
  31. }
  32. );
  33. module.exports.definition = {
  34. set: function(v) {
  35. if (typeof v === 'number') {
  36. v = String(v);
  37. }
  38. if (typeof v !== 'string') {
  39. return;
  40. }
  41. var V = v.toLowerCase();
  42. switch (V) {
  43. case 'inherit':
  44. case 'initial':
  45. case 'unset':
  46. case '':
  47. myGlobal.call(this, V);
  48. break;
  49. default:
  50. mySetter.call(this, v);
  51. break;
  52. }
  53. },
  54. get: function() {
  55. return this.getPropertyValue('margin');
  56. },
  57. enumerable: true,
  58. configurable: true,
  59. };
  60. module.exports.isValid = isValid;
  61. module.exports.parser = parser;