BVB Source Codes

reactide Show selector.js Source code

Return Download reactide: download selector.js Source code - Download reactide Source code - Type:.js
  1. (function() {
  2.   var Browsers, OldSelector, Prefixer, Selector, utils,
  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.  
  6.   OldSelector = require('./old-selector');
  7.  
  8.   Prefixer = require('./prefixer');
  9.  
  10.   Browsers = require('./browsers');
  11.  
  12.   utils = require('./utils');
  13.  
  14.   Selector = (function(superClass) {
  15.     extend(Selector, superClass);
  16.  
  17.     function Selector(name1, prefixes, all) {
  18.       this.name = name1;
  19.       this.prefixes = prefixes;
  20.       this.all = all;
  21.       this.regexpCache = {};
  22.     }
  23.  
  24.     Selector.prototype.check = function(rule) {
  25.       if (rule.selector.indexOf(this.name) !== -1) {
  26.         return !!rule.selector.match(this.regexp());
  27.       } else {
  28.         return false;
  29.       }
  30.     };
  31.  
  32.     Selector.prototype.prefixed = function(prefix) {
  33.       return this.name.replace(/^([^\w]*)/, '$1' + prefix);
  34.     };
  35.  
  36.     Selector.prototype.regexp = function(prefix) {
  37.       var name;
  38.       if (this.regexpCache[prefix]) {
  39.         return this.regexpCache[prefix];
  40.       }
  41.       name = prefix ? this.prefixed(prefix) : this.name;
  42.       return this.regexpCache[prefix] = RegExp("(^|[^:\"'=])" + (utils.escapeRegexp(name)), "gi");
  43.     };
  44.  
  45.     Selector.prototype.possible = function() {
  46.       return Browsers.prefixes();
  47.     };
  48.  
  49.     Selector.prototype.prefixeds = function(rule) {
  50.       var i, len, prefix, prefixeds, ref;
  51.       if (rule._autoprefixerPrefixeds) {
  52.         return rule._autoprefixerPrefixeds;
  53.       }
  54.       prefixeds = {};
  55.       ref = this.possible();
  56.       for (i = 0, len = ref.length; i < len; i++) {
  57.         prefix = ref[i];
  58.         prefixeds[prefix] = this.replace(rule.selector, prefix);
  59.       }
  60.       return rule._autoprefixerPrefixeds = prefixeds;
  61.     };
  62.  
  63.     Selector.prototype.already = function(rule, prefixeds, prefix) {
  64.       var before, index, key, prefixed, some;
  65.       index = rule.parent.index(rule) - 1;
  66.       while (index >= 0) {
  67.         before = rule.parent.nodes[index];
  68.         if (before.type !== 'rule') {
  69.           return false;
  70.         }
  71.         some = false;
  72.         for (key in prefixeds) {
  73.           prefixed = prefixeds[key];
  74.           if (before.selector === prefixed) {
  75.             if (prefix === key) {
  76.               return true;
  77.             } else {
  78.               some = true;
  79.               break;
  80.             }
  81.           }
  82.         }
  83.         if (!some) {
  84.           return false;
  85.         }
  86.         index -= 1;
  87.       }
  88.       return false;
  89.     };
  90.  
  91.     Selector.prototype.replace = function(selector, prefix) {
  92.       return selector.replace(this.regexp(), '$1' + this.prefixed(prefix));
  93.     };
  94.  
  95.     Selector.prototype.add = function(rule, prefix) {
  96.       var cloned, prefixeds;
  97.       prefixeds = this.prefixeds(rule);
  98.       if (this.already(rule, prefixeds, prefix)) {
  99.         return;
  100.       }
  101.       cloned = this.clone(rule, {
  102.         selector: prefixeds[prefix]
  103.       });
  104.       return rule.parent.insertBefore(rule, cloned);
  105.     };
  106.  
  107.     Selector.prototype.old = function(prefix) {
  108.       return new OldSelector(this, prefix);
  109.     };
  110.  
  111.     return Selector;
  112.  
  113.   })(Prefixer);
  114.  
  115.   module.exports = Selector;
  116.  
  117. }).call(this);
  118.  
downloadselector.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top