Created
July 3, 2011 02:13
-
-
Save getify/1061887 to your computer and use it in GitHub Desktop.
howto: resumable chains with LABjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style>#link1, #link2 { display:none; }</style> | |
<script src="lab.js"></script> | |
<script> | |
$LAB.script("jquery.js").wait(function(){ | |
var ready = false, | |
chain = $LAB.script("links.js").wait(function(){ | |
ready = true; | |
}) | |
; | |
// links.js may finish loading long before either link is clicked, so `chain` is resumable, or link may be clicked before links.js is loaded, so chain will just be added to while still in process | |
$("#notready").hide(); | |
$("#link1, #link2").show().click(function(evt){ | |
if (!ready) $("#notready").show(); | |
chain = chain.wait(function(){ | |
$("#notready").hide(); | |
linkClicked($(evt.target).attr("id")); // comes from links.js | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="notready">Please wait...</div> | |
<a id="link1" href="#">link 1</a> | |
<a id="link2" href="#">link 2</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment