cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

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.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div id="title">Pomodoro Clock</div>

<div id="image-box"><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/15790-200.png"</img>
</div>

<div id="header">
  <div id="pomodoro">
    <div id="work-title">WORK TIME</div>
    <button id="pom-minus">-</button>
    <span id="pom-minutes"></span>
    <button id="pom-plus">+</button>
  </div>  
  
  <span id="break">
    <div id="break-title">BREAK TIME</div>
    <button id="break-minus">-</button>
    <span id="break-minutes"></span>
    <button id="break-plus">+</button>
  </span>  
</div> <!--header-->

<div class="box">
  <div id="countdown"></div>
</div>

<div id="take-action">
  <button class="start" id="start-stop">GO</button>
  <button id="reset"><i class="fa fa-refresh" aria-hidden="true"></i>   
  </button>
</div>

<div id="signature">by Laura Barluzzi</div>

            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Lobster);

html, body {
  text-align: center;
  background-color: #333;
  color: white;
  padding: 10px 30px ;
  font-family: 'Orbitron', sans-serif;
}

img {
  max-width: 60px;
  max-height: 60px;
}

#image-box {
  display: inline-block;
  text-align: center;
  background-color: white;
  border-radius: 50%;
  padding: 5px;
}

#title {
  font-size: 50px;
  magin-top: 20px;
  margin-bottom: 20px;
  font-family: Lobster;
}

#signature {
  font-size: 10px;
  margin-top: 10px;
  margin-bottom: 30px;
}

#header, #take-action {
  display: flex;
  justify-content: center;
}

#pomodoro, #break {
  display: inline;
  text-align: center;
  margin-right: 30px;
  margin-left: 30px;
  margin-top: 10px;
  margin-bottom: 20px;
  font-size: 20px;
  padding: 20px;
}

#work-title, #break-title {
  font-weight: 600;
}

#pomodoro.selected, #break.selected {
  border-style: solid;
  border-color: white;
  border-width: 3px;
}

#pom-minutes, #break-minutes {
  font-size: 25px;
  margin-right: 5px;
  margin-left: 5px;
}
#pom-minus, #pom-plus, #break-minus, #break-plus {
  width: 30px;
  height: 30px;
  line-height: 30px;
  background-color: #333;
  border-color: white;
  border-radius: 50%;
  border-style: solid;
  border-width: 1px;
  font-size: 30px;
}

#pom-minus:hover, #pom-plus:hover, #break-minus:hover, #break-plus:hover {
  background-color: #686565;
}

#start-stop, #reset {
  display: inline;
  text-align: center;
  margin-right: 30px;
  margin-left: 30px;
}

.start {
  width: 60px;
  height: 60px;
  line-height: 60px;
  background-color: #0c7230;
  border-radius: 50%;
  text-align: center;
  font-size: 20px;
}

.stop {
  width: 60px;
  height: 60px;
  line-height: 60px;
  background-color: #770f0f;
  border-radius: 50%;
  text-align: center;
  font-size: 15px;
}

.stop:hover {
  background-color: #540707;
}

.start:hover {
  background-color: #045621;
}

#reset {
  width: 60px;
  height: 60px;
  line-height: 60px;
  background-color: #770f0f;
  border-radius: 50%;
  text-align: center;
}

#reset:hover {
  background-color: #540707;
}

.box {
  display: table; 
  margin: auto;
}

#countdown {
  display: table-cell;
  vertical-align: middle;
  width: 300px;
  height: 150px;
  color: #333;
  font-weight: 600;
  font-size: 60px;
  background-color: #b7bcb9;
  border-right-style: solid;
  border-bottom-style: solid;
  border-right-color: #262827;
  border-bottom-color: #262827;
  border-radius: 2%;
  box-shadow: 5px 5px 10px #262827; 
}

#take-action {
  margin-top: 20px;
  margin-bottom: 30px;
}
            
          
!
            
              function setStopButton() {
  $("#start-stop").removeClass("start");
  $("#start-stop").addClass("stop");    
  $("#start-stop").html("STOP");
}

function setStartButton() {
  $("#start-stop").removeClass("stop");
  $("#start-stop").addClass("start");
  $("#start-stop").html("GO");
}

function resetLastSetting() {
  var timerIsRunning = $("#start-stop").hasClass("stop");
  //console.log(typeof $("#pom-minutes").text()); // why here a string
  var minutes = parseInt($("#pom-minutes").text());
  minutes = minutes < 10 ? "0" + minutes : minutes;
  
  $("#countdown").html(minutes + ":00");
  $("#pomodoro, #break").removeClass("selected");

  if (timerIsRunning) {
    setStartButton();
    clearInterval($("#start-stop").data("intervalId"));
  }
}

function startNextSession(previousSession) {
  var display = $("#countdown"); 
  var nextSession;
  
  if (previousSession === "pomodoro") {
    var breakSeconds = ($("#break-minutes").text())*60; //why typeof number?
    nextSession = "break";
    $("#pomodoro").removeClass("selected");  
    $("#break").addClass("selected");
    startTimer(breakSeconds, display, nextSession);
    
  } else {
    var pomSeconds = ($("#pom-minutes").text())*60; // why typeof number?
    nextSession = "pomodoro";
    $("#break").removeClass("selected");
    $("#pomodoro").addClass("selected");
    startTimer(pomSeconds, display, nextSession);
  }
}

function playAlarm(typeSession) {  
  var audio = new Audio('https://www.freespecialeffects.co.uk/soundfx/clocks/clock_chime.wav');  
  audio.volume = 0.1;
  audio.play();
  setTimeout(function() {startNextSession(typeSession)}, 5500);
} 

function startTimer(SecondsSession, display, typeSession) {
  var timer = SecondsSession;
  var interval = setInterval(function() {
      var minutes = parseInt(timer / 60, 10);
      var seconds = parseInt(timer % 60, 10);

      minutes = minutes < 10 ? "0" + minutes : minutes;
      seconds = seconds < 10 ? "0" + seconds : seconds;
      display.text(minutes + ":" + seconds);

      if (--timer < 0) {
        playAlarm(typeSession);
        clearInterval(interval);

      } else if (timer < SecondsSession) {
        $("#start-stop").data("min", parseInt(minutes));
        $("#start-stop").data("sec", parseInt(seconds));
        $("#start-stop").data("session", typeSession);
        $("#start-stop").data("intervalId", interval);
      }
    
  }, 1000);
}

function isTheBeginningOfSession() {
  var duration = $("#pom-minutes").text(); //why here string
  var currentValue = $("#countdown").html();
  var defaultValue = (duration.length === 1) ? "0" + duration + ":00" : duration + ":00";
  return defaultValue === currentValue;
}

function checkButtonStatus(Session) {
  return function(event) {
    var clicked = $(event.target);
    var display = $("#countdown");
    var hasClassStart = $(event.target).hasClass("start");
    var isTheStart = isTheBeginningOfSession();

    if (hasClassStart && isTheStart) {   
      var pomSeconds = ($("#pom-minutes").text())*60;
      $("#pomodoro").addClass("selected");
      setStopButton();
      startTimer(pomSeconds, display, Session);

    } else if (hasClassStart) {
        var session = clicked.data("session");
        var restartPoint = (clicked.data("min") * 60) + clicked.data("sec");
        setStopButton();
        startTimer(restartPoint, display, session);
    
    } else {
        var interval = clicked.data("intervalId");
        setStartButton();
        clearInterval(interval);
    }
  }
} 

function reduceMin(minutesId) {
  return function(event) {
    var minStr = $(minutesId).text();
    var min = parseInt(minStr);
    if (min > 1) {
      $(minutesId).text(min-1);
    }  
  }
}

function addMin(minutesId) {
  return function(event) {
    var minStr = $(minutesId).text();
    var min = parseInt(minStr);
    if (min < 60) {
      $(minutesId).text(min+1);
    }  
  }
}

function setUpPage() {
  var pomDefault = 25;
  var breakDefault = 5;
  $("#pom-minutes").html(pomDefault);
  $("#break-minutes").html(breakDefault);
  $("#countdown").html(((pomDefault < 10) ? "0" + pomDefault : pomDefault) + ":00");
}

function main() {
  setUpPage();    
  $("#pom-minus").click(reduceMin("#pom-minutes"));
  $("#break-minus").click(reduceMin("#break-minutes")); 
  $("#pom-plus").click(addMin("#pom-minutes"));
  $("#break-plus").click(addMin("#break-minutes"));  
  $("#start-stop").click(checkButtonStatus("pomodoro"));
  $("#reset").click(resetLastSetting);  
}

$(document).ready(main);
            
          
!
999px
Loading ..................

Console