JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<link href='https://fonts.googleapis.com/css?family=Delius+Swash+Caps' rel='stylesheet' type='text/css'>
<body>
<div class='container'><center>
<h1 style='font-size:50px;' class='text-center text-primary'><span class='glyphicon glyphicon-align-right' style='color:white;'></span><font style='color:white;'> KSoft</font>Pomodoro</font> <span class='glyphicon glyphicon-align-left'></span></h1>
<div class='row'>
<div class='col-md-6 text-center'>
<input autofocus id='work' type='text' min=0 max=200 value='' class='form-control ins' placeholder="Enter work minutes...">
<input id='break' class='form-control ins' type='text' min=0 max=100 value='' placeholder="Enter break minutes...">
<div class='jumbotron myJumbo'>
<h1 id='msg' class='text-center'></h1>
<h4 id='time' class='text-center'></h4>
</div>
</div>
<div class='col-md-6'>
<a href='#' id='start' class='btn btn-primary center-block'><span class='glyphicon glyphicon-play'></span></a>
<a href='#' id='pause' class='btn btn-primary center-block pause'><span class='glyphicon glyphicon-pause'></span></a>
<a href='#' id='reset' class='btn btn-primary center-block'><span class='glyphicon glyphicon-repeat'></span></a>
</div>
</div>
</div>
<h1 id='alert' class='text-center'></h1>
</center>
</div>
</body>
body {
background-color:#0C2C52;
}
* {
font-family: 'Delius Swash Caps', cursive;
}
#start, #pause, #reset {
height:90px;
font-size:30px;
margin-top:10px;
line-height:80px;
}
.jumbotron {
margin-top:10px;
background-color:#0C2C52;
color:white;
border-left:10px solid #DEE7EF;
border-right:10px solid #5A79A5;
}
.ins {
margin-top:10px;
}
h3 {
font-size:35px;
font-weight:bold;
}
.container {
padding:20px;
border-left:20px solid #5A79A5;
border-right:20px solid #DEE7EF;
margin-top:130px;
border-radius:50px;
//box-shadow:0px 10px 25px #bbb;
}
var timer;
$(document).ready(function(){
var working = false;
var active = '';
var workTime = 0;
var breakTime = 0;
checkStatus();
//Controls if a button is disabled based on status of timer
function checkStatus() {
if (!working) {
$('#start').removeClass('disabled');
$('#pause').addClass('disabled');
$('#reset').addClass('disabled');
} else {
$('#pause').removeClass('disabled');
$('#reset').removeClass('disabled');
$('#start').addClass('disabled');
}
}
//End Check Status
//Function to Show Time !!Finished!!
function showTime(time) {
var min = Math.floor(time/60);
var sec = Math.round(time%60);
if (sec < 10) {
sec = '0' + sec;
}
var timeString = min+':'+sec;
$('#msg').text(timeString);
}
//End showTime
//Enables the timer !!Mostly Finished!!
function startTimer() {
$('.jumbotron').css('visibility', 'visible');
return setInterval(function() {
console.log("Work Timer...")
workTime--;
if (workTime < 0) {
clearInterval(timer);
timer = breakTimer();
} else {
showTime(workTime);
}
}, 1000);
}
//End Timer
//What Happens when #start is pressed
function start() {
if (working == true){ //This keeps it from being spammable
return
} //Else
workTime = $('#work').val()*60;
breakTime = $('#break').val()*60;
working = true;
checkStatus();
timer = startTimer();
}
//What Happens when #pause/resume is pressed
function pause() {
clearInterval(timer);
$('.resume').unbind().click(resume);
$('#pause').html('Resume');
$('#pause').addClass('resume');
$('#pause').removeClass('pause');
$('.resume').click(resume);
}
function resume(){
$('#pause').unbind().click(pause);
$('#pause').html('Pause');
$('#pause').addClass('pause');
$('#pause').removeClass('resume');
timer = startTimer();
}
//What happens when #reset is pressed
function reset() {
clearInterval(timer);
working = false;
workTime = 0;
breakTime = 0;
checkStatus();
$('.jumbotron').css('visibility', 'hidden');
$('#msg').html("");
}
//Break Timer
function breakTimer() {
$('.jumbotron').css('visibility', 'visible');
return setInterval(function() {
console.log("Break Timer...");
breakTime--;
if (breakTime < 0) {
clearInterval(timer);
working = false;
start();
} else {
showTime(breakTime);
}
}, 1000);
}
//Button Association
$('#start').click(start);
$('#work').keypress(function(e) {
if(e.which == 13) {
start();
}
});
//This Makes Enter Work as well to Start
$('.pause').click(pause);
$('#reset').click(reset);
}); //End of DocReady
Also see: Tab Triggers