No Description

flex-direction.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. (function() {
  2. var Declaration, FlexDirection, flexSpec,
  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. FlexDirection = (function(superClass) {
  8. extend(FlexDirection, superClass);
  9. function FlexDirection() {
  10. return FlexDirection.__super__.constructor.apply(this, arguments);
  11. }
  12. FlexDirection.names = ['flex-direction', 'box-direction', 'box-orient'];
  13. FlexDirection.prototype.normalize = function(prop) {
  14. return 'flex-direction';
  15. };
  16. FlexDirection.prototype.insert = function(decl, prefix, prefixes) {
  17. var already, cloned, dir, orient, ref, spec, value;
  18. ref = flexSpec(prefix), spec = ref[0], prefix = ref[1];
  19. if (spec === 2009) {
  20. already = decl.parent.some(function(i) {
  21. return i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction';
  22. });
  23. if (already) {
  24. return;
  25. }
  26. value = decl.value;
  27. orient = value.indexOf('row') !== -1 ? 'horizontal' : 'vertical';
  28. dir = value.indexOf('reverse') !== -1 ? 'reverse' : 'normal';
  29. cloned = this.clone(decl);
  30. cloned.prop = prefix + 'box-orient';
  31. cloned.value = orient;
  32. if (this.needCascade(decl)) {
  33. cloned.before = this.calcBefore(prefixes, decl, prefix);
  34. }
  35. decl.parent.insertBefore(decl, cloned);
  36. cloned = this.clone(decl);
  37. cloned.prop = prefix + 'box-direction';
  38. cloned.value = dir;
  39. if (this.needCascade(decl)) {
  40. cloned.before = this.calcBefore(prefixes, decl, prefix);
  41. }
  42. return decl.parent.insertBefore(decl, cloned);
  43. } else {
  44. return FlexDirection.__super__.insert.apply(this, arguments);
  45. }
  46. };
  47. FlexDirection.prototype.old = function(prop, prefix) {
  48. var ref, spec;
  49. ref = flexSpec(prefix), spec = ref[0], prefix = ref[1];
  50. if (spec === 2009) {
  51. return [prefix + 'box-orient', prefix + 'box-direction'];
  52. } else {
  53. return FlexDirection.__super__.old.apply(this, arguments);
  54. }
  55. };
  56. return FlexDirection;
  57. })(Declaration);
  58. module.exports = FlexDirection;
  59. }).call(this);