Read about this and more on the ThousandEyes blog.
Last active
December 17, 2015 03:09
-
-
Save chrisirhc/5541721 to your computer and use it in GitHub Desktop.
Timeout with no targetable DOM feedback
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> | |
</head> | |
<body> | |
<pre id="result"></pre> | |
<button id="myBtn">Go!</button> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script src="script.js"></script> | |
</body> | |
</html> |
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
/* global $ */ | |
var isProcessingStarted = false, | |
isProcessingDone = false, | |
$myBtn = $('#myBtn'); | |
$myBtn.on('click', clickHandler); | |
function clickHandler() { | |
if (!isProcessingStarted) { | |
startProcessing(); | |
} else { | |
checkIfReady(); | |
} | |
} | |
function startProcessing() { | |
isProcessingStarted = true; | |
$myBtn.text('Processing...'); | |
// Processing takes about two seconds before it's ready | |
// (could be an AJAX request) | |
setTimeout(processingDone, 2000); | |
} | |
function processingDone() { | |
isProcessingDone = true; | |
$myBtn.text('Done'); | |
} | |
function checkIfReady() { | |
if (isProcessingDone) { | |
$('#result').append('Horray!!\n'); | |
} else { | |
$('#result').append('Fail :(\n'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment