Selector.js 797 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Generated by CoffeeScript 1.9.3
  2. var CSSSelect, Selector;
  3. CSSSelect = require('css-select');
  4. module.exports = Selector = (function() {
  5. var self;
  6. self = Selector;
  7. function Selector(text1) {
  8. this.text = text1;
  9. this._fn = CSSSelect.compile(this.text);
  10. this.priority = self.calculatePriority(this.text);
  11. }
  12. Selector.prototype.matches = function(elem) {
  13. return CSSSelect.is(elem, this._fn);
  14. };
  15. Selector.calculatePriority = function(text) {
  16. var n, priotrity;
  17. priotrity = 0;
  18. if (n = text.match(/[\#]{1}/g)) {
  19. priotrity += 100 * n.length;
  20. }
  21. if (n = text.match(/[a-zA-Z]+/g)) {
  22. priotrity += 2 * n.length;
  23. }
  24. if (n = text.match(/\*/g)) {
  25. priotrity += 1 * n.length;
  26. }
  27. return priotrity;
  28. };
  29. return Selector;
  30. })();