css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <body ng-app="pomodoroApp" ng-controller="pomodoroCtrl" ng-class="{'work-background' : workTime, 'break-background' : !workTime}">

  <div class="container">

    <h1 class="text-center header">Pomodoro Clock</h1>

    <div class="container pomodoro">
      <div class="row text-center clock">
        <p class="pomodoro-status">{{pomodoroStatus}}</p>
        <p>{{ displayedCount | date: 'mm:ss' }}
          <p>
      </div>
      <div class="row buttons text-center">
        <button class="clock-btn start-pause" ng-click="startPause()">Start | Pause</button>
        <button class="clock-btn reset" ng-click="reset()">Reset</button>
      </div>
      <div class="row buttons text-center increments">
        <h1>Work Time</h1>
        <button class="clock-btn increment" ng-click="removeWorkMinute()">-</button>
        <button class="clock-btn increment" ng-click="addWorkMinute()">+</button>
        <span>{{workTimerInitialSetting}} min</span>
      </div>
      <div class="row buttons text-center increments">
        <h1>Break Time</h1>
        <button class="clock-btn increment" ng-click="removeBreakMinute()">-</button>
        <button class="clock-btn increment" ng-click="addBreakMinute()">+</button>
        <span>{{breakTimerInitialSetting}} min</span>
      </div>
    </div>

  </div>
</body>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Slab|Merriweather);

$header-font: "Merriweather";
$clock-font: "Open Sans";
$button-font: "Roboto Slab";

html {
  font-size: 16px;
}

.work-background {
  background: #bfe;
}

.break-background {
  background: url('/img/break.gif') no-repeat center center fixed;
  background-size: cover;
}


.header {
  font-size: 4em;
  font-family: $header-font;
}

.clock {
  margin: 2.5rem auto 0;
  background-color: #dd6;
  height: 10rem;
  width: 18rem;
  border: 6px outset #eef;
  border-radius: 20px;
  font-size: 6em;
  font-family: $clock-font;
}

.pomodoro-status {
  margin: .6rem 0 -.8rem 0;
  font-size: .3em;
}

.buttons {
  margin: 2rem auto;
}

.clock-btn {
  display: inline-block;
  margin: 0 auto;
  border: 2px solid #eee;
  border-radius: 20px;
  height: 4.5rem;
  width: 8rem;
  color: #eee;
  font-size: 2em;
  font-family: $button-font;
}

.start-pause {
  background-color: #4a4;
  width: 12rem;
}

.reset {
  background-color: #f54;
}

.increment {
	height: 2.8rem;
	width: 2.8rem;
	border-radius: 100%;
	background-color: #BBB;
}

.increments {
	margin: 0 0 0 0;

	span {
		margin: 0rem 0 0 1rem;
		font-size: 4em;
	}
}
            
          
!
            
              'use strict';

var pomodoroApp = angular.module('pomodoroApp', []);

pomodoroApp.controller('pomodoroCtrl', 
  function($scope, $interval) {
  
    /******* Initializing Variables =====================================================*/
      // Number of minutes of work time to countdown from. User changeable
    $scope.workTimerInitialSetting = 25;
      // Number of minutes of break time to countdown from. User changable
    $scope.breakTimerInitialSetting = 5;
      // Amount of time to resume from after pause
    $scope.resumeTimerSetting = null;
      // Exact time of Start | Pause button press
    $scope.startTime = null;
      // The exact time of the timer's future completion, calculated from startTime plus workTimerInitialSetting
    $scope.endTime = null;
      // The diplayed count in the view, initiallized with initalTimerSetting's time
    $scope.resumeTime = (Date.now() + $scope.resumeTimerSetting) - Date.now();
  
    $scope.displayedCount = 60000 * $scope.workTimerInitialSetting;

    $scope.timerRunning = false;
  
    $scope.timerPaused = false;
  
    $scope.resumeTimerSetting = null;

    $scope.workTime = true;

    $scope.pomodoroStatus = 'Working';

    $scope.pomodoroBackground = 'work-background';
    

  
    /******* Timer Functions ============================================================*/
      // Stores the exact time of a Start | Pause button press
    $scope.getStartTime = function () {
      $scope.startTime = Date.now();
    };
      /**
      * The endTime for each timer is calculated by adding the startTime to the number of  
      * minutes to countdown from (which is multiplyed by 60000 to convert the minutes to 
      * miliseconds).
      */
    $scope.getWorkEndTime = function () {
      $scope.endTime = $scope.startTime + (60000 * $scope.workTimerInitialSetting);
    };
    $scope.getBreakEndTime = function () {
      $scope.endTime = $scope.startTime + (60000 * $scope.breakTimerInitialSetting)
    };
  
    $scope.getResumeTime = function() {
      $scope.resumeTime = Date.now() + $scope.resumeTimerSetting;
    };
  
      // Initialize Timer
    $scope.runTimer = function () {

      if ($scope.workTime) {
        $scope.pomodoroStatus = 'Working';
        $scope.pomodoroBackground = 'work-background';
      } else {
        $scope.pomodoroStatus = 'Enjoy your break!';
        $scope.pomodoroBackground = 'break-background';
      }
      // Calculate start and end times from the exact time of button press
      $scope.getStartTime();

      if ($scope.workTime) {
        $scope.getWorkEndTime();
      } else {
        $scope.getBreakEndTime();
      }
      $scope.timerRunning = true;
      // TODO update display to show Work Time or Break Time depending on workTime's truthyness
      // Also, write the update display function
      $scope.promise = $interval(countdown, 100);

      function countdown() {
        $scope.displayedCount = $scope.endTime - Date.now();
        
        // Once timer expires, stop the interval
        if ($scope.displayedCount <= 10) {
          $interval.cancel($scope.promise);
          $scope.displayedCount = 0;
          $scope.timerRunning = false;
          $scope.workTime = !$scope.workTime;
          console.log('$scope.workTime flipped! :', $scope.workTime);
          $scope.runTimer();     
        }

      }

    };
  
      // Pause timer
    $scope.timerPause = function() {
      $scope.resumeTimerSetting = $scope.displayedCount;
      console.log('paused!', '$scope.resumeTimerSetting = ', $scope.resumeTimerSetting);
      $interval.cancel($scope.promise);
      $interval.cancel($scope.promiseResume);
    };
  
      // Resume timer after pause
    $scope.timerResume = function () {
      $scope.getResumeTime();
      $scope.promiseResume = $interval(resumeCountdown, 100);
      function resumeCountdown() {
        $scope.displayedCount = $scope.resumeTime - Date.now();
        if ($scope.displayedCount < 10) {
          $interval.cancel($scope.promiseResume);
        }
      }
    };

    $scope.updateDisplayedCount = function () {
    	$scope.displayedCount = 60000 * $scope.workTimerInitialSetting
    };
  
  /******* Button handlers ================================================================*/
    
    /******* Start | Pause Button Handler *******/
    $scope.startPause = function () { 
      
      // if timer is currently running, pause or resume
      if ($scope.timerRunning) {
        
        // if timer is paused, resume
        if($scope.timerPaused) {
          $scope.timerPaused = false;     
          $scope.timerResume();
          return;
        }
        
        // If timer is running, then pause
        $scope.timerPaused = true;
        $scope.timerPause();
        return;
      }
      

      
      // Update the view with current time remaining until endTime is reached
      $scope.runTimer();
    };

    /** Reset Button Handler *******/
    $scope.reset = function () {
    	console.log('reset!')
      $interval.cancel($scope.promise);
      $interval.cancel($scope.promiseResume);
      $scope.displayedCount = 60000 * $scope.workTimerInitialSetting;
      $scope.startTime = null;
      $scope.endTime = null;
      $scope.timerRunning = false;
      $scope.timerPaused = false;
      $scope.pomodoroStatus = 'Working';
      $scope.workTime = true;
      console.log('workTime should be true: ', $scope.workTime);
    };

    /** User Config handlers for setting work time and break time in minutes 
    ======================================================================*/

    $scope.addWorkMinute = function () {
   	
    	if ($scope.timerRunning) {
    		$scope.reset();
    	}

    	/**
    	* A maximum of 60 minutes of work is allowed, otherwise
    	* are you really doing a pomodoro? I don't care. 60 minutes or less.
    	*/
    	if ($scope.workTimerInitialSetting === 60) {
    		return;
    	}

    	$scope.workTimerInitialSetting += 1;
    	$scope.updateDisplayedCount();
    };

    $scope.removeWorkMinute = function () {

    	// At least 1 minute of work time is required.
    	if ($scope.workTimerInitialSetting === 1) {
    		return;
    	}

    	if ($scope.timerRunning) {
    		$scope.reset();
    	}

    	$scope.workTimerInitialSetting -= 1;
    	$scope.updateDisplayedCount();

    };

    $scope.addBreakMinute = function () {

      if ($scope.breakTimerInitialSetting === 60) {
        return; 
      }

      $scope.breakTimerInitialSetting += 1;
      $scope.updateDisplayedCount();
    };

    $scope.removeBreakMinute = function () {

      if ($scope.breakTimerInitialSetting === 1) {
        return;
      }

      $scope.breakTimerInitialSetting -= 1;
      $scope.updateDisplayedCount();
    };
 
});

            
          
!
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.
Loading ..................

Console