Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

59 rindas
1.7 KiB

pirms 4 gadiem
  1. "use strict";
  2. module.exports = CSSselect;
  3. var Pseudos = require("./lib/pseudos.js"),
  4. DomUtils = require("domutils"),
  5. findOne = DomUtils.findOne,
  6. findAll = DomUtils.findAll,
  7. getChildren = DomUtils.getChildren,
  8. removeSubsets = DomUtils.removeSubsets,
  9. falseFunc = require("boolbase").falseFunc,
  10. compile = require("./lib/compile.js"),
  11. compileUnsafe = compile.compileUnsafe,
  12. compileToken = compile.compileToken;
  13. function getSelectorFunc(searchFunc){
  14. return function select(query, elems, options){
  15. if(typeof query !== "function") query = compileUnsafe(query, options, elems);
  16. if(!Array.isArray(elems)) elems = getChildren(elems);
  17. else elems = removeSubsets(elems);
  18. return searchFunc(query, elems);
  19. };
  20. }
  21. var selectAll = getSelectorFunc(function selectAll(query, elems){
  22. return (query === falseFunc || !elems || elems.length === 0) ? [] : findAll(query, elems);
  23. });
  24. var selectOne = getSelectorFunc(function selectOne(query, elems){
  25. return (query === falseFunc || !elems || elems.length === 0) ? null : findOne(query, elems);
  26. });
  27. function is(elem, query, options){
  28. return (typeof query === "function" ? query : compile(query, options))(elem);
  29. }
  30. /*
  31. the exported interface
  32. */
  33. function CSSselect(query, elems, options){
  34. return selectAll(query, elems, options);
  35. }
  36. CSSselect.compile = compile;
  37. CSSselect.filters = Pseudos.filters;
  38. CSSselect.pseudos = Pseudos.pseudos;
  39. CSSselect.selectAll = selectAll;
  40. CSSselect.selectOne = selectOne;
  41. CSSselect.is = is;
  42. //legacy methods (might be removed)
  43. CSSselect.parse = compile;
  44. CSSselect.iterate = selectAll;
  45. //hooks
  46. CSSselect._compileUnsafe = compileUnsafe;
  47. CSSselect._compileToken = compileToken;