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="container">
  <div id="work-clock">
    <p class="title">Work Activity <span id="work-span"></span></p>
    <div id="theclock-a" class="clock pom-clock"></div>
  </div>
  <div id="rest-clock">
    <p class="title">Rest Activity <span id="rest-span"></span></p>
    <div id="theclock-b" class="clock rest-clock"></div>
  </div>
  <div id="recharge-clock">
    <p class="title">Recharge Activity</p>
    <div id="theclock-c" class="clock recharge-clock"></div>
  </div>
  <div>
    <button id="the-button"></button>
    <button id="reset-button">Reset</button>
    <span id="auto-adv"><input id="auto-adv-chk" type="checkbox" checked>Auto Advance</span>
  </div>
</div>
            
          
!
            
              .container {
  display: flex; 
  flex-direction: column;  
  align-items:center;
}

.clock {
  text-align: center;
  font-size: 5em;
  color: blue;
  line-height: 100%;
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none;   /* Chrome/Safari/Opera */
  -khtml-user-select: none;    /* Konqueror */
  -moz-user-select: none;      /* Firefox */
  -ms-user-select: none;       /* IE/Edge */
  user-select: none;           /* non-prefixed version, currently
                                  not supported by any browser */
}

.ten-min, .ten-sec {
  margin-right: 0;
  padding-right: 0;
}

.one-min {
  margin-left: 0;
  padding-left: 0;
}

.one-sec { 
  margin-left: 0;
  padding-left: 0;
}

.title {
  margin-top: 10px;
  text-align: center;
  font-size: 30px;
}

#buttoncontainer {
  text-align: center;  
}

#the-button, #reset-button {
  font-size: 2em;
  color: blue;
  border-radius: 10px
}

#auto-adv {
  margin-left: 10px;
  font-size: 1.5em;
  color: blue;  
}

.colon {
  padding-bottom: 10px;
}

.dr {
  display: flex; 
  flex-direction: row;  
}

.dc {
  display: flex; 
  flex-direction: column;
  width: 60px;
}

button.down {
  border-radius: 5px;
  background-color: grey;
  display:block;
}

button.up  {
  border-radius: 5px;
  background-color: grey;
  display:block;
}

hr {
  margin: 10px 0 10px 0;
}


            
          
!
            
              function Clock(elem, id, duration, cb) {

  var tick;
  this.clockId = id;
  this.duration = duration * 60;
  this.countDown = 0;
  this.state = "stopped";
  this.parent = elem;
  this.ticklength = tick || 1000
  this.expireCallback = cb;

  // console.log(elem);

  elem.html(
    '<div class="dr" data-clock="' + elem.attr('id') + '">' +
    '<div class="dc">' +
    '<button id="hour-btn-up-' + id + '"  class="up" data-mult="3600" data-adj="1" data-min="0" data-max="9"><i class="fa fa-arrow-up"></i></button>' +
    '<span id="hour-' + id + '"></span>' +
    '<button id="hour-btn-down-' + id + '" class="down" data-mult="3600" data-adj="-1" data-min="0" data-max="9"><i class="fa fa-arrow-down"></i></button>' +
    '</div>' +
    '<div class="dc">' +
    '<span id="hour-colon" class="colon">:</span>' +
    '</div>' +
    '<div class="dc">' +
    '<button id="ten-min-btn-up-' + id + '" class="up" data-mult="600" data-adj="1" data-min="0" data-max="5"><i class="fa fa-arrow-up"></i></button>' +
    '<span id="ten-min-' + id + '"></span>' +
    '<button id="ten-min-btn-down-' + id + '" class="down" data-mult="600" data-adj="-1" data-min="0" data-max="5"><i class="fa fa-arrow-down"></i></button>' +
    '</div>' +
    '<div class="dc">' +
    '<button id="one-min-btn-up-' + id + '" class="up" data-mult="60" data-adj="1" data-min="0" data-max="9"><i class="fa fa-arrow-up"></i></button>' +
    '<span id="one-min-' + id + '"></span>' +
    '<button id="one-min-btn-down-' + id + '" class="down" data-mult="60" data-adj="-1" data-min="0" data-max="9"><i class="fa fa-arrow-down"></i></button>' +
    '</div>' +
    '<div class="dc">' +
    '<span class="colon">:</span>' +
    '</div>' +
    '<div class="dc">' +
    '<button id="ten-sec-btn-up-' + id + '" class="up" data-mult="10" data-adj="1" data-min="0" data-max="5"><i class="fa fa-arrow-up"></i></button>' +
    '<span id="ten-sec-' + id + '"></span>' +
    '<button id="ten-sec-btn-down-' + id + '" class="down" data-mult="10" data-adj="-1" data-min="0" data-max="5"><i class="fa fa-arrow-down"></i></button>' +
    '</div>' +
    '<div class="dc">' +
    '<button id="one-sec-btn-up-' + id + '" class="up" data-mult="1" data-adj="1" data-min="0" data-max="9"><i class="fa fa-arrow-up"></i></button>' +
    '<span id="one-sec-' + id + '" class="one-sec"></span>' +
    '<button id="one-sec-btn-down-' + id + '" class="down" data-mult="1" data-adj="-1" data-min="0" data-max="9"><i class="fa fa-arrow-down"></i></button>' +
    '</div>' +
    '</div><hr>');

  $("#hour-btn-up-" + id).click(this.arrowClick);
  $("#hour-btn-down-" + id).click(this.arrowClick);
  $("#ten-min-btn-up-" + id).click(this.arrowClick);
  $("#ten-min-btn-down-" + id).click(this.arrowClick);
  $("#one-min-btn-up-" + id).click(this.arrowClick);
  $("#one-min-btn-down-" + id).click(this.arrowClick);
  $("#ten-sec-btn-up-" + id).click(this.arrowClick);
  $("#ten-sec-btn-down-" + id).click(this.arrowClick);
  $("#one-sec-btn-up-" + id).click(this.arrowClick);
  $("#one-sec-btn-down-" + id).click(this.arrowClick);

  this.setClock(elem.attr('id'), this);

  this.display();

  return this;
};

Clock.clocks = {};

Clock.prototype = {

  setClock: function setClock(id, clock) {
    Clock.clocks[id] = clock;
  },

  display: function display() {
    var curr = this.countDown;
    var time = Math.floor(curr / 3600);
    $("#hour-" + this.clockId).text("" + time);
    curr = curr - time * 3600;
    time = Math.floor(curr / 600);
    $("#ten-min-" + this.clockId).text("" + time);
    curr = curr - time * 600;
    time = Math.floor(curr / 60);
    $("#one-min-" + this.clockId).text("" + time);
    curr = curr - time * 60;
    time = Math.floor(curr / 10);
    $("#ten-sec-" + this.clockId).text("" + time);
    time = curr - time * 10;
    $("#one-sec-" + this.clockId).text("" + time);
  },

  reset: function reset() {
    this.countDown = this.duration;
    this.state = "reset";
    this.display();

    $("#hour-btn-up-" + this.clockId).show();
    $("#hour-btn-down-" + this.clockId).show();
    $("#ten-min-btn-up-" + this.clockId).show();
    $("#ten-min-btn-down-" + this.clockId).show();
    $("#one-min-btn-up-" + this.clockId).show();
    $("#one-min-btn-down-" + this.clockId).show();
    $("#ten-sec-btn-up-" + this.clockId).show();
    $("#ten-sec-btn-down-" + this.clockId).show();
    $("#one-sec-btn-up-" + this.clockId).show();
    $("#one-sec-btn-down-" + this.clockId).show();
  },

  ready: function ready() {
    $("#hour-btn-up-" + this.clockId).hide();
    $("#hour-btn-down-" + this.clockId).hide();
    $("#ten-min-btn-up-" + this.clockId).hide();
    $("#ten-min-btn-down-" + this.clockId).hide();
    $("#one-min-btn-up-" + this.clockId).hide();
    $("#one-min-btn-down-" + this.clockId).hide();
    $("#ten-sec-btn-up-" + this.clockId).hide();
    $("#ten-sec-btn-down-" + this.clockId).hide();
    $("#one-sec-btn-up-" + this.clockId).hide();
    $("#one-sec-btn-down-" + this.clockId).hide();

  },

  resetCountdown: function resetCountdown() {
    this.countDown = this.duration;
    this.display();
  },

  start: function start() {
    if (this.state === "reset") {
      this.countDown = this.duration;
      if (this.countDown == 0) this.countDown = 1;
    }

    this.ready();

    if (this.countDown > 0) {
      this.state = "running";
      setTimeout(this.tick.bind(this), this.ticklength);
    }
  },

  pause: function stop() {
    this.state = "paused";
  },

  tick: function tick() {
    if (this.state !== "running") return;
    // console.log("count: " + this.countDown);
    this.countDown--;
    if (this.countDown > 0) {
      this.display();
      var that = this;
      setTimeout(this.tick.bind(this), this.ticklength);
    } else {
      this.countDown = 0;
      this.display();
      this.timerFinished();
    }
  },

  blink: function blink(elem, duration, count, colora, colorb) {
    elem.css("color", colora);
    if (count > 0) {
      setTimeout(this.blink.bind(this), duration, elem, duration, --count, colorb, colora);
    } else if (this.expireCallback && !(this.state === "reset")) {
      this.state = "reset"
      this.expireCallback();
    }
  },

  timerFinished: function timerFinished() {
    this.blink(this.parent, 500, 5, "red", "blue");
  },

  setDuration: function setDuration(duration) {
    this.duration = duration;
    this.reset();
  },

  getDuration: function getDuration() {
    return this.duration;
  },

  adjust: function adjust(val) {
    this.duration += val;
    this.countDown = this.duration;
  },

  arrowClick: function arrowClick(evt) {
    var thisClock = Clock.clocks[$(this).parent().parent().data("clock")];
    var currVal = +$($(this).parent().children()[1]).text();
    var adj = +$(this).data("adj");
    var min = +$(this).data("min");
    var max = +$(this).data("max");

    currVal += adj;
    if ((currVal >= min) && (currVal <= max)) {
      thisClock.adjust(adj * (+$(this).data("mult")));
      thisClock.display();
    }
  }

};

$("document").ready(function() {
  var currentClock;
  var aClock;
  var cycle = 1;

  var cClock = new Clock($("#theclock-c"), "c", 15, function() {
    cycle = 1;
    $("#work-span").text("Cycle: " + cycle);
    $("#rest-span").text("Cycle: " + cycle);
    $("#recharge-clock").slideUp("slow", function() {
      $("#work-clock").slideDown("slow", function() {
        currentClock = aClock;
        if ($('#auto-adv-chk').prop('checked')) {
          currentClock.start();
        } else {
          $("#the-button").text("Continue");
          currentClock.resetCountdown();
        }
      });
    });
  });
  cClock.reset();

  var bClock = new Clock($("#theclock-b"), "b", 5, function() {
    $("#rest-clock").slideUp("slow", function() {
      cycle++;
      $("#work-span").text("Cycle: " + cycle);
      $("#rest-span").text("Cycle: " + cycle);
      if (cycle == 4) {
        $("#recharge-clock").slideDown("slow", function() {
          currentClock = cClock;
          if ($('#auto-adv-chk').prop('checked')) {
            currentClock.start();
          } else {
            $("#the-button").text("Continue");
            currentClock.resetCountdown();
          }
        });
      } else {
        $("#work-clock").slideDown("slow", function() {
          currentClock = aClock;
          if ($('#auto-adv-chk').prop('checked')) {
            currentClock.start();
          } else {
            $("#the-button").text("Continue");
            currentClock.resetCountdown();
          }
        });
      }
    });
  });
  bClock.reset();

  aClock = new Clock($("#theclock-a"), "a", 25, function() {
    $("#work-clock").slideUp("slow", function() {
      $("#rest-clock").slideDown("slow", function() {
        currentClock = bClock;
        if ($('#auto-adv-chk').prop('checked')) {
          currentClock.start();
        } else {
          $("#the-button").text("Continue");
          currentClock.resetCountdown();
        }
      });
    });
  });
  aClock.reset();

  $("#the-button").text("Start");

  $("#reset-button").click(function() {
    $("#the-button").text("Start");
    $("#work-clock").slideDown("fast");
    $("#rest-clock").slideDown("fast");
    $("#recharge-clock").slideDown("fast");
    aClock.reset();
    bClock.reset();
    cClock.reset();
    $("#work-span").text("");
    $("#rest-span").text("");
    $("#recharge-span").text("");
  });

  $("#the-button").click(function() {
    if ($(this).text() == "Start") {
      cycle = 1;
      aClock.ready();
      bClock.ready();
      cClock.ready();
      setTimeout(function() {
        $("#recharge-clock").slideUp("slow", function() {
          $("#rest-clock").slideUp("slow", function() {
            aClock.start();
            currentClock = aClock;
            $("#the-button").text("Pause");
            $("#work-span").text("Cycle: " + cycle);
            $("#rest-span").text("Cycle: " + cycle);
            $("#recharge-span").text("Cycle: " + cycle);
          });
        });
      }, 500);
    } else if ($(this).text() == "Pause") {
      currentClock.pause();
      $(this).text("Run");
    } else if (($(this).text() == "Run") ||
      ($(this).text() == "Continue")) {
      currentClock.start();
      $(this).text("Pause");
    }
  });
})
            
          
!
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