Guest User

Untitled

a guest
Jun 13th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. load() sequentially, instead of at the same time with jQuery
  2. $('nav a').each(function(index){
  3. var to_load = $(this).attr('href') + '#slides section';
  4. $('<section>').load(to_load, function(){
  5. $('#slides').append($(this).html());
  6. });
  7. });
  8.  
  9. $(this).attr('href') + '#slides section'
  10.  
  11. this.href + '#slides section'
  12.  
  13. var loadTos = [];
  14. $('nav a').each(function(index){
  15. loadTos.append($(this).attr('href') + '#slides section');
  16. });
  17. function load_link(to_load) {
  18. $('<section>').load(to_load, function(){
  19. $('#slides').append($(this).html());
  20. loadTos.length && load_link(loadTos.pop());
  21. });
  22. }
  23. if(loadTos.length) {
  24. loadTos = loadTos.reverse(); // make getting urls from first to last
  25. load_link(loadTos.pop());
  26. }
  27.  
  28. var i = -1; // this is because we will increment the value before using it
  29. var collection = $('nav a');
  30.  
  31. function loadNext() {
  32. i++;
  33. if (i < collection.length) {
  34. var to_load = $(collection[i]).attr('href') + '#slides section';
  35. $('<section>').load(to_load, function(){
  36. $('#slides').append($(this).html());
  37. loadNext();
  38. });
  39. }
  40. }
  41.  
  42. loadNext();
  43.  
  44. // grab array of links
  45. var links = $('nav a').map(function() {
  46. return this.href;
  47. }).get();
  48.  
  49. function loadSlides() {
  50. $('<section>').load(links[0] + '#slides section', function() {
  51. $('#slides').append($(this).html());
  52.  
  53. // remove first item of links array
  54. links.shift();
  55. loadSlides();
  56. });
  57. }
  58.  
  59. loadSlides();
Advertisement
Add Comment
Please, Sign In to add comment