selector-debug.js revision 45411eef9a56441369baf37f93779e0eb0a8bf90
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;
}
return ret;
}
};
}
// allow standalone selector-native module
if (NativeSelector._supportsNative()) {
}
/**
* 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',
SelectorCSS1 = {
_regexCache: {},
_re: {
attr: /(\[.*\])/g,
},
/**
* Mapping of attributes to aliases, normally to work around HTMLAttributes
* that conflict with JS reserved words.
* @property attrAliases
* @type object
*/
attrAliases: {
},
/**
* 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: {
'=': '^{val}$', // equality
'~=': '(?:^|\\s+){val}(?:\\s+|$)', // space-delimited
'|=': '^{val}-?' // optional hyphen-delimited
},
pseudos: {
'first-child': function(node) {
}
},
_brute: {
/**
* Test if the supplied node matches the supplied selector.
* @method test
*
* @param {HTMLElement | String} node An id or node reference to the HTMLElement being tested.
* @param {string} selector The CSS Selector to test the node against.
* @return{boolean} Whether or not the node matches the selector.
* @static
*/
if (!node) {
return false;
}
return true;
}
}
return false;
}
},
/**
* Filters a set of nodes based on a given CSS selector.
* @method filter
*
* @param {string} selector The selector used to test each node.
* @return{array} An array of nodes from the supplied array that match the given selector.
* @static
*/
return result;
},
/**
* 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
*/
return result;
},
},
return false;
}
return false;
}
} else {
return false;
}
}
}
}
true;
},
if (nodes) {
continue;
}
if (firstOnly) {
return nodes[i];
}
if (deDupe) {
continue;
}
}
}
}
return result;
},
node;
if (!selector) {
return result;
}
var found;
result = [];
}
}
nodes = [],
// use id shortcut when possible
if (id) { // but not with element scoped queries
}
}
}
return result;
},
}
},
_combinators: {
return true;
}
}
return false;
},
},
}
return true;
}
return false;
}
},
_parsers: [
{
fn: function(token, match) {
var operator = match[2],
val = match[3],
test = Selector.operators[operator] || null;
// operator tests may be string or function
if (typeof test === 'string') {
test = Selector._getRegExp(test.replace('{val}', val), 'i');
}
if (test) {
token.tests.push({
name: match[1],
test: test
});
}
if (match[1] === 'id') { // store ID for fast-path match
token.id = match[1];
}
}
},
{
name: TAG_NAME,
re: /^((?:-?[_a-z]+[\w-]*)|\*)/i,
fn: function(token, match) {
var test = Selector.operators['='].replace('{val}', match[1]);
token.tag = match[1];
if (token.tag !== '*') {
token.tests.push({
name: TAG_NAME,
test: Selector._getRegExp(test, 'i') // TODO: case-sensitive? (XML)
});
}
}
},
{
name: COMBINATOR,
re: /^\s*([>+~]|\s)\s*/,
fn: function(token, match) {
token[COMBINATOR] = match[1];
}
},
{
name: PSEUDOS,
re: /^:([\-\w]+)(?:\(['"]?(.+)['"]?\))*/i,
fn: function(token, match) {
token.tests.push({
name: match[1],
test: Selector[PSEUDOS][match[1]]
});
}
}
],
_getToken: function(token) {
return {
previous: token,
combinator: ' ',
tag: '*',
tests: []
};
},
/**
Break selector into token units per simple selector.
Combinator is attached to left-hand selector.
*/
_tokenize: function(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
match; // the regex match
selector = Selector._replaceShorthand(selector);
/*
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:
*/
do {
found = false; // reset after full pass
for (var i = 0, parser; parser = Selector._parsers[i++];) {
if ( (match = parser.re.exec(selector)) ) { // note assignment
found = true;
parser.fn(token, match);
selector = selector.replace(match[0], ''); // strip current match from selector
if (!selector[LENGTH] || parser.name === COMBINATOR) {
tokens.push(token);
token = Selector._getToken(token);
}
}
}
} while (found);
return (!selector.length) ? tokens : [];
},
_replaceShorthand: function(selector) {
var shorthand = Selector.shorthand;
var 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;
}
};
// TODO: IE8 quirks
if (Y.UA.ie && Y.UA.ie < 8) { // rewrite class for IE < 8
}
Y.mix(Y.Selector, SelectorCSS1, true);
// only override native when not supported
if (!Y.Selector._supportsNative()) {
Y.Selector.query = Selector._brute.query;
Y.Selector.filter = Selector._brute.filter;
Y.Selector.test = Selector._brute.test;
}