flex.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var shorthandParser = require('../parsers').shorthandParser;
  3. var shorthandSetter = require('../parsers').shorthandSetter;
  4. var shorthandGetter = require('../parsers').shorthandGetter;
  5. var shorthand_for = {
  6. 'flex-grow': require('./flexGrow'),
  7. 'flex-shrink': require('./flexShrink'),
  8. 'flex-basis': require('./flexBasis'),
  9. };
  10. var myShorthandSetter = shorthandSetter('flex', shorthand_for);
  11. module.exports.isValid = function isValid(v) {
  12. return shorthandParser(v, shorthand_for) !== undefined;
  13. };
  14. module.exports.definition = {
  15. set: function(v) {
  16. var normalizedValue = String(v)
  17. .trim()
  18. .toLowerCase();
  19. if (normalizedValue === 'none') {
  20. myShorthandSetter.call(this, '0 0 auto');
  21. return;
  22. }
  23. if (normalizedValue === 'initial') {
  24. myShorthandSetter.call(this, '0 1 auto');
  25. return;
  26. }
  27. if (normalizedValue === 'auto') {
  28. this.removeProperty('flex-grow');
  29. this.removeProperty('flex-shrink');
  30. this.setProperty('flex-basis', normalizedValue);
  31. return;
  32. }
  33. myShorthandSetter.call(this, v);
  34. },
  35. get: shorthandGetter('flex', shorthand_for),
  36. enumerable: true,
  37. configurable: true,
  38. };