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.

            
              <body onload='document.getElementsByTagName("input")[0].focus()'>
  <h1>A VERY NICE TO DO LIST</h1>
  <div id=content>
    <div>
      <input type='text' placeholder='Click + or press Enter.' onkeydown='if (event.keyCode === 13) {addTask(undoneTasks)}'>
      <div id=buttons>
        <button title='Add the task to your To Do list.' class='change' type='button' onclick='addTask(undoneTasks)'>+</button>
        <button title='Remove the last task from your To Do list.' class='change' type='button' onclick='removeLastTask(undoneTasks)'>-</button>
        <button title='Delete all tasks from your To Do list.' id='clear' type='button' onclick='undoneTasks=[];doneTasks=[];refresh(undoneTasks,doneTasks)'>clear</button>
      </div>
    </div>
    <h2>Your things to do</h2> <output title='done/undone' id='out'> 0/0:</output>
    <ul id='tasks'></ul>
    <h4>v3.0</h4>
    <h3>created by <a href="http://balazsorban.com">balázs orbán</a></h3>
  </div>
  <script type='text/javascript' src='todo.js' async></script>
</body>
            
          
!
            
              body,
button {
  background: #333
}

.change,
button,
h1,
h3,
h3 a {
  color: gold
}

#content,
h1,
h3,
ul li {
  position: relative
}

h3 a,
ul li,
ul li span {
  transition: .3s ease-in-out
}

h1,
h3 {
  z-index: 1
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  width: 100vw
}

*,
h3,
h3 a {
  color: #333
}

* {
  margin: 0;
  padding: 0;
  font-family: sans-serif;
  font-weight: bolder;
  font-size: 1em;
  border: none;
  outline: 0
}

#content {
  min-width: 200px;
  min-height: 114px;
  padding: 20px;
  border-radius: 10px;
  background-color: gold;
  border: 5px solid #daa520;
  border-bottom: 10px solid #daa520;
  box-shadow: 0 0 4px 4px rgba(0, 0, 0, .2)
}

h1 {
  font-size: 1.3em;
  margin: 5% 0 0 -2em
}

h2 {
  font-size: 1.1em;
  text-decoration: underline;
  display: inline
}

h2:after {
  font-size: .8em
}

h3,
h4 {
  font-size: .5em;
  bottom: -1.1em;
  position: absolute
}

h3 {
  padding: 0 5px;
  right: 0
}

h3 a {
  text-decoration: none
}

h3 a:hover {
  color: #fff
}

h4 {
  left: 0;
  padding: 0 8px
}

input[type=text] {
  padding: 10px;
  margin: 0 10px 20px 0;
  min-width: 240px;
  border-radius: 5px;
  border: 1px solid #333;
  box-shadow: inset 0 0 3px rgba(0, 0, 0, .3)
}

#buttons {
  position: absolute;
  top: 5px;
  right: -24px;
  display: flex;
  flex-direction: column;
  align-items: center
}

button {
  border-radius: 50%;
  padding: 15px;
  margin-top: 5px;
  border: 3px solid #daa520;
  width: 48px;
  height: 48px;
  cursor: pointer;
  font-size: 1.5em;
  line-height: 0;
  transition: .4s ease-in-out
}

button:hover {
  color: #daa520;
  background: #fff
}

.change {
  display: flex;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 1em;
  padding: 15px
}

#clear {
  font-size: .6em;
  line-height: normal;
  vertical-align: top;
  padding-left: 10px
}

#clear:hover {
  transform: none
}

ul {
  margin-top: 10px
}

ul li {
  max-width: 90%;
  list-style-type: none;
  padding: 5px;
  align-self: flex-start;
  border-bottom: 1px solid #daa520
}

ul li:hover {
  background-color: rgba(255, 255, 255, .3);
  cursor: pointer
}

ul li input {
  margin: 0 5px
}

ul li span {
  position: absolute;
  right: 0;
  padding-right: 5px
}

ul li span:hover {
  transform: scale(1.2);
  transform-origin: center
}

ul li span:after {
  content: '✕';
  color: #daa520
}

            
          
!
            
              undoneTasks = [];
doneTasks = [];
var inputArea = document.getElementsByTagName('input')[0];
var tasks = document.getElementById("tasks");

/*------------------------------------This function renders the done and undone undoneTasks.----------------------------------*/
function refresh(array1, array2) {

  /*-----Sorting the undone undoneTasks.---*/
  array1.sort(function(a, b) {
    return parseFloat(parseFloat(b.timestamp) - a.timestamp);
  });

  /*-----Emptying the unordered tasks to avoid duplicates in the next step.---*/
  while (tasks.firstChild) {
    tasks.removeChild(tasks.firstChild);
  }

  /*------This loop puts the newly added undoneTasks to the unordered tasks.------------*/
  for (i = 0; i < array1.length; i += 1) {
    var task = document.createElement("li");
    task.setAttribute("onclick", "checkCheckBox()")
    task.setAttribute("title", "Click to check this task.");

    var checkBox = document.createElement("input");
    var removeTask = document.createElement("span");
    removeTask.setAttribute("title", "Remove this task from the list.");
    removeTask.setAttribute("onclick", "removeTask()")
    checkBox.setAttribute("type", "checkbox");
    task.appendChild(checkBox);
    task.appendChild(document.createTextNode(array1[i].task));
    task.appendChild(removeTask);
    task.id = array1[i].timestamp;
    tasks.appendChild(task);
  }
  /*-----This loop puts the checked undoneTasks at the bottom of the unordered tasks.---*/
  for (i = 0; i < array2.length; i += 1) {
    var task = document.createElement("li");
    task.setAttribute("onclick", "unCheckCheckBox()");
    task.setAttribute("title", "Click to uncheck this task.");
    var checkBox = document.createElement("input");
    checkBox.setAttribute("type", "checkBox");
    checkBox.checked = true;
    task.appendChild(checkBox);
    task.appendChild(document.createTextNode(array2[i].task));
    task.id = array2[i].timestamp;
    task.style.textDecoration = "line-through";
    tasks.appendChild(task);
  }

  /*-----------------------Writing out the done/all undoneTasks.------------------------*/
  document.getElementById("out").value = doneTasks.length + "/" + (undoneTasks.length + doneTasks.length) + ":"

  /*-----Revert to the main input field.---*/
  inputArea.value = "";

}

/*-----------------------Add a new task to the the undone array as an object. ------------------------*/
function addTask(array) {

  /*-----If statement to avoid empty undoneTasks.---*/
  if (inputArea.value != "") {
    undoneTasks.unshift({
      timestamp: new Date().getTime(),
      task: inputArea.value
    });

    /*-----Run tasks rendering.---*/
    refresh(array, doneTasks);
    inputArea.placeholder = "Click + or press Enter.";
  }

  /*-----Asks the user to do not make empty undoneTasks.---*/
  else {
    inputArea.placeholder = "Write something...";
  }
}

function removeLastTask(array) {
  array = array.splice(0, 1)
  refresh(undoneTasks, doneTasks);
}

function removeTask() {
  var task = event.target.parentNode
  for (i = 0; i < undoneTasks.length; i += 1) {
    if (task.id == undoneTasks[i].timestamp) {
      undoneTasks.splice(i, 1)
    }
  }

  /*-----Run tasks rendering.---*/
  refresh(undoneTasks, doneTasks)
}

/*-----------------------Move checked element into the done array.------------------------*/
function checkCheckBox() {
  if (event.target.tagName == "INPUT") {
    var task = event.target.parentNode
  } else if (event.target.tagName == "LI") {
    var task = event.target
  } else {
    return
  }
  doneTasks.unshift({
    timestamp: parseInt(task.id),
    task: task.innerText
  });
  for (i = 0; i < undoneTasks.length; i += 1) {
    if (task.id == undoneTasks[i].timestamp) {
      undoneTasks.splice(i, 1)
    }
  }

  /*-----Run tasks rendering.---*/
  refresh(undoneTasks, doneTasks)
}

/*-----------------------Move unchecked element back to the undone array.------------------------*/
function unCheckCheckBox() {
  if (event.target.tagName === "INPUT") {
    var task = event.target.parentNode
  } else {
    var task = event.target
  }
  undoneTasks.unshift({
    timestamp: parseInt(task.id),
    task: task.innerText
  });
  for (i = 0; i < doneTasks.length; i += 1) {
    if (task.id == doneTasks[i].timestamp) {
      doneTasks.splice(i, 1)
    }
  }

  /*-----Run tasks rendering.---*/
  refresh(undoneTasks, doneTasks)
}

            
          
!
999px
Loading ..................

Console