at-rule.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function() {
  2. var AtRule, Prefixer,
  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. Prefixer = require('./prefixer');
  6. AtRule = (function(superClass) {
  7. extend(AtRule, superClass);
  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 j, len, parent, prefix, ref, results;
  27. parent = this.parentPrefix(node);
  28. ref = this.prefixes;
  29. results = [];
  30. for (j = 0, len = ref.length; j < len; j++) {
  31. prefix = ref[j];
  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);