selector-native.js revision 04b64da9f66b8791f4519ebf215ca4ee5771dfe3
(function(Y) {
/**
* The selector-native module provides support for native querySelector
* @module dom
* @submodule selector-native
* @for Selector
*/
/**
* Provides support for using CSS selectors to query the DOM
* @class Selector
* @static
* @for Selector
*/
var COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
OWNER_DOCUMENT = 'ownerDocument';
var Selector = {
_foundCache: [],
useNative: true,
var a = nodeA.sourceIndex,
b = nodeB.sourceIndex;
if (a === b) {
return 0;
} else if (a > b) {
return 1;
}
return -1;
return -1;
} else {
return 1;
}
} :
}
return compare;
}),
if (nodes) {
}
}
return nodes;
},
var ret = [],
i, node;
}
}
}
return ret;
},
/**
* 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 = [],
i,
// split group into seperate queries
if (!skipNative && // already done if skipping
}
if (!firstOnly) { // coerce DOM Collection to Array
}
if (result) {
}
}
}
}
},
// allows element scoped queries to begin with combinator
// e.g. query('> p', document.body) === query('body > p')
queries = [],
prefix = '',
i, len;
if (node) {
// enforce for element scoping
}
}
}
return queries;
},
(Y.Selector.pseudos && Y.Selector.pseudos.checked)) { // webkit (chrome, safari) fails to find "selected"
}
try {
} catch(e) { // fallback to brute if available
}
},
var ret = [],
i, node;
}
}
} else {
}
return ret;
},
var ret = false,
useFrag = false,
item,
frag,
i, j, group;
} else { // test with query
// we need a root if off-doc
if (parent) {
} else { // only use frag when no parent to query
useFrag = true;
}
}
}
ret = true;
break;
}
}
if (ret) {
break;
}
}
if (useFrag) { // cleanup
}
};
}
return ret;
},
/**
* A convenience function to emulate Y.Node's aNode.ancestor(selector).
* @param {HTMLElement} element An HTMLElement to start the query from.
* @param {String} selector The CSS selector to test the node against.
* @return {HTMLElement} The ancestor node matching the selector, or null.
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
* @static
* @method ancestor
*/
}, testSelf);
}
};
})(Y);