break-props.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (function() {
  2. var BreakProps, 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. BreakProps = (function(superClass) {
  7. extend(BreakProps, superClass);
  8. function BreakProps() {
  9. return BreakProps.__super__.constructor.apply(this, arguments);
  10. }
  11. BreakProps.names = ['break-inside', 'page-break-inside', 'column-break-inside', 'break-before', 'page-break-before', 'column-break-before', 'break-after', 'page-break-after', 'column-break-after'];
  12. BreakProps.prototype.prefixed = function(prop, prefix) {
  13. if (prefix === '-webkit-') {
  14. return '-webkit-column-' + prop;
  15. } else if (prefix === '-moz-') {
  16. return 'page-' + prop;
  17. } else {
  18. return BreakProps.__super__.prefixed.apply(this, arguments);
  19. }
  20. };
  21. BreakProps.prototype.normalize = function(prop) {
  22. if (prop.indexOf('inside') !== -1) {
  23. return 'break-inside';
  24. } else if (prop.indexOf('before') !== -1) {
  25. return 'break-before';
  26. } else if (prop.indexOf('after') !== -1) {
  27. return 'break-after';
  28. }
  29. };
  30. BreakProps.prototype.set = function(decl, prefix) {
  31. var v;
  32. v = decl.value;
  33. if (decl.prop === 'break-inside' && v === 'avoid-column' || v === 'avoid-page') {
  34. decl.value = 'avoid';
  35. }
  36. return BreakProps.__super__.set.apply(this, arguments);
  37. };
  38. BreakProps.prototype.insert = function(decl, prefix, prefixes) {
  39. if (decl.prop !== 'break-inside') {
  40. return BreakProps.__super__.insert.apply(this, arguments);
  41. } else if (decl.value === 'avoid-region') {
  42. } else if (decl.value === 'avoid-page' && prefix === '-webkit-') {
  43. } else {
  44. return BreakProps.__super__.insert.apply(this, arguments);
  45. }
  46. };
  47. return BreakProps;
  48. })(Declaration);
  49. module.exports = BreakProps;
  50. }).call(this);