margin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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;