Padding.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Generated by CoffeeScript 1.9.3
  2. var Padding, PaddingBottom, PaddingLeft, PaddingRight, PaddingTop, _Declaration,
  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. _Declaration = require('./_Declaration');
  6. PaddingTop = require('./PaddingTop');
  7. PaddingLeft = require('./PaddingLeft');
  8. PaddingRight = require('./PaddingRight');
  9. PaddingBottom = require('./PaddingBottom');
  10. module.exports = Padding = (function(superClass) {
  11. var self;
  12. extend(Padding, superClass);
  13. function Padding() {
  14. return Padding.__super__.constructor.apply(this, arguments);
  15. }
  16. self = Padding;
  17. Padding.setOnto = function(declarations, prop, originalValue) {
  18. var append, val, vals;
  19. append = '';
  20. val = _Declaration.sanitizeValue(originalValue);
  21. if (_Declaration.importantClauseRx.test(String(val))) {
  22. append = ' !important';
  23. val = val.replace(_Declaration.importantClauseRx, '');
  24. }
  25. val = val.trim();
  26. if (val.length === 0) {
  27. return self._setAllDirections(declarations, append, append, append, append);
  28. }
  29. vals = val.split(" ").map(function(val) {
  30. return val + append;
  31. });
  32. if (vals.length === 1) {
  33. return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]);
  34. } else if (vals.length === 2) {
  35. return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]);
  36. } else if (vals.length === 3) {
  37. return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]);
  38. } else if (vals.length === 4) {
  39. return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]);
  40. } else {
  41. throw Error("Can't understand value for padding: `" + originalValue + "`");
  42. }
  43. };
  44. Padding._setAllDirections = function(declarations, top, right, bottom, left) {
  45. PaddingTop.setOnto(declarations, 'paddingTop', top);
  46. PaddingTop.setOnto(declarations, 'paddingRight', right);
  47. PaddingTop.setOnto(declarations, 'paddingBottom', bottom);
  48. PaddingTop.setOnto(declarations, 'paddingLeft', left);
  49. };
  50. return Padding;
  51. })(_Declaration);