/** *Listofoperatorsandcorrespondingbooleanfunctions. *Thesefunctionsarepassedtheattributeandthecurrentnode'svalueoftheattribute. *@propertyoperators *@typeobject
*/
operators: { '=': function(attr, val) { return attr === val; }, // Equality '!=': function(attr, val) { return attr !== val; }, // Inequality '~=': function(attr, val) { // Match one of space seperated words var s = ' '; return (s + attr + s).indexOf((s + val + s)) > -1;
}, '|=': function(attr, val) { return getRegExp('^' + val + '[-]?').test(attr); }, // Match start with value followed by optional hyphen '^=': function(attr, val) { return attr.indexOf(val) === 0; }, // Match starts with value '$=': function(attr, val) { return attr.lastIndexOf(val) === attr.length - val.length; }, // Match ends with value '*=': function(attr, val) { return attr.indexOf(val) > -1; }, // Match contains value as substring '': function(attr, val) { return attr; } // Just test for existence of attribute
},
var groups = selector ? selector.split(',') : []; if (groups.length) { for (var i = 0, len = groups.length; i < len; ++i) { if ( rTestNode(node, groups[i]) ) { // passes if ANY group matches returntrue;
}
} returnfalse;
} return rTestNode(node, selector);
},
var node,
result = [],
tokens = tokenize(selector);
if (!nodes.item) { // if not HTMLCollection, handle arrays of ids and/or nodes for (var i = 0, len = nodes.length; i < len; ++i) { if (!nodes[i].tagName) { // tagName limits to HTMLElements
node = Selector.document.getElementById(nodes[i]); if (node) { // skip IDs that return null
nodes[i] = node;
} else {
}
}
}
}
result = rFilter(nodes, tokenize(selector)[0]);
clearParentCache(); return result;
},
var query = function(selector, root, firstOnly, deDupe) { var result = (firstOnly) ? null : []; if (!selector) { return result;
}
var groups = selector.split(','); // TODO: handle comma in attribute/pseudo
if (groups.length > 1) { var found; for (var i = 0, len = groups.length; i < len; ++i) {
found = arguments.callee(groups[i], root, firstOnly, true);
result = firstOnly ? found : result.concat(found);
}
clearFoundCache(); return result;
}
if (root && !root.nodeName) { // assume ID
root = Selector.document.getElementById(root); if (!root) { return result;
}
}
if (token.attributes.length) { var attribute; for (var i = 0, len = token.attributes.length; i < len; ++i) {
attribute = node.getAttribute(token.attributes[i][0], 2); if (attribute === null || attribute === undefined) { returnfalse;
} if ( Selector.operators[token.attributes[i][1]] &&
!Selector.operators[token.attributes[i][1]](attribute, token.attributes[i][2])) { returnfalse;
}
}
}
if (token.pseudos.length) { for (var i = 0, len = token.pseudos.length; i < len; ++i) { if (Selector.pseudos[token.pseudos[i][0]] &&
!Selector.pseudos[token.pseudos[i][0]](node, token.pseudos[i][1])) { returnfalse;
}
}
}
var foundCache = []; var parentCache = []; var regexCache = {};
var clearFoundCache = function() { for (var i = 0, len = foundCache.length; i < len; ++i) { try { // IE no like delete delete foundCache[i]._found;
} catch(e) {
foundCache[i].removeAttribute('_found');
}
}
foundCache = [];
};
var clearParentCache = function() { if (!document.documentElement.children) { // caching children lookups for gecko returnfunction() { for (var i = 0, len = parentCache.length; i < len; ++i) { delete parentCache[i]._children;
}
parentCache = [];
};
} elsereturnfunction() {}; // do nothing
}();
var getRegExp = function(str, flags) {
flags = flags || ''; if (!regexCache[str + flags]) {
regexCache[str + flags] = new RegExp(str, flags);
} return regexCache[str + flags];
};
var combinators = { ' ': function(node, token) { while (node = node.parentNode) { if (rTestNode(node, '', token.previous)) { returntrue;
}
} returnfalse;
},
'~': function(node, token) { var sib = node.previousSibling; while (sib) { if (sib.nodeType === 1 && rTestNode(sib, null, token.previous)) { returntrue;
}
sib = sib.previousSibling;
}
returnfalse;
}
};
var getChildren = function() { if (document.documentElement.children) { // document for capability test returnfunction(node, tag) { return (tag) ? node.children.tags(tag) : node.children || [];
};
} else { returnfunction(node, tag) { if (node._children) { return node._children;
} var children = [],
childNodes = node.childNodes;
for (var i = 0, len = childNodes.length; i < len; ++i) { if (childNodes[i].tagName) { if (!tag || childNodes[i].tagName.toLowerCase() === tag) {
children[children.length] = childNodes[i];
}
}
}
node._children = children;
parentCache[parentCache.length] = node; return children;
};
}
}();
/* an+b=getevery_a_thnodestartingatthe_b_th 0n+b=norepeat("0"and"n"maybothbeomitted(together),e.g."0n+1"or"1",not"0+1"),returnonlythe_b_thelement 1n+b=geteveryelementstartingfromb("1"maymaybeomitted,e.g."1n+0"or"n+0"or"n") an+0=getevery_a_thelement,"0"maybeomitted
*/ var getNth = function(node, expr, tag, reverse) { if (tag) tag = tag.toLowerCase();
reNth.test(expr); var a = parseInt(RegExp.$1, 10), // include every _a_ elements (zero means no repeat, just first _a_)
n = RegExp.$2, // "n"
oddeven = RegExp.$3, // "odd" or "even"
b = parseInt(RegExp.$4, 10) || 0, // start scan from element _b_
result = [];
var siblings = getChildren(node.parentNode, tag);
if (oddeven) {
a = 2; // always every other
op = '+';
n = 'n';
b = (oddeven === 'odd') ? 1 : 0;
} elseif ( isNaN(a) ) {
a = (n) ? 1 : 0; // start from the first or no repeat
}
if (a === 0) { // just the first if (reverse) {
b = siblings.length - b + 1;
}
} elseif (a < 0) {
reverse = !!reverse;
a = Math.abs(a);
}
if (!reverse) { for (var i = b - 1, len = siblings.length; i < len; i += a) { if ( i >= 0 && siblings[i] === node ) { returntrue;
}
}
} else { for (var i = siblings.length - b, len = siblings.length; i >= 0; i -= a) { if ( i < len && siblings[i] === node ) { returntrue;
}
}
} returnfalse;
};
var getId = function(attr) { for (var i = 0, len = attr.length; i < len; ++i) { if (attr[i][0] == 'id' && attr[i][1] === '=') { return attr[i][2];
}
}
};
var getIdTokenIndex = function(tokens) { for (var i = 0, len = tokens.length; i < len; ++i) { if (getId(tokens[i].attributes)) { return i;
}
} return -1;
};
/** Breakselectorintotokenunitspersimpleselector. Combinatorisattachedtoleft-handselector.
*/ var tokenize = function(selector) { var token = {}, // one token per simple selector (left selector holds combinator)
tokens = [], // array of tokens
id, // unique id for the simple selector (if found)
found = false, // whether or not any matches were found this pass
match; // the regex match
selector = replaceShorthand(selector); // convert ID and CLASS shortcuts to attributes
Multipleattributesandpseudosareallowed,inanyorder. forexample: 'form:first-child[type=button]:not(button)[lang|=en]'
*/ do {
found = false; // reset after full pass for (var re in patterns) { if (!YAHOO.lang.hasOwnProperty(patterns, re)) { continue;
} if (re != 'tag' && re != 'combinator') { // only one allowed
token[re] = token[re] || [];
} if (match = patterns[re].exec(selector)) { // note assignment
found = true; if (re != 'tag' && re != 'combinator') { // only one allowed //token[re] = token[re] || [];
// capture ID for fast path to element if (re === 'attributes' && match[1] === 'id') {
token.id = match[3];
}
token[re].push(match.slice(1));
} else { // single selector (tag, combinator)
token[re] = match[1];
}
selector = selector.replace(match[0], ''); // strip current match from selector if (re === 'combinator' || !selector.length) { // next token or done
token.attributes = fixAttributes(token.attributes);
token.pseudos = token.pseudos || [];
token.tag = token.tag ? token.tag.toUpperCase() : '*';
tokens.push(token);
token = { // prep next token
previous: token
};
}
}
}
} while (found);
return tokens;
};
var fixAttributes = function(attr) { var aliases = Selector.attrAliases;
attr = attr || []; for (var i = 0, len = attr.length; i < len; ++i) { if (aliases[attr[i][0]]) { // convert reserved words, etc
attr[i][0] = aliases[attr[i][0]];
} if (!attr[i][1]) { // use exists operator
attr[i][1] = '';
}
} return attr;
};
var replaceShorthand = function(selector) { var shorthand = Selector.shorthand; var attrs = selector.match(patterns.attributes); // pull attributes to avoid false pos on "." and "#" if (attrs) {
selector = selector.replace(patterns.attributes, 'REPLACED_ATTRIBUTE');
} for (var re in shorthand) { if (!YAHOO.lang.hasOwnProperty(shorthand, re)) { continue;
}
selector = selector.replace(getRegExp(re, 'gi'), shorthand[re]);
}
if (attrs) { for (var i = 0, len = attrs.length; i < len; ++i) {
selector = selector.replace('REPLACED_ATTRIBUTE', attrs[i]);
}
} return selector;
};
Selector = new Selector();
Selector.patterns = patterns;
Y.Selector = Selector;
if (YAHOO.env.ua.ie) { // rewrite class for IE (others use getAttribute('class')
Y.Selector.attrAliases['class'] = 'className';
Y.Selector.attrAliases['for'] = 'htmlFor';
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.