doLater.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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["dojox.timing.doLater"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.timing.doLater"] = true;
  8. dojo.provide("dojox.timing.doLater");
  9. dojo.experimental("dojox.timing.doLater");
  10. dojox.timing.doLater = function(/*anything*/conditional,/*Object ?*/context, /* Number ? */interval){
  11. // summary:
  12. // Check if a parameter is ready, and if not,
  13. // "do later". doLater will ping the parameter
  14. // until it evaluates to something (truthy).
  15. // It thens calls the caller with original
  16. // arguments, using the supplied context or
  17. // window.
  18. // description:
  19. // dojox.timing.doLater(conditional) is testing if the call
  20. // should be done later. So it returns
  21. // true if the param is false.
  22. // arguments:
  23. // conditional: anything
  24. // Can be a property that eventually gets set, or
  25. // an expression, method... anything that can be
  26. // evaluated.
  27. // context: Object
  28. // The namespace where the call originated.
  29. // Defaults to global and anonymous functions
  30. // interval: Number
  31. // Poll time to check conditional in Milliseconds
  32. // example:
  33. // | setTimeout(function(){
  34. // | if(dojox.timing.doLater(app.ready)){return;}
  35. // | console.log("Code is ready! anonymous.function SUCCESS")
  36. // | },700);
  37. //
  38. if(conditional){ return false; } // Boolean
  39. var callback = dojox.timing.doLater.caller,
  40. args = dojox.timing.doLater.caller.arguments;
  41. interval = interval || 100;
  42. context = context || dojo.global;
  43. setTimeout(function(){
  44. callback.apply(context, args);
  45. },interval);
  46. return true; // Boolean
  47. }
  48. }