123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

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.

            
              <div class="clock">
  <div class="timer">
    <div class="progress-radial step-0 session">
      <div class="main-display overlay">
      </div><!-- /.main-display -->
    </div><!-- /.progress-radial -->
  </div><!-- /.timer -->
  <div class="session-info">
    <div class="session-count">
    </div><!-- /.session-count -->
  </div><!-- /.session-info -->
  <div class="settings">
    <div class="time-session">
      <h6>session time</h6>
      <p class="time-session-display"></p>
      <button class="minus">-</button>
      <button class="plus">+</button>
    </div><!-- /.time-session -->
    <div class="time-break">
      <h6>break time</h6>
      <p class="time-break-display"></p>
      <button class="minus">-</button>
      <button class="plus">+</button>
    </div><!-- /.time-break -->
  </div><!-- /.settings -->
  <div class="controls">
    <button class="time-start">Start</button>
    <button class="time-reset">Reset</button>
  </div><!-- /.controls -->
</div><!-- /.clock -->
            
          
!
            
              $dark-gray: rgba(34, 33, 32, 0.8);
$main-text-color: #DADADB;
$radial-bg-color: #636361;
$radial-break-color: #EB6841;
$radial-session-color: #00A0B0;
$radial-overlay-color: #EAE9E5;
$shadow: 0 16px 28px 0 rgba(0,0,0,.8),0 25px 55px 0 rgba(0,0,0,0.21);

html, body {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
}

body {
  background: linear-gradient(60deg, #135058, #F1F2B5);
  padding-top: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  @media (min-height: 500px) {
    align-items: center;
    padding-top: 0;
  }
}

.clock {
  background-color: $dark-gray;
  border-radius: 4px;
  box-shadow: $shadow;
  font-family: 'Open Sans', sans-serif;
  width: 220px;
  height: auto;
  text-align: center;
  margin: 0 auto;
  padding: 10px;
  .progress-radial {
    display: inline-block;
    position: relative;
    font-size: 2.2em;
    width: 6em;
    padding-bottom: 6em;
    margin-top: 5px;
    border-radius: 50%;
    background-color: $radial-session-color;
    .overlay {
      position: absolute;
      top: 5%;
      bottom: 5%;
      left: 5%;
      right: 5%;
      border-radius: 50%;
      background-color: $radial-overlay-color;
      font-family: 'Droid Sans Mono', monospace;
      padding-top: 34%;
    }
    &.session .overlay {
      color: $radial-session-color;
    }
    &.break .overlay {
      color: $radial-break-color;
    }
  }
  .session-info, .settings, .controls {
    color: $main-text-color;
  }
  .settings {
    border-top: 1px dotted #818184;
    border-bottom: 1px dotted #818184;
    .time-session, .time-break {
      display: inline-block;
      padding: 20px;
      h6 {
        margin-top: 0;
        margin-bottom: 5px;
      }
      button {
        background-color: rgba(8,8,8,0.7);
        border: none;
        border-radius: 4px;
        color: $main-text-color;
        transition: background-color 0.2s ease-in-out;
        width: 30px;
        &:hover, &:focus {
          background-color: rgba(130,130,130, 0.8);         
        }
      }
      .time-session-display, .time-break-display {
        margin-bottom: 8px;
        margin-top: 0px;
        line-height: 1em;
      }
      .time-session-display {
        color: $radial-session-color;
      }
      .time-break-display {
        color: $radial-break-color;
      }
    }
  }
  .controls {
    padding-top: 20px;
    padding-bottom: 10px;
    button {
      background-color: rgba(8,8,8,0.7);
      border: none;
      border-radius: 4px;
      color: $main-text-color;
      font-size: 0.9em;
      transition: background-color 0.2s ease-in-out;
      height: 40px;
      width: 70px;
      margin-left: 15px;
      margin-right: 15px;
      &:hover, &:focus {
        background-color: rgba(130,130,130, 0.8); 
      }
    }
  }
}

$increment: 3.6;
@for $i from 0 through 100 {
  .step-#{$i} {
    @if $i < 50 {
      $nextdeg: 90deg + ( $increment * $i );
      &.session {
        background-image: linear-gradient(90deg, $radial-bg-color 50%, transparent 50%, transparent), linear-gradient($nextdeg, $radial-session-color 50%, $radial-bg-color 50%, $radial-bg-color); 
      }
      &.break {
        background-image: linear-gradient(90deg, $radial-bg-color 50%, transparent 50%, transparent), linear-gradient($nextdeg, $radial-break-color 50%, $radial-bg-color 50%, $radial-bg-color);
      }
    } @else {
      $nextdeg: -90deg + ( $increment * ( $i - 50 ) );
      &.session {
        background-image: linear-gradient($nextdeg, $radial-session-color 50%, transparent 50%, transparent), linear-gradient(270deg, $radial-session-color 50%, $radial-bg-color 50%, $radial-bg-color);
      }
      &.break {
        background-image: linear-gradient($nextdeg, $radial-break-color 50%, transparent 50%, transparent), linear-gradient(270deg, $radial-break-color 50%, $radial-bg-color 50%, $radial-bg-color);
      }
    }
  }
}
            
          
!
            
              $(function() {
  
  // initialize the clock and display
  var clock = new Clock();
  clock.displayCurrentTime();
  clock.displaySessionTime();
  clock.displayBreakTime();
  clock.displaySessionCount();
  
  // add event listeners 
  $(".time-session .minus").click(function() {
    clock.changeSessionTime("subtract");
  });
  $(".time-session .plus").click(function() {
    clock.changeSessionTime("add");
  });
  $(".time-break .minus").click(function() {
    clock.changeBreakTime("subtract");
  });
  $(".time-break .plus").click(function() {
    clock.changeBreakTime("add");
  });
  $(".time-start").click(function() {
    clock.toggleClock();
  });
  $(".time-reset").click(function() {
    clock.reset();
  });
  
  
  // Clock contains all the properties and methods to run a pomodoro clock
  function Clock() {
    
    var _this = this, // needed to pass 'this' to setInterval
        timer, // reference to the interval
        active = false, // is the timer running?
        type = "Session", // type -- "Session" or "Break"
        startTime = 1500, // stores the starting value of timer
        currentTime = 1500, // current time on the clock in seconds
        sessionTime = 1500, // stores the session time in seconds
        breakTime = 300, // stores the break time in seconds
        sessionCount = 0, // stores the number of session that have passed
        startAudio = new Audio("https://jpk-image-hosting.s3.amazonaws.com/pomodoro-app/audio/start.mp3"),
        endAudio = new Audio("https://jpk-image-hosting.s3.amazonaws.com/pomodoro-app/audio/end.mp3");
    
    // formatTime returns a friendly formatted time string
    function formatTime(secs) {
      var result = "";
      var seconds = secs % 60;
      var minutes = parseInt(secs / 60) % 60;
      var hours = parseInt(secs / 3600);
      function addLeadingZeroes(time) {
        return time < 10 ? "0" + time : time;
      }
      if (hours > 0) result += (hours + ":");
      result += (addLeadingZeroes(minutes) + ":" + addLeadingZeroes(seconds));
      return result;
    }
    
    // method to add/substract 60 seconds from session time
    // only works if timer is not active
    this.changeSessionTime = function(str) {
      if (active === false) {
        this.reset();
        if (str === "add") {
          sessionTime += 60;
        } else if ( sessionTime > 60){
          sessionTime -= 60;
        }
        currentTime = sessionTime;
        startTime = sessionTime;
        this.displaySessionTime();
        this.displayCurrentTime();
      }
    }
    
    // method to add/subtract 60 seconds from break time
    // only works if timer is not active
    this.changeBreakTime = function(str) {
      if (active === false) {
        this.reset();
        if (str === "add") {
          breakTime += 60;
        } else if (breakTime > 60) {
          breakTime -= 60;
        }
        this.displayBreakTime();
      }
    }
    
    // inserts the current time variable into the DOM
    this.displayCurrentTime = function() {
      $('.main-display').text(formatTime(currentTime));
      if (type === "Session" && $('.progress-radial').hasClass('break')) {
        $('.progress-radial').removeClass('break').addClass('session');
      } else if (type === "Break" && $('.progress-radial').hasClass('session')) {
        $('.progress-radial').removeClass('session').addClass('break');
      }
      $('.progress-radial').attr('class', function(i, c) {
        return c.replace(/(^|\s)step-\S+/g, " step-" + (100 - parseInt((currentTime / startTime) * 100)));
      });
    }
    
    // inserts the session time variable into the DOM
    this.displaySessionTime = function() {
      $('.time-session .time-session-display').text(parseInt(sessionTime / 60) + " min");
    }
    
    // inserts the break time variable into the DOM
    this.displayBreakTime = function() {
      $('.time-break .time-break-display').text(parseInt(breakTime / 60) + " min");
    }
    
    // inserts the session count variable into the DOM
    this.displaySessionCount = function() {
      if (sessionCount === 0) {
        $('.session-count').html("<h2>Pomodoro Clock</h2>");
      } else if (type === "Session") {
        $('.session-count').html("<h2> Session " + sessionCount + "</h2>"); 
      } else if (type === "Break") {
        $('.session-count').html("<h2>Break!</h2>");
      }
    }
    
    // toggles the timer start/pause
    this.toggleClock = function() {
      if (active === true) {
        clearInterval(timer);
        $('.time-start').text('Start');
        active = false;
      } else {
        $('.time-start').text('Pause');
        if (sessionCount === 0) {
          sessionCount = 1;
          this.displaySessionCount();
          startAudio.play();
        }
        timer = setInterval(function() {
          _this.stepDown();
        }, 1000);
        active = true;
      }
    }
    
    // steps the timer down by 1
    // when current time runs out, alternates new Session or Break
    this.stepDown = function() {
      if (currentTime > 0) {
        currentTime --;
        this.displayCurrentTime();
        if (currentTime === 0) {
          if (type === "Session") {
            currentTime = breakTime;
            startTime = breakTime;
            type = "Break";
            this.displaySessionCount();
            endAudio.play();
          } else {
            sessionCount ++;
            currentTime = sessionTime;
            startTime = sessionTime;
            type = "Session";
            this.displaySessionCount();
            startAudio.play();
          }
        }
      }
    }
    
    // reset the timer
    this.reset = function() {
      clearInterval(timer);
      active = false;
      type = "Session";
      currentTime = sessionTime;
      sessionCount = 0;
      $('.time-start').text('Start');
      this.displayCurrentTime();
      this.displaySessionTime();
      this.displaySessionCount();
    }
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console