selector-debug.js revision 90a1586bd47830bcf9efe76bba77d5d2ec096be7
/**
* The selector-native module provides support for native querySelector
* @module selector-native
*/
/**
* Provides a wrapper for native querySelectorAll
* @for Selector
*/
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 = [],
if (root) {
if (!isDocRoot) {
// break into separate queries for element scoping
}
} else {
}
}
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 module provides helper methods allowing CSS2 Selectors to be used with DOM elements.
* @module selector
* @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
SelectorCSS2 = {
SORT_RESULTS: true,
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) {
}
}
},
/**
* Executes the supplied function against each node until true is returned.
* @method some
*
* @param {Array} nodes The nodes to run the function against
* @param {Function} fn The function to run against each node
* @return {Boolean} whether or not any element passed
* @static
*/
} :
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)
query = selector, // original query for debug report
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, SelectorCSS2, true);
// only override native when not supported
if (!Y.Selector._supportsNative()) {
Y.Selector.query = Selector._brute.query;
}