githubashto / enhancejs

Automatically exported from code.google.com/p/enhancejs
Other
0 stars 0 forks source link

add onScriptsLoaded option for executing code when all scripts finish loading #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add an option called scriptsLoaded. It would accept a callback function 
that could execute when all scripts referenced via the loadScripts option 
have finished loading.

{{{
enhance({
  loadScripts: ['a.js', 'b.js'],
  scriptsLoaded: function(){
         alert('all JavaScript files have loaded!');
  }
});
}}}

Enhancement proposed by Jack Shaw and Karl Rosaen.

Original issue reported on code.google.com by scottj...@gmail.com on 12 Mar 2010 at 9:41

GoogleCodeExporter commented 9 years ago
I found this was trickier to implement than I'd expected because the 
queue.length isn't 
trustworthy to check while iterating through loadScripts (since some items may 
contain 
IEconditions and won't be applied in depending on the browser). 

We may need to add a cleanQueue function early in the script that finds all 
children of 
loadScripts and loadStyles that have ieConditional attributes and removes those 
children 
in Browsers that don't apply. Then the queue will contain only valid entries 
and we can 
make the final script trigger the onScriptsLoaded callback once it finishes 
loading.

Original comment by scottj...@gmail.com on 18 Mar 2010 at 8:18

GoogleCodeExporter commented 9 years ago
Attached a patch that seems to cover all the use cases here. The option name is 
onScriptsLoaded.

Original comment by scottj...@gmail.com on 18 Mar 2010 at 10:53

Attachments:

GoogleCodeExporter commented 9 years ago
added http://code.google.com/p/enhancejs/source/detail?r=79

Original comment by scottj...@gmail.com on 24 Mar 2010 at 10:01