grid-start.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. (function() {
  2. var Declaration, GridStart,
  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. GridStart = (function(superClass) {
  7. extend(GridStart, superClass);
  8. function GridStart() {
  9. return GridStart.__super__.constructor.apply(this, arguments);
  10. }
  11. GridStart.names = ['grid-row-start', 'grid-column-start', 'grid-row', 'grid-column'];
  12. GridStart.prototype.check = function(decl) {
  13. return decl.value.indexOf('/') === -1 || decl.value.indexOf('span') !== -1;
  14. };
  15. GridStart.prototype.normalize = function(prop) {
  16. return prop.replace('-start', '');
  17. };
  18. GridStart.prototype.prefixed = function(prop, prefix) {
  19. if (prefix === '-ms-') {
  20. return prefix + prop.replace('-start', '');
  21. } else {
  22. return GridStart.__super__.prefixed.call(this, prop, prefix);
  23. }
  24. };
  25. GridStart.prototype.insert = function(decl, prefix, prefixes) {
  26. var parts;
  27. parts = this.splitValue(decl, prefix);
  28. if (parts.length === 2) {
  29. decl.cloneBefore({
  30. prop: '-ms-' + decl.prop + '-span',
  31. value: parts[1]
  32. });
  33. }
  34. return GridStart.__super__.insert.call(this, decl, prefix, prefixes);
  35. };
  36. GridStart.prototype.set = function(decl, prefix) {
  37. var parts;
  38. parts = this.splitValue(decl, prefix);
  39. if (parts.length === 2) {
  40. decl.value = parts[0];
  41. }
  42. return GridStart.__super__.set.call(this, decl, prefix);
  43. };
  44. GridStart.prototype.splitValue = function(decl, prefix) {
  45. var parts;
  46. if (prefix === '-ms-' && decl.prop.indexOf('-start') === -1) {
  47. parts = decl.value.split(/\s*\/\s*span\s+/);
  48. if (parts.length === 2) {
  49. return parts;
  50. }
  51. }
  52. return false;
  53. };
  54. return GridStart;
  55. })(Declaration);
  56. module.exports = GridStart;
  57. }).call(this);