08-27-周三_17-09-29
This commit is contained in:
178
node_modules/CSSselect/lib/attributes.js
generated
vendored
Normal file
178
node_modules/CSSselect/lib/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
var DomUtils = require("domutils"),
|
||||
hasAttrib = DomUtils.hasAttrib,
|
||||
getAttributeValue = DomUtils.getAttributeValue,
|
||||
falseFunc = require("./basefunctions.js").falseFunc;
|
||||
|
||||
//https://github.com/slevithan/XRegExp/blob/master/src/xregexp.js#L469
|
||||
var reChars = /[-[\]{}()*+?.,\\^$|#\s]/g;
|
||||
|
||||
/*
|
||||
attribute selectors
|
||||
*/
|
||||
|
||||
var attributeRules = {
|
||||
__proto__: null,
|
||||
equals: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value;
|
||||
|
||||
if(data.ignoreCase){
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function equalsIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.toLowerCase() === value && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function equals(elem){
|
||||
return getAttributeValue(elem, name) === value && next(elem);
|
||||
};
|
||||
},
|
||||
hyphen: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value,
|
||||
len = value.length;
|
||||
|
||||
if(data.ignoreCase){
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function hyphenIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null &&
|
||||
(attr.length === len || attr.charAt(len) === "-") &&
|
||||
attr.substr(0, len).toLowerCase() === value &&
|
||||
next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function hyphen(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null &&
|
||||
attr.substr(0, len) === value &&
|
||||
(attr.length === len || attr.charAt(len) === "-") &&
|
||||
next(elem);
|
||||
};
|
||||
},
|
||||
element: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value;
|
||||
|
||||
if(/\s/.test(value)){
|
||||
return falseFunc;
|
||||
}
|
||||
|
||||
value = value.replace(reChars, "\\$&");
|
||||
|
||||
var pattern = "(?:^|\\s)" + value + "(?:$|\\s)",
|
||||
flags = data.ignoreCase ? "i" : "",
|
||||
regex = new RegExp(pattern, flags);
|
||||
|
||||
return function element(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && regex.test(attr) && next(elem);
|
||||
};
|
||||
},
|
||||
exists: function(next, data){
|
||||
var name = data.name;
|
||||
return function exists(elem){
|
||||
return hasAttrib(elem, name) && next(elem);
|
||||
};
|
||||
},
|
||||
start: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value,
|
||||
len = value.length;
|
||||
|
||||
if(len === 0){
|
||||
return falseFunc;
|
||||
}
|
||||
|
||||
if(data.ignoreCase){
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function startIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(0, len).toLowerCase() === value && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function start(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(0, len) === value && next(elem);
|
||||
};
|
||||
},
|
||||
end: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value,
|
||||
len = -value.length;
|
||||
|
||||
if(len === 0){
|
||||
return falseFunc;
|
||||
}
|
||||
|
||||
if(data.ignoreCase){
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function endIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(len).toLowerCase() === value && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function end(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(len) === value && next(elem);
|
||||
};
|
||||
},
|
||||
any: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value;
|
||||
|
||||
if(value === ""){
|
||||
return falseFunc;
|
||||
}
|
||||
|
||||
if(data.ignoreCase){
|
||||
var regex = new RegExp(value.replace(reChars, "\\$&"), "i");
|
||||
|
||||
return function anyIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && regex.test(attr) && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function any(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.indexOf(value) >= 0 && next(elem);
|
||||
};
|
||||
},
|
||||
not: function(next, data){
|
||||
var name = data.name,
|
||||
value = data.value;
|
||||
|
||||
if(value === ""){
|
||||
return function notEmpty(elem){
|
||||
return !!getAttributeValue(elem, name) && next(elem);
|
||||
};
|
||||
} else if(data.ignoreCase){
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function notIC(elem){
|
||||
var attr = getAttributeValue(elem, name);
|
||||
return attr != null && attr.toLowerCase() !== value && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function not(elem){
|
||||
return getAttributeValue(elem, name) !== value && next(elem);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
compile: function(next, data){
|
||||
return attributeRules[data.action](next, data);
|
||||
},
|
||||
rules: attributeRules
|
||||
};
|
8
node_modules/CSSselect/lib/basefunctions.js
generated
vendored
Normal file
8
node_modules/CSSselect/lib/basefunctions.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
trueFunc: function trueFunc(){
|
||||
return true;
|
||||
},
|
||||
falseFunc: function falseFunc(){
|
||||
return false;
|
||||
}
|
||||
};
|
84
node_modules/CSSselect/lib/compile.js
generated
vendored
Normal file
84
node_modules/CSSselect/lib/compile.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
compiles a selector to an executable function
|
||||
*/
|
||||
|
||||
module.exports = compile;
|
||||
module.exports.compileUnsafe = compileUnsafe;
|
||||
|
||||
var parse = require("CSSwhat"),
|
||||
DomUtils = require("domutils"),
|
||||
isTag = DomUtils.isTag,
|
||||
Rules = require("./general.js"),
|
||||
sortRules = require("./sort.js"),
|
||||
BaseFuncs = require("./basefunctions.js"),
|
||||
trueFunc = BaseFuncs.trueFunc,
|
||||
falseFunc = BaseFuncs.falseFunc;
|
||||
|
||||
function compile(selector, options){
|
||||
var next = compileUnsafe(selector, options);
|
||||
|
||||
return function base(elem){
|
||||
return isTag(elem) && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
function compileUnsafe(selector, options){
|
||||
return parse(selector, options)
|
||||
.map(compileRules)
|
||||
.reduce(reduceRules, falseFunc);
|
||||
}
|
||||
|
||||
function compileRules(arr){
|
||||
if(arr.length === 0) return falseFunc;
|
||||
return sortRules(arr).reduce(function(func, rule){
|
||||
if(func === falseFunc) return func;
|
||||
return Rules[rule.type](func, rule);
|
||||
}, trueFunc);
|
||||
}
|
||||
|
||||
function reduceRules(a, b){
|
||||
if(b === falseFunc || a === trueFunc){
|
||||
return a;
|
||||
}
|
||||
if(a === falseFunc || b === trueFunc){
|
||||
return b;
|
||||
}
|
||||
|
||||
return function combine(elem){
|
||||
return a(elem) || b(elem);
|
||||
};
|
||||
}
|
||||
|
||||
//:not and :has have to compile selectors
|
||||
//doing this in lib/pseudos.js would lead to circular dependencies,
|
||||
//so we add them here
|
||||
|
||||
var Pseudos = require("./pseudos.js"),
|
||||
filters = Pseudos.filters,
|
||||
isParent = Pseudos.pseudos.parent,
|
||||
existsOne = DomUtils.existsOne,
|
||||
getChildren = DomUtils.getChildren;
|
||||
|
||||
filters.not = function(next, select){
|
||||
var func = compileUnsafe(select);
|
||||
|
||||
if(func === falseFunc) return next;
|
||||
if(func === trueFunc) return falseFunc;
|
||||
|
||||
return function(elem){
|
||||
return !func(elem) && next(elem);
|
||||
};
|
||||
};
|
||||
|
||||
filters.has = function(next, selector){
|
||||
var func = compile(selector);
|
||||
|
||||
if(func === falseFunc) return falseFunc;
|
||||
if(func === trueFunc) return function(elem){
|
||||
return isParent(elem) && next(elem);
|
||||
};
|
||||
|
||||
return function has(elem){
|
||||
return next(elem) && existsOne(func, getChildren(elem));
|
||||
};
|
||||
};
|
80
node_modules/CSSselect/lib/general.js
generated
vendored
Normal file
80
node_modules/CSSselect/lib/general.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
var DomUtils = require("domutils"),
|
||||
isTag = DomUtils.isTag,
|
||||
getParent = DomUtils.getParent,
|
||||
getChildren = DomUtils.getChildren,
|
||||
getSiblings = DomUtils.getSiblings,
|
||||
getName = DomUtils.getName;
|
||||
|
||||
/*
|
||||
all available rules
|
||||
*/
|
||||
module.exports = {
|
||||
__proto__: null,
|
||||
|
||||
attribute: require("./attributes.js").compile,
|
||||
pseudo: require("./pseudos.js").compile,
|
||||
|
||||
//tags
|
||||
tag: function(next, data){
|
||||
var name = data.name;
|
||||
return function tag(elem){
|
||||
return getName(elem) === name && next(elem);
|
||||
};
|
||||
},
|
||||
|
||||
//traversal
|
||||
descendant: function(next){
|
||||
return function descendant(elem){
|
||||
var found = false;
|
||||
|
||||
while(!found && (elem = getParent(elem))){
|
||||
found = next(elem);
|
||||
}
|
||||
|
||||
return found;
|
||||
};
|
||||
},
|
||||
parent: function(next){
|
||||
return function parent(elem){
|
||||
return getChildren(elem).some(next);
|
||||
};
|
||||
},
|
||||
child: function(next){
|
||||
return function child(elem){
|
||||
var parent = getParent(elem);
|
||||
return !!parent && next(parent);
|
||||
};
|
||||
},
|
||||
sibling: function(next){
|
||||
return function sibling(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) break;
|
||||
if(next(siblings[i])) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
},
|
||||
adjacent: function(next){
|
||||
return function adjacent(elem){
|
||||
var siblings = getSiblings(elem),
|
||||
lastElement;
|
||||
|
||||
for(var i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) break;
|
||||
lastElement = siblings[i];
|
||||
}
|
||||
}
|
||||
|
||||
return !!lastElement && next(lastElement);
|
||||
};
|
||||
},
|
||||
universal: function(next){
|
||||
return next;
|
||||
}
|
||||
};
|
84
node_modules/CSSselect/lib/nth-check.js
generated
vendored
Normal file
84
node_modules/CSSselect/lib/nth-check.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
var BaseFuncs = require("./basefunctions.js"),
|
||||
trueFunc = BaseFuncs.trueFunc,
|
||||
falseFunc = BaseFuncs.falseFunc;
|
||||
|
||||
module.exports = function nthCheck(formula){
|
||||
return compile(parse(formula));
|
||||
};
|
||||
|
||||
module.exports.parse = parse;
|
||||
module.exports.compile = compile;
|
||||
|
||||
//following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
|
||||
|
||||
//[ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
|
||||
var re_nthElement = /^([+\-]?\d*n)?\s*(?:([+\-]?)\s*(\d+))?$/;
|
||||
|
||||
/*
|
||||
parses a nth-check formula, returns an array of two numbers
|
||||
*/
|
||||
function parse(formula){
|
||||
formula = formula.trim().toLowerCase();
|
||||
|
||||
if(formula === "even"){
|
||||
return [2, 0];
|
||||
} else if(formula === "odd"){
|
||||
return [2, 1];
|
||||
} else {
|
||||
var parsed = formula.match(re_nthElement);
|
||||
|
||||
if(!parsed){
|
||||
throw new SyntaxError("n-th rule couldn't be parsed ('" + formula + "')");
|
||||
}
|
||||
|
||||
var a;
|
||||
|
||||
if(parsed[1]){
|
||||
a = parseInt(parsed[1], 10);
|
||||
if(!a){
|
||||
if(parsed[1].charAt(0) === "-") a = -1;
|
||||
else a = 1;
|
||||
}
|
||||
} else a = 0;
|
||||
|
||||
return [
|
||||
a,
|
||||
parsed[3] ? parseInt((parsed[2] || "") + parsed[3], 10) : 0
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
returns a function that checks if an elements index matches the given rule
|
||||
highly optimized to return the fastest solution
|
||||
*/
|
||||
function compile(parsed){
|
||||
var a = parsed[0],
|
||||
b = parsed[1] - 1;
|
||||
|
||||
//when b <= 0, a*n won't be possible for any matches when a < 0
|
||||
//besides, the specification says that no element is matched when a and b are 0
|
||||
if(b < 0 && a <= 0) return falseFunc;
|
||||
|
||||
//when a is in the range -1..1, it matches any element (so only b is checked)
|
||||
if(a ===-1) return function(pos){ return pos <= b; };
|
||||
if(a === 0) return function(pos){ return pos === b; };
|
||||
//when b <= 0 and a === 1, they match any element
|
||||
if(a === 1) return b < 0 ? trueFunc : function(pos){ return pos >= b; };
|
||||
|
||||
//when a > 0, modulo can be used to check if there is a match
|
||||
var bMod = b % a;
|
||||
if(bMod < 0) bMod += a;
|
||||
|
||||
if(a > 1){
|
||||
return function(pos){
|
||||
return pos >= b && pos % a === bMod;
|
||||
};
|
||||
}
|
||||
|
||||
a *= -1; //make `a` positive
|
||||
|
||||
return function(pos){
|
||||
return pos <= b && pos % a === bMod;
|
||||
};
|
||||
}
|
338
node_modules/CSSselect/lib/pseudos.js
generated
vendored
Normal file
338
node_modules/CSSselect/lib/pseudos.js
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
pseudo selectors
|
||||
|
||||
---
|
||||
|
||||
they are available in two forms:
|
||||
* filters called when the selector
|
||||
is compiled and return a function
|
||||
that needs to return next()
|
||||
* pseudos get called on execution
|
||||
they need to return a boolean
|
||||
*/
|
||||
|
||||
var DomUtils = require("domutils"),
|
||||
isTag = DomUtils.isTag,
|
||||
getText = DomUtils.getText,
|
||||
getParent = DomUtils.getParent,
|
||||
getChildren = DomUtils.getChildren,
|
||||
getSiblings = DomUtils.getSiblings,
|
||||
hasAttrib = DomUtils.hasAttrib,
|
||||
getName = DomUtils.getName,
|
||||
getAttribute= DomUtils.getAttributeValue,
|
||||
getNCheck = require("./nth-check.js"),
|
||||
checkAttrib = require("./attributes.js").rules.equals,
|
||||
BaseFuncs = require("./basefunctions.js"),
|
||||
trueFunc = BaseFuncs.trueFunc,
|
||||
falseFunc = BaseFuncs.falseFunc;
|
||||
|
||||
//helper methods
|
||||
function getFirstElement(elems){
|
||||
for(var i = 0; elems && i < elems.length; i++){
|
||||
if(isTag(elems[i])) return elems[i];
|
||||
}
|
||||
}
|
||||
|
||||
function getAttribFunc(name, value){
|
||||
var data = {name: name, value: value};
|
||||
return function attribFunc(next){
|
||||
return checkAttrib(next, data);
|
||||
};
|
||||
}
|
||||
|
||||
function getChildFunc(next){
|
||||
return function(elem){
|
||||
return !!getParent(elem) && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
var filters = {
|
||||
contains: function(next, text){
|
||||
if(
|
||||
(text.charAt(0) === "\"" || text.charAt(0) === "'") &&
|
||||
text.charAt(0) === text.substr(-1)
|
||||
){
|
||||
text = text.slice(1, -1);
|
||||
}
|
||||
return function contains(elem){
|
||||
return getText(elem).indexOf(text) >= 0 && next(elem);
|
||||
};
|
||||
},
|
||||
|
||||
//location specific methods
|
||||
//first- and last-child methods return as soon as they find another element
|
||||
"first-child": function(next){
|
||||
return function firstChild(elem){
|
||||
return getFirstElement(getSiblings(elem)) === elem && next(elem);
|
||||
};
|
||||
},
|
||||
"last-child": function(next){
|
||||
return function lastChild(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = siblings.length - 1; i >= 0; i--){
|
||||
if(siblings[i] === elem) return next(elem);
|
||||
if(isTag(siblings[i])) break;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
},
|
||||
"first-of-type": function(next){
|
||||
return function firstOfType(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) return next(elem);
|
||||
if(getName(siblings[i]) === getName(elem)) break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
},
|
||||
"last-of-type": function(next){
|
||||
return function lastOfType(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = siblings.length-1; i >= 0; i--){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) return next(elem);
|
||||
if(getName(siblings[i]) === getName(elem)) break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
},
|
||||
"only-of-type": function(next){
|
||||
return function onlyOfType(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = 0, j = siblings.length; i < j; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) continue;
|
||||
if(getName(siblings[i]) === getName(elem)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return next(elem);
|
||||
};
|
||||
},
|
||||
"only-child": function(next){
|
||||
return function onlyChild(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i]) && siblings[i] !== elem) return false;
|
||||
}
|
||||
|
||||
return next(elem);
|
||||
};
|
||||
},
|
||||
"nth-child": function(next, rule){
|
||||
var func = getNCheck(rule);
|
||||
|
||||
if(func === falseFunc) return func;
|
||||
if(func === trueFunc) return getChildFunc(next);
|
||||
|
||||
return function nthChild(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var i = 0, pos = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) break;
|
||||
else pos++;
|
||||
}
|
||||
}
|
||||
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-last-child": function(next, rule){
|
||||
var func = getNCheck(rule);
|
||||
|
||||
if(func === falseFunc) return func;
|
||||
if(func === trueFunc) return getChildFunc(next);
|
||||
|
||||
return function nthLastChild(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var pos = 0, i = siblings.length - 1; i >= 0; i--){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) break;
|
||||
else pos++;
|
||||
}
|
||||
}
|
||||
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-of-type": function(next, rule){
|
||||
var func = getNCheck(rule);
|
||||
|
||||
if(func === falseFunc) return func;
|
||||
if(func === trueFunc) return getChildFunc(next);
|
||||
|
||||
return function nthOfType(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var pos = 0, i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem) break;
|
||||
if(getName(siblings[i]) === getName(elem)) pos++;
|
||||
}
|
||||
}
|
||||
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-last-of-type": function(next, rule){
|
||||
var func = getNCheck(rule);
|
||||
|
||||
if(func === falseFunc) return func;
|
||||
if(func === trueFunc) return getChildFunc(next);
|
||||
|
||||
return function nthLastOfType(elem){
|
||||
var siblings = getSiblings(elem);
|
||||
|
||||
for(var pos = 0, i = siblings.length - 1; i >= 0; i--){
|
||||
if(siblings[i] === elem) break;
|
||||
if(getName(siblings[i]) === getName(elem)) pos++;
|
||||
}
|
||||
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
|
||||
//jQuery extensions (others follow as pseudos)
|
||||
checkbox: getAttribFunc("type", "checkbox"),
|
||||
file: getAttribFunc("type", "file"),
|
||||
password: getAttribFunc("type", "password"),
|
||||
radio: getAttribFunc("type", "radio"),
|
||||
reset: getAttribFunc("type", "reset"),
|
||||
image: getAttribFunc("type", "image"),
|
||||
submit: getAttribFunc("type", "submit")
|
||||
};
|
||||
|
||||
//while filters are precompiled, pseudos get called when they are needed
|
||||
var pseudos = {
|
||||
root: function(elem){
|
||||
return !getParent(elem);
|
||||
},
|
||||
empty: function(elem){
|
||||
return !getChildren(elem).some(function(elem){
|
||||
return isTag(elem) || elem.type === "text";
|
||||
});
|
||||
},
|
||||
|
||||
//forms
|
||||
//to consider: :target, :enabled
|
||||
selected: function(elem){
|
||||
if(hasAttrib(elem, "selected")) return true;
|
||||
else if(getName(elem) !== "option") return false;
|
||||
|
||||
//the first <option> in a <select> is also selected
|
||||
var parent = getParent(elem);
|
||||
|
||||
if(!parent || getName(parent) !== "select") return false;
|
||||
|
||||
var siblings = getChildren(parent),
|
||||
sawElem = false;
|
||||
|
||||
for(var i = 0; i < siblings.length; i++){
|
||||
if(isTag(siblings[i])){
|
||||
if(siblings[i] === elem){
|
||||
sawElem = true;
|
||||
} else if(!sawElem){
|
||||
return false;
|
||||
} else if(hasAttrib(siblings[i], "selected")){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sawElem;
|
||||
},
|
||||
disabled: function(elem){
|
||||
return hasAttrib(elem, "disabled");
|
||||
},
|
||||
enabled: function(elem){
|
||||
return !hasAttrib(elem, "disabled");
|
||||
},
|
||||
checked: function(elem){
|
||||
return hasAttrib(elem, "checked") || pseudos.selected(elem);
|
||||
},
|
||||
|
||||
//jQuery extensions
|
||||
|
||||
//:parent is the inverse of :empty
|
||||
parent: function(elem){
|
||||
return !pseudos.empty(elem);
|
||||
},
|
||||
header: function(elem){
|
||||
var name = getName(elem);
|
||||
return name === "h1" ||
|
||||
name === "h2" ||
|
||||
name === "h3" ||
|
||||
name === "h4" ||
|
||||
name === "h5" ||
|
||||
name === "h6";
|
||||
},
|
||||
|
||||
button: function(elem){
|
||||
var name = getName(elem);
|
||||
return name === "button" ||
|
||||
name === "input" &&
|
||||
getAttribute(elem, "type") === "button";
|
||||
},
|
||||
input: function(elem){
|
||||
var name = getName(elem);
|
||||
return name === "input" ||
|
||||
name === "textarea" ||
|
||||
name === "select" ||
|
||||
name === "button";
|
||||
},
|
||||
text: function(elem){
|
||||
var attr;
|
||||
return getName(elem) === "input" && (
|
||||
!(attr = getAttribute(elem, "type")) ||
|
||||
attr.toLowerCase() === "text"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
function verifyArgs(func, name, subselect){
|
||||
if(subselect === null){
|
||||
if(func.length > 1){
|
||||
throw new SyntaxError("pseudo-selector :" + name + " requires an argument");
|
||||
}
|
||||
} else {
|
||||
if(func.length === 1){
|
||||
throw new SyntaxError("pseudo-selector :" + name + " doesn't have any arguments");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compile: function(next, data){
|
||||
var name = data.name,
|
||||
subselect = data.data;
|
||||
|
||||
if(typeof filters[name] === "function"){
|
||||
verifyArgs(filters[name], name, subselect);
|
||||
return filters[name](next, subselect);
|
||||
} else if(typeof pseudos[name] === "function"){
|
||||
var func = pseudos[name];
|
||||
verifyArgs(func, name, subselect);
|
||||
return function pseudoArgs(elem){
|
||||
return func(elem, subselect) && next(elem);
|
||||
};
|
||||
} else {
|
||||
throw new SyntaxError("unmatched pseudo-class :" + name);
|
||||
}
|
||||
},
|
||||
filters: filters,
|
||||
pseudos: pseudos
|
||||
};
|
59
node_modules/CSSselect/lib/sort.js
generated
vendored
Normal file
59
node_modules/CSSselect/lib/sort.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
module.exports = sortByProcedure;
|
||||
|
||||
/*
|
||||
sort the parts of the passed selector,
|
||||
as there is potential for optimization
|
||||
(some types of selectors are faster than others)
|
||||
*/
|
||||
|
||||
var ATTRIBUTE = 1;
|
||||
|
||||
var procedure = {
|
||||
__proto__: null,
|
||||
universal: 5, //should be last so that it can be ignored
|
||||
tag: 3, //very quick test
|
||||
attribute: ATTRIBUTE,
|
||||
pseudo: 0, //can be pretty expensive (especially :has)
|
||||
|
||||
//everything else shouldn't be moved
|
||||
descendant: -1,
|
||||
child: -1,
|
||||
parent: -1,
|
||||
sibling: -1,
|
||||
adjacent: -1
|
||||
};
|
||||
|
||||
var attributes = {
|
||||
__proto__: null,
|
||||
exists: 8,
|
||||
equals: 7,
|
||||
not: 6,
|
||||
start: 5,
|
||||
end: 4,
|
||||
any: 3,
|
||||
hyphen: 2,
|
||||
element: 1
|
||||
};
|
||||
|
||||
function sortByProcedure(arr){
|
||||
for(var i = 1; i < arr.length; i++){
|
||||
var procNew = procedure[arr[i].type];
|
||||
|
||||
if(procNew < 0) continue;
|
||||
|
||||
for(var j = i - 1; j >= 0; j--){
|
||||
if(
|
||||
procNew > procedure[arr[j].type] || !(
|
||||
procNew === ATTRIBUTE &&
|
||||
procedure[arr[j].type] === ATTRIBUTE &&
|
||||
attributes[arr[i].action] <= attributes[arr[j].action]
|
||||
)
|
||||
) break;
|
||||
|
||||
var tmp = arr[j + 1];
|
||||
arr[j + 1] = arr[j];
|
||||
arr[j] = tmp;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
Reference in New Issue
Block a user