loader_debug.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojo._base._loader.loader_debug"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo._base._loader.loader_debug"] = true;
  8. dojo.provide("dojo._base._loader.loader_debug");
  9. //Override dojo.provide, so we can trigger the next
  10. //script tag for the next local module. We can only add one
  11. //at a time because there are browsers that execute script tags
  12. //in the order that the code is received, and not in the DOM order.
  13. dojo.nonDebugProvide = dojo.provide;
  14. dojo.provide = function(resourceName){
  15. var dbgQueue = dojo["_xdDebugQueue"];
  16. if(dbgQueue && dbgQueue.length > 0 && resourceName == dbgQueue["currentResourceName"]){
  17. //Set a timeout so the module can be executed into existence. Normally the
  18. //dojo.provide call in a module is the first line. Don't want to risk attaching
  19. //another script tag until the current one finishes executing.
  20. if(dojo.isAIR){
  21. window.setTimeout(function(){dojo._xdDebugFileLoaded(resourceName);}, 1);
  22. }else{
  23. window.setTimeout(dojo._scopeName + "._xdDebugFileLoaded('" + resourceName + "')", 1);
  24. }
  25. }
  26. return dojo.nonDebugProvide.apply(dojo, arguments);
  27. }
  28. dojo._xdDebugFileLoaded = function(resourceName){
  29. if(!dojo._xdDebugScopeChecked){
  30. //If using a scoped dojo, we need to expose dojo as a real global
  31. //for the debugAtAllCosts stuff to work.
  32. if(dojo._scopeName != "dojo"){
  33. window.dojo = window[dojo.config.scopeMap[0][1]];
  34. window.dijit = window[dojo.config.scopeMap[1][1]];
  35. window.dojox = window[dojo.config.scopeMap[2][1]];
  36. }
  37. dojo._xdDebugScopeChecked = true;
  38. }
  39. var dbgQueue = dojo._xdDebugQueue;
  40. if(resourceName && resourceName == dbgQueue.currentResourceName){
  41. dbgQueue.shift();
  42. }
  43. if(dbgQueue.length == 0){
  44. //Check for more modules that need debug loading.
  45. //dojo._xdWatchInFlight will add more things to the debug
  46. //queue if they just recently loaded but it was not detected
  47. //between the dojo._xdWatchInFlight intervals.
  48. dojo._xdWatchInFlight();
  49. }
  50. if(dbgQueue.length == 0){
  51. dbgQueue.currentResourceName = null;
  52. //Make sure nothing else is in flight.
  53. //If something is still in flight, then it still
  54. //needs to be added to debug queue after it loads.
  55. for(var param in dojo._xdInFlight){
  56. if(dojo._xdInFlight[param] === true){
  57. return;
  58. }
  59. }
  60. dojo._xdNotifyLoaded();
  61. }else{
  62. if(resourceName == dbgQueue.currentResourceName){
  63. dbgQueue.currentResourceName = dbgQueue[0].resourceName;
  64. var element = document.createElement("script");
  65. element.type = "text/javascript";
  66. element.src = dbgQueue[0].resourcePath;
  67. document.getElementsByTagName("head")[0].appendChild(element);
  68. }
  69. }
  70. }
  71. }