at-rule.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function() {
  2. var AtRule, Prefixer,
  3. __extends = 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. Prefixer = require('./prefixer');
  6. AtRule = (function(_super) {
  7. __extends(AtRule, _super);
  8. function AtRule() {
  9. return AtRule.__super__.constructor.apply(this, arguments);
  10. }
  11. AtRule.prototype.add = function(rule, prefix) {
  12. var already, cloned, prefixed;
  13. prefixed = prefix + rule.name;
  14. already = rule.parent.some(function(i) {
  15. return i.name === prefixed && i.params === rule.params;
  16. });
  17. if (already) {
  18. return;
  19. }
  20. cloned = this.clone(rule, {
  21. name: prefixed
  22. });
  23. return rule.parent.insertBefore(rule, cloned);
  24. };
  25. AtRule.prototype.process = function(node) {
  26. var parent, prefix, _i, _len, _ref, _results;
  27. parent = this.parentPrefix(node);
  28. _ref = this.prefixes;
  29. _results = [];
  30. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  31. prefix = _ref[_i];
  32. if (parent && parent !== prefix) {
  33. continue;
  34. }
  35. _results.push(this.add(node, prefix));
  36. }
  37. return _results;
  38. };
  39. return AtRule;
  40. })(Prefixer);
  41. module.exports = AtRule;
  42. }).call(this);