Skip to content

Instantly share code, notes, and snippets.

@yctay
Created June 5, 2012 06:43
Show Gist options
  • Select an option

  • Save yctay/2873139 to your computer and use it in GitHub Desktop.

Select an option

Save yctay/2873139 to your computer and use it in GitHub Desktop.
Simple Timer Controls, with Bootstrap v2 CSS styles
<!-- Le CSS
============================== -->
<link href="https://raw.github.com/twitter/bootstrap/master/docs/assets/css/bootstrap.css" rel="stylesheet" type="text/css">
<!-- Le HTML
============================== -->
<div class="btn-group" id="timer-controls">
<a class="btn btn-success" id="timer-start" style="padding-left:47px;padding-right:48px;"><i class="icon-play icon-white"></i>&nbsp;Start</a>
</div>
<!-- Le jQuery include, from Google CDN with local fallback
============================== -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='js/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<!-- Le Timer Button Controls
============================== -->
<script>
var secondaryButtonsHTML = '<a class="btn btn-warning" id="timer-pause"><i class="icon-pause icon-white"></i>&nbsp;Pause</a>' + '<a class="btn btn-danger" id="timer-stop"><i class="icon-stop icon-white"></i>&nbsp;Stop</a>';
var resumeButtonHTML = '<a class="btn btn-success" id="timer-resume" style="padding-left:37px;padding-right:37px;"><i class="icon-play icon-white"></i>&nbsp;Resume</a>'
var restartButtonHTML = '<a class="btn btn-success" id="timer-restart" style="padding-left:40px;padding-right:40px;"><i class="icon-play icon-white"></i>&nbsp;Restart</a>'
function showTimerSecondaryButtons() {
$(this).replaceWith( $(secondaryButtonsHTML));
}
function showTimerResumeButton() {
$(this).replaceWith( $(resumeButtonHTML));
$('#timer-stop').remove();
}
function showTimerRestartButton() {
$(this).replaceWith( $(restartButtonHTML));
$('#timer-pause').remove();
}
$('#timer-start').on('click', showTimerSecondaryButtons);
$('#timer-controls').on('click', '#timer-pause', showTimerResumeButton);
$('#timer-controls').on('click', '#timer-stop', showTimerRestartButton);
$('#timer-controls').on('click', '#timer-resume', showTimerSecondaryButtons);
$('#timer-controls').on('click', '#timer-restart', showTimerSecondaryButtons);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment