Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. (function(){
  2. function Pomodoro($interval) {
  3. var Pomodoro = {};
  4.  
  5. Pomodoro.currentTime = 1500; // == 25 minutes
  6. Pomodoro.timerRunning = false; // the default state of the timer
  7. Pomodoro.timerText = "Start";
  8. Pomodoro.button = "default";
  9. var interval; // used in timerStart and timerStop
  10.  
  11.  
  12. // this function is the subtracts 1 off the currentTime
  13. var countdown = function() {
  14. Pomodoro.currentTime -= 1;
  15. }
  16.  
  17. // sets timerRunning to true and resets the button
  18. // stores $interval promise inside interval variable
  19. var timerStart = function() {
  20. Pomodoro.timerRunning = true;
  21. interval = $interval(countdown, 1000);
  22. Pomodoro.timerText = "Reset";
  23. Pomodoro.button = "danger";
  24. }
  25.  
  26. // cancels $interval, resets currentTime and changes button
  27. var timerEnd = function() {
  28. $interval.cancel(interval);
  29. Pomodoro.timerRunning = false;
  30. Pomodoro.currentTime = 1500;
  31. Pomodoro.timerText = "Start";
  32. Pomodoro.button = "default";
  33. }
  34.  
  35. // if timer is running stop and resets
  36. // if it's not running start the timer
  37. Pomodoro.timer = function() {
  38. if (Pomodoro.timerRunning) {
  39. timerEnd();
  40. } else if (!Pomodoro.timerRunning){
  41. timerStart();
  42. }
  43. }
  44.  
  45.  
  46. return Pomodoro;
  47. };
  48.  
  49.  
  50. angular
  51. .module('pomodoroApp')
  52. .factory('Pomodoro', ['$interval', Pomodoro])
  53. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement