flex.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function() {
  2. var Declaration, Flex, flexSpec, list,
  3. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  4. hasProp = {}.hasOwnProperty;
  5. flexSpec = require('./flex-spec');
  6. Declaration = require('../declaration');
  7. list = require('postcss/lib/list');
  8. Flex = (function(superClass) {
  9. extend(Flex, superClass);
  10. function Flex() {
  11. return Flex.__super__.constructor.apply(this, arguments);
  12. }
  13. Flex.names = ['flex', 'box-flex'];
  14. Flex.oldValues = {
  15. 'auto': '1',
  16. 'none': '0'
  17. };
  18. Flex.prototype.prefixed = function(prop, prefix) {
  19. var ref, spec;
  20. ref = flexSpec(prefix), spec = ref[0], prefix = ref[1];
  21. if (spec === 2009) {
  22. return prefix + 'box-flex';
  23. } else {
  24. return Flex.__super__.prefixed.apply(this, arguments);
  25. }
  26. };
  27. Flex.prototype.normalize = function() {
  28. return 'flex';
  29. };
  30. Flex.prototype.set = function(decl, prefix) {
  31. var components, spec;
  32. spec = flexSpec(prefix)[0];
  33. if (spec === 2009) {
  34. decl.value = list.space(decl.value)[0];
  35. decl.value = Flex.oldValues[decl.value] || decl.value;
  36. return Flex.__super__.set.call(this, decl, prefix);
  37. } else if (spec === 2012) {
  38. components = list.space(decl.value);
  39. if (components.length === 3 && components[2] === '0') {
  40. decl.value = components.slice(0, 2).concat('0px').join(' ');
  41. }
  42. return Flex.__super__.set.call(this, decl, prefix);
  43. } else {
  44. return Flex.__super__.set.apply(this, arguments);
  45. }
  46. };
  47. return Flex;
  48. })(Declaration);
  49. module.exports = Flex;
  50. }).call(this);