selector-debug.js revision f268847c5a0286f83cd89c3d39b8e51d897679fa
var PARENT_NODE = 'parentNode',
LENGTH = 'length',
NativeSelector = {
_reUnSupported: /!./,
_foundCache: [],
_supportsNative: function() {
// whitelist and feature detection to manage
// future implementations manually
},
try {
} catch(e) { // IE: requires manual copy
ret = [];
}
}
}
return ret;
},
_clearFoundCache: function() {
try { // IE no like delete
delete foundCache[i]._found;
} catch(e) {
}
}
foundCache = [];
},
if (nodes) {
});
}
}
return nodes;
},
var ret = [],
}
}
return ret;
},
// allows element scoped queries to begin with combinator
// e.g. query('> p', document.body) === query('body > p')
queries = [],
scopeQuery = false,
if (root) {
if (!isDocRoot) {
// break into separate queries for element scoping
combinator = RegExp.$1;
scopeQuery = true;
if (root[PARENT_NODE]) {
} else {
'error', 'Selector');
}
}
} else {
tmpSelector = groups[i];
}
}
}
if (!scopeQuery) {
}
}
return queries;
},
}
if (selector) {
ret = [];
try {
}
} catch(e) {
}
}
}
}
return ret;
},
var ret = [];
}
}
} else {
}
return ret;
},
var ret = false,
item;
//group = '#' + node[PARENT_NODE].id + ' ' + group; // document scope parent test
if (ret) {
break;
}
}
}
return ret;
}
};
}
// allow standalone selector-native module
if (NativeSelector._supportsNative()) {
//Y.Selector.filter = NativeSelector._filter;
//Y.Selector.test = NativeSelector._test;
}
/**
* The selector-css1 module provides helper methods allowing CSS1 Selectors to be used with DOM elements.
* @module selector-css1
* @title Selector Utility
* @requires yahoo, dom
*/
/**
* Provides helper methods for collecting and filtering DOM elements.
* @class Selector
* @static
*/
var PARENT_NODE = 'parentNode',
TAG_NAME = 'tagName',
ATTRIBUTES = 'attributes',
COMBINATOR = 'combinator',
PSEUDOS = 'pseudos',
PREVIOUS = 'previous',
PREVIOUS_SIBLING = 'previousSibling',
LENGTH = 'length',
_childCache = [], // cache to cleanup expando node.children
SelectorCSS1 = {
SORT_RESULTS: false,
if (!ret) {
ret = [];
if (n.tagName) {
}
}
}
return ret;
},
_regexCache: {},
_re: {
attr: /(\[.*\])/g,
},
/**
* Mapping of shorthand tokens to corresponding attribute selector
* @property shorthand
* @type object
*/
shorthand: {
'\\#(-?[_a-z]+[-\\w]*)': '[id=$1]',
'\\.(-?[_a-z]+[-\\w]*)': '[className~=$1]'
},
/**
* List of operators and corresponding boolean functions.
* These functions are passed the attribute and the current node's value of the attribute.
* @property operators
* @type object
*/
operators: {
'': function(node, m) { return Y.DOM.getAttribute(node, m[0]) !== ''; }, // Just test for existence of attribute
//'': '.+',
'=': '^{val}$', // equality
'~=': '(?:^|\\s+){val}(?:\\s+|$)', // space-delimited
'|=': '^{val}-?' // optional hyphen-delimited
},
pseudos: {
'first-child': function(node) {
}
},
_brute: {
/**
* Retrieves a set of nodes based on a given CSS selector.
* @method query
*
* @param {string} selector The CSS Selector to test the node against.
* @param {HTMLElement} root optional An HTMLElement to start the query from. Defaults to Y.config.doc
* @param {Boolean} firstOnly optional Whether or not to return only the first match.
* @return {Array} An array of nodes that match the given selector.
* @static
*/
var ret = [];
if (selector) {
}
}
},
} :
return true;
}
}
return false;
}
}(),
// TODO: make extensible? events?
_cleanup: function() {
}
_childCache = [];
},
var ret = [],
nodes = [],
}
} else {
}
if (token) {
if (deDupe) {
}
}
}
if (firstOnly) {
} else {
}
}
}
}
return ret;
},
i = 0,
null;
if (//node[TAG_NAME] && // tagName limits to HTMLElements
i++;
return false;
}
return false;
}
}
return false;
}
}
return true;
}
return false;
},
}
},
combinators: {
return true;
}
}
return false;
},
},
}
return true;
}
return false;
}
},
_parsers: [
{
};
return true;
}
},
{
fn: function(token, match) {
var val = match[3],
operator = !(match[2] && val) ? '' : match[2],
test = Selector.operators[operator];
// might be a function
if (typeof test === 'string') {
test = Selector._getRegExp(test.replace('{val}', val));
}
if (match[1] === 'id' && val) { // store ID for fast-path match
token.id = val;
token.prefilter = function(root) {
var doc = root.nodeType === 9 ? root : root.ownerDocument,
node = doc.getElementById(val);
return node ? [node] : [];
};
} else if (document.documentElement.getElementsByClassName &&
match[1].indexOf('class') === 0) {
if (!token.prefilter) {
token.prefilter = function(root) {
return root.getElementsByClassName(val);
};
test = true; // skip class test
}
}
return test;
}
},
{
name: COMBINATOR,
re: /^\s*([>+~]|\s)\s*/,
fn: function(token, match) {
token[COMBINATOR] = match[1];
return !! Selector.combinators[token[COMBINATOR]];
}
},
{
name: PSEUDOS,
re: /^:([\-\w]+)(?:\(['"]?(.+)['"]?\))*/i,
fn: function(token, match) {
return Selector[PSEUDOS][match[1]];
}
}
],
_getToken: function(token) {
return {
previous: token,
combinator: ' ',
tag: '*',
prefilter: function(root) {
return root.getElementsByTagName('*');
},
tests: [],
result: []
};
},
/**
Break selector into token units per simple selector.
Combinator is attached to the previous token.
*/
_tokenize: function(selector) {
selector = selector || '';
selector = Selector._replaceShorthand(Y.Lang.trim(selector));
var token = Selector._getToken(), // one token per simple selector (left selector holds combinator)
tokens = [], // array of tokens
found = false, // whether or not any matches were found this pass
test,
match; // the regex match
/*
Search for selector patterns, store, and strip them from the selector string
until no patterns match (invalid selector) or we run out of chars.
Multiple attributes and pseudos are allowed, in any order.
for example:
*/
outer:
do {
found = false; // reset after full pass
for (var i = 0, parser; parser = Selector._parsers[i++];) {
if ( (match = parser.re.exec(selector)) ) { // note assignment
test = parser.fn(token, match);
if (test) {
if (test !== true) { // auto-pass
token.tests.push({
name: match[1],
test: test,
match: match.slice(1)
});
}
found = true;
selector = selector.replace(match[0], ''); // strip current match from selector
if (!selector[LENGTH] || parser.name === COMBINATOR) {
tokens.push(token);
token = Selector._getToken(token);
}
} else {
found = false;
break outer;
}
}
}
} while (found && selector.length);
if (!found || selector.length) { // not fully parsed
tokens = [];
}
return tokens;
},
_replaceShorthand: function(selector) {
var shorthand = Selector.shorthand,
attrs = selector.match(Selector._re.attr); // pull attributes to avoid false pos on "." and "#"
if (attrs) {
}
for (var re in shorthand) {
if (shorthand.hasOwnProperty(re)) {
}
}
if (attrs) {
for (var i = 0, len = attrs[LENGTH]; i < len; ++i) {
}
}
return selector;
}
};
Y.mix(Y.Selector, SelectorCSS1, true);
// only override native when not supported
if (!Y.Selector._supportsNative()) {
Y.Selector.query = Selector._brute.query;
}
/*
an+b = get every _a_th node starting at the _b_th
0n+b = no repeat ("0" and "n" may both be omitted (together) , e.g. "0n+1" or "1", not "0+1"), return only the _b_th element
1n+b = get every element starting from b ("1" may may be omitted, e.g. "1n+0" or "n+0" or "n")
an+0 = get every _a_th element, "0" may be omitted
*/
Y.Selector._reNth = /^(?:([-]?\d*)(n){1}|(odd|even)$)*([-+]?\d*)$/;
Y.Selector._getNth = function(node, expr, tag, reverse) {
Y.Selector._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 = [],
op;
var siblings = node.parentNode.children || Selector._children(node.parentNode);
if (oddeven) {
a = 2; // always every other
op = '+';
n = 'n';
} else if ( 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;
}
if (siblings[b - 1] === node) {
return true;
} else {
return false;
}
} else if (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 ) {
return true;
}
}
} else {
for (var i = siblings.length - b, len = siblings.length; i >= 0; i -= a) {
if ( i < len && siblings[i] === node ) {
return true;
}
}
}
return false;
};
Y.mix(Y.Selector.pseudos, {
return node === node.ownerDocument.documentElement;
},
return Y.Selector._getNth(node, m[1]);
},
return Y.Selector._getNth(node, m[1], null, true);
},
return Y.Selector._getNth(node, m[1], node.tagName);
},
return Y.Selector._getNth(node, m[1], node.tagName, true);
},
var children = node.children || Y.Selector._children(node.parentNode);
return children[children.length - 1] === node;
},
return Y.DOM._childrenByTag(node.parentNode, node.tagName)[0];
},
var children = Y.DOM._childrenByTag(node.parentNode, node.tagName);
return children[children.length - 1];
},
var children = node.children || Y.Selector._children(node.parentNode);
return children.length === 1 && children[0] === node;
},
return Y.DOM._childrenByTag(node.parentNode, node.tagName).length === 1;
},
return node.childNodes.length === 0;
},
return !Y.Selector.test(node, m[1]);
},
var text = node.innerText || node.textContent || '';
return text.indexOf(m[1]) > -1;
},
return node.checked === true;
}
});
Y.mix(Y.Selector.operators, {
});
Y.Selector.combinators['~'] = function(node, token) {
var sib = node.previousSibling;
while (sib) {
if (sib.nodeType === 1 && Y.Selector._testToken(sib, null, null, token.previous)) {
return true;
}
sib = sib.previousSibling;
}
return false;
}