_loader.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. define("dojo/selector/_loader", ["../has", "require"],
  2. function(has, require){
  3. // summary:
  4. // This module handles loading the appropriate selector engine for the given browser
  5. "use strict";
  6. var testDiv = document.createElement("div");
  7. has.add("dom-qsa2.1", !!testDiv.querySelectorAll);
  8. has.add("dom-qsa3", function(){
  9. // test to see if we have a reasonable native selector engine available
  10. try{
  11. testDiv.innerHTML = "<p class='TEST'></p>"; // test kind of from sizzle
  12. // Safari can't handle uppercase or unicode characters when
  13. // in quirks mode, IE8 can't handle pseudos like :empty
  14. return testDiv.querySelectorAll(".TEST:empty").length == 1;
  15. }catch(e){}
  16. });
  17. var fullEngine;
  18. var acme = "./acme", lite = "./lite";
  19. return {
  20. load: function(id, parentRequire, loaded, config){
  21. var req = require;
  22. // here we implement the default logic for choosing a selector engine
  23. id = id == "default" ? has("config-selectorEngine") || "css3" : id;
  24. id = id == "css2" || id == "lite" ? lite :
  25. id == "css2.1" ? has("dom-qsa2.1") ? lite : acme :
  26. id == "css3" ? has("dom-qsa3") ? lite : acme :
  27. id == "acme" ? acme : (req = parentRequire) && id;
  28. if(id.charAt(id.length-1) == '?'){
  29. id = id.substring(0,id.length - 1);
  30. var optionalLoad = true;
  31. }
  32. // the query engine is optional, only load it if a native one is not available or existing one has not been loaded
  33. if(optionalLoad && (has("dom-compliant-qsa") || fullEngine)){
  34. return loaded(fullEngine);
  35. }
  36. // load the referenced selector engine
  37. req([id], function(engine){
  38. if(id != "./lite"){
  39. fullEngine = engine;
  40. }
  41. loaded(engine);
  42. });
  43. }
  44. };
  45. });