⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 css3selector.js

📁 CSS3Selector.rar 非常好的css管理工具
💻 JS
📖 第 1 页 / 共 2 页
字号:
        for (var i=0; i<this.length; i++){
            node = this[i].firstChild;
            node.uid = node.uid || uid++;
            if (node.uid in checkedhash){
                continue;
            } else {
                checkedhash[node.uid] = 1;
            }
            while (node){
                if (node.nodeType == 1){
                    node.uid = node.uid || uid++;
                    if (!(node.uid in hash) && $CONDITION$){
                        hash[node.uid] = 1;
                        ret.push(node);
                    }
                }
                node = node.nextSibling;
            }
        }
        return ret;
    };
    childFind = childFind.toString();

    var adjustFind = function (ret){
        var hash = ret.hash = ret.hash || {};
        var checkedhash = {};
        var node;
        for (var i=0; i<this.length; i++){
            node = this[i];
            while (node = node.nextSibling){
                node.uid = node.uid || uid++;
                if (node.uid in checkedhash) {
                    break;
                } else {
                    checkedhash[node.uid] = 1;
                }
                if (!(node.uid in hash) && $CONDITION$){
                    hash[node.uid] = 1;
                    ret.push(node);
                }
            }
        }
        return ret;
    };
    adjustFind = adjustFind.toString();

    var adjustFind1 = function (ret){
        var hash = ret.hash = ret.hash || {};
        var node;
        for (var i=0; i<this.length; i++){
            node = this[i];
            node.uid = node.uid || uid++;
            while (node = node.nextSibling){
                node.uid = node.uid || uid++;
                if (node.nodeType == 1){
                    if (!(node.uid in hash) && $CONDITION$){
                        hash[node.uid] = 1;
                        ret.push(node);
                    }
                    break;
                }
            }
        }
        return ret;
    };
    adjustFind1 = adjustFind1.toString();

    var finder = {
        'tagName': function (tagName){
            this.addArg('tagName', tagName);
            this.setTemplate(byTagName);
        },
        '.': function (className){
            if (document.getElementsByClassName){
                this.addArg('className', className);
                this.setTemplate(byClassName);
            } else {
                this.addArg('classNameRE', new RegExp('(?:^|\b)'+className+'(?:\b|$)'));
                this.setTemplate(byClassNameRE);
            }
        },
        '#': function (id){
            this.addArg('id', id);
            this.setTemplate(byId);
        },
        '>': function (){
            this.setTemplate(childFind);
        },
        '~': function (){
            this.setTemplate(adjustFind);
        },
        '+': function (){
            this.setTemplate(adjustFind1);
        }
    };
    var tester = {
        ' ': function (ctx){
            if (ctx.length == 1 && ctx[0] === document) {
                
            } else {
                
            }
        },
        'tagName': function (tagName){
            tagName = this.addArg(tagName.toUpperCase());
            this.addCon('node.tagName === '+tagName);
        },
        '#': function (id){
            id = this.addArg(id);
            this.addCon('node.id === '+id);
        },
        '.': function (className){
            className = new RegExp('\\b'+className+'\\b');
            className = this.addArg(className);
            this.addCon(className+'.test(node.className)');
        },
        '[': function (attrName){
            if (attrName == 'className'){
                this.addCon('"className" in node');
            } else if (attrName == 'href'){
                this.addCon('node.getAttribute("href", 2)');
            } else {
                attrName = this.addArg(attrName);
                this.addCon('node.getAttribute('+attrName+')');
            }
        },
        '=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            attrValue = this.addArg(attrValue);
            this.addCon('node['+attrName+'] == '+attrValue);
        },
        '!=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            attrValue = this.addArg(attrValue);
            this.addCon('node['+attrName+'] !== '+attrValue);
        },
        '~=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            attrValue = new RegExp('\\b'+attrValue+'\\b');
            attrValue = this.addArg(attrValue);
            this.addCon(attrValue+'.test(node['+attrName+'])');
        },
        '|=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            attrValue = new RegExp('^'+attrValue+'(-.*)?', 'g');
            attrValue = this.addArg(attrValue);
            this.addCon(attrValue+'.test(node['+attrName+'])');
        },
        '^=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            var len = attrValue.length;
            attrValue = this.addArg(attrValue);
            this.addCon('node['+attrName+'].indexOf('+attrValue+') === 0');
        },
        '$=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            var len = attrValue.length;
            attrValue = this.addArg(attrValue);
            this.addCon('node['+attrName+'].lastIndexOf('+attrValue+') === node['+attrName+'].length-'+len);
        },
        '*=': function (attrName, attrValue){
            attrName = this.addArg(attrName);
            attrValue = this.addArg(attrValue);
            this.addCon('node['+attrName+'].indexOf('+attrValue+') >= 0');
        },
        'contains': function (text){
            text = this.addArg(new RegExp(text));
            this.addCon(text+'.test(node.textContent||node.innerText||"")');
        }
    };
}
{
    function makefn(ctx){
        var sf = new SearchFunction;
        var token, i;
        if (ctx) {
            token = this[0];
            finder[token.name].apply(sf, token);
            for (i=1; i<this.length; i++){
                token = this[i];
                tester[token.name].apply(sf, token);
            }
            tester[this.combinator].call(sf, ctx);
        } else {
            finder[this.combinator].call(sf);
            for (i=0; i<this.length; i++){
                token = this[i];
                tester[token.name].apply(sf, token);
            }
        }
        return sf.compile();
    }
    function query(ctx, ret){
        var search;
        if (this[0].name == '#' || ctx.length > 1024){
            search = makefn.call(this, ctx);
            ctx = doc;
        } else if (this.combinator === ' '){
            search = makefn.call(this, doc);
        } else {
            search = makefn.call(this);
        }
        return search.call(ctx, ret);
    }
    function chain(ctx, ret){
        var lasti = this.length - 1;
        for (var i=0; i<lasti; i++){
            ctx = query.call(this[i], ctx, []);
        }
        return query.call(this[lasti], ctx, ret);
    }
    function group(ctx, ret){
        for (var i=0; i<this.length; i++){
            chain.call(this[i], ctx, ret);
        }
        return ret;
    }
    return function (src){
        return cache[src] = cache[src] || group.call(build(src), doc, []);
    };
}
}();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -