Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="test-div">TEST</div>
<div id="test-buttons-div">
  <input id="test-add-number" type="number" placeholder="how much notes to add?">
  <button onclick="nNotesToAdd(skipValidation = false)">add</button>
  <button onclick="testAdd(skipValidation = false)" style="margin-right: 40px">single add</button>
  <button onclick="testDel()">remove last one</button>
  <button onclick="testDel(true)">remove all</button>
</div>
<div id="board">
  <img src="http://res.cloudinary.com/cspaveljb/image/upload/v1499110957/pen2_albumw.png" alt="sorry" id="pen" href="#input-modal" data-toggle="modal">
  <div id="input-modal" class="modal fade">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close glyphicon glyphicon-remove" data-dismiss="modal" aria-hidden="true"></button>
          <h4 class="modal-title">New task</h4>
        </div>
        <div class="modal-body">
          <form>
            <div class="form-group">
              <label for="title">Title:</label><span class="validation-error">error</span>
              <input type="text" class="form-control" id="title" placeholder="Enter title of the task" autofocus>
            </div>
            <div class="form-group">
              <label for="title">Date and Time:</label><span class="validation-error">error</span>
              <input type='text' class="form-control" id="datetimepicker4" placeholder="Enter date and time of the task">
            </div>
            <div class="form-group">
              <label for="description">Description:</label><span class="validation-error">error</span>
              <textarea class="form-control" id="description" rows="4" placeholder="Describe the task"></textarea>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <span id="color-input" style="display: none"><label style="float: left;">Pick a color: &nbsp;</label>
            <input type="color" style="float: left" value="#FFFF00"></span>
          <button type="button" class="btn btn-info" id="color-button" style="float: left">Custom color</button>
          <button type="button" class="btn btn-default" id="clear-button">Clear</button>
          <button type="button" class="btn btn-primary" id="add-button" data-dismiss="modal">Add</button>
        </div>
      </div>
    </div>
  </div>
  <div class="wscroll" id="inner-board">
  </div>
</div>
              
            
!

CSS

              
                @keyframes swing {
  20% {
    transform: rotate(6deg);
  }
  40% {
    transform: rotate(-4deg);
  }
  60% {
    transform: rotate(2deg);
  }
  80% {
    transform: rotate(-2deg);
  }
  to {
    transform: rotate(0deg);
  }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale3d(.1, .1, .1);
  }
  12% {
    transform: scale3d(1.6, 1.6, 1.6) translate(50px, 50px);
  }
  to {
    opacity: 1;
    transform: scale(1, 1, 1);
  }
}

@keyframes rotateOutDownRight {
  from {
    transform-origin: right bottom;
    opacity: 1;
  }
  to {
    transform-origin: right bottom;
    transform: rotate3d(0, 0, 1, -45deg);
    opacity: 0;
  }
}

.wscroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.wscroll::-webkit-scrollbar-button {
  width: 9px;
  height: 9px;
}

.wscroll::-webkit-scrollbar-thumb {
  background-color: hsl(36, 100%, 50%);
  border-radius: 9px;
  background-image: -webkit-linear-gradient(
    45deg,
    rgba(255, 255, 255, .2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, .2) 50%,
    rgba(255, 255, 255, .2) 75%,
    transparent 75%,
    transparent
  );
}

.wscroll::-webkit-scrollbar-thumb:hover {
  background-color: hsl(36, 100%, 40%);
  background-image: -webkit-linear-gradient(
    45deg,
    rgba(255, 255, 255, .2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, .2) 50%,
    rgba(255, 255, 255, .2) 75%,
    transparent 75%,
    transparent
  );
}

.wscroll::-webkit-scrollbar-thumb:active {
  background-color: hsl(36, 100%, 35%);
  background-image: -webkit-linear-gradient(
    45deg,
    rgba(255, 255, 255, .2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, .2) 50%,
    rgba(255, 255, 255, .2) 75%,
    transparent 75%,
    transparent
  );
}

.wscroll::-webkit-scrollbar-track {
  background: #5a5a5a;
  border-radius: 50px;
}

.wscroll::-webkit-scrollbar-track:hover {
  background: #4a4a4a;
}

.wscroll::-webkit-scrollbar-track:active {
  background: #3f3f3f;
}

.wscroll::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  margin: 20px;
  background-image: url("http://res.cloudinary.com/cspaveljb/image/upload/v1499110966/whitewall_jxi78g.jpg");
}

#board {
  border: 31px solid transparent;
  height: 93vh;
  width: 97vw;
  min-height: 381px;
  min-width: 572px;
  /*max-width: 1500px;*/
  background-image: url("http://res.cloudinary.com/cspaveljb/image/upload/v1499110969/cork_w2tt25.jpg");
  background-size: 1300px;
  border-image-source: url("http://res.cloudinary.com/cspaveljb/image/upload/v1499110958/corkborder_f8cm3g.png");
  border-image-slice: 31 29;
  border-image-width: 31px 29px;
  overflow: hidden;
  position: absolute;
}

#inner-board {
  /*border: 2px dotted red;*/
  /*min-height: 300px;*/
  height: 93%;
  overflow: auto;
  overflow-x: visible;
  /*position: relative;*/
}

#pen {
  margin: 10px auto;
  display: block;
  width: 500px;
}
/*--------NOTE SECTION------------*/

.note {
  margin: 3px;
  background-color: yellow;
  border-radius: 7px;
  text-align: center;
  overflow: hidden;
  display: inline-block;
  box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.6);
  position: relative;
  height: 240px;
  width: 240px;
  /*animation-name: bounceIn;*/
  animation-duration: 1.5s;
  animation-play-state: "running";
  border: 1px solid rgba(135, 135, 135, 0.45);
  background-image: url("http://res.cloudinary.com/cspaveljb/image/upload/v1499110956/note_font_pcdcst.png");
  background-size: cover;
}

.trash-button {
  position: absolute;
  right: 10px;
  top: 10px;
  visibility: hidden;
  color: #333333;
  font-size: 15px;
  opacity: 0.5;
  z-index: 1;
  text-shadow: 2px 2px 5px #505050;
}

.note:hover .trash-button {
  visibility: visible;
  cursor: pointer;
}

.date {
  position: absolute;
  left: 21px;
  bottom: 0;
  font-family: "Courier New", Courier, monospace;
}

.title {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  position: absolute;
  font-size: 22px;
  left: 3px;
  width: 232px;
  height: 30px;
  overflow: hidden;
  /*border: 2px solid red;*/
  border-radius: 3px;
  background-color: rgba(0, 0, 0, 0.2);
}

.description {
  font-family: 'Calligraffitti', cursive;
  font-size: 22px;
  overflow: auto;
  position: absolute;
  text-align: left;
  max-height: 180px;
  margin: 36px 0px 0px 21px;
  height: 176px;
  width: 215px;
  /*border: 2px solid red;*/
}
/*-------------------*/

#pen:hover {
  animation-duration: 1s;
  animation-fill-mode: both;
  transform-origin: top center;
  animation-name: swing;
}

textarea {
  resize: none;
}

.modal-content {
  background-image: url("http://res.cloudinary.com/cspaveljb/image/upload/v1499110958/yellow_page_h0zg70.jpg");
  background-size: cover;
  z-index: 5;
}

.modal-title {
  font-family: Impact, Charcoal, sans-serif;
  text-align: center;
  font-size: 30px;
}

.modal-content {
  font-size: 25px;
  font-family: 'Calligraffitti', cursive;
}

.modal-footer button {
  font-family: Impact, Charcoal, sans-serif;
}
/*------------validation area ------------*/

.validation-error {
  color: red;
  float: right;
  font-size: 15px;
  font-family: "Arial Black", Gadget, sans-serif;
  visibility: hidden;
  margin-top: 10px;
}

.validation-error::before {
  content: "*";
}

input, textarea, .dropdown-menu {
  font-family: initial;
}

#test-buttons-div {
  width: 565px;
  visibility: hidden;
  position: absolute;
  z-index: 1;
  margin: 2px 0 0 15px;
}

#test-div {
  font-family: "Arial Black", Gadget, sans-serif;
  position: absolute;
  z-index: 2;
  color: green;
  text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
  font-size: 18px;
  transform: translate(-3px, 13px) rotate(-45deg);
  opacity: 0.6;
}

              
            
!

JS

              
                "use strict";

window.onload = function() {
  restoreFromLocalStorage();
  restoreNotesFromObject();
};
window.onbeforeunload = saveToLocalStorage;

// Color input button event listener
document.getElementById("color-button").addEventListener("click", function() {
  document.getElementsByTagName("button")[5].style.display = "none";
  document.getElementById("color-input").style.display = "";
});

document
  .getElementById("clear-button")
  .addEventListener("click", clearInputValues);
document.getElementById("add-button").addEventListener("click", domAddNote);

//----- ADDING FROM INPUT TO DOM -----///
function domAddNote() {
  var titleInput = document.getElementsByTagName("input")[1].value;
  var decriptionInput = document.getElementsByTagName("textarea")[0].value;
  var dateInput = document.getElementsByTagName("input")[2].value;
  var colorInput = document.getElementsByTagName("input")[3].value;
  addNote(
    titleInput,
    decriptionInput,
    dateInput,
    colorInput,
    "bounceIn",
    false
  );
}

// Clears input values and error messages
function clearInputValues() {
  document.getElementsByTagName("input")[1].value = "";
  document.getElementsByTagName("input")[2].value = "";
  document.getElementsByTagName("textarea")[0].value = "";
  document.getElementsByClassName("validation-error")[0].style.visibility =
    "hidden";
  document.getElementsByClassName("validation-error")[1].style.visibility =
    "hidden";
  document.getElementsByClassName("validation-error")[2].style.visibility =
    "hidden";
}

function saveToLocalStorage() {
  localStorage.setItem("corkBoard", JSON.stringify(notes));
  console.log(localStorage.corkBoard);
}

function restoreFromLocalStorage() {
  if (localStorage.getItem("corkBoard") !== null) {
    notes = JSON.parse(localStorage.getItem("corkBoard"));
  }
}

// ------------ RESTORATION FROM OBJECT TO DOM ------------------
function restoreNotesFromObject() {
  for (var i in notes) {
    if (notes.hasOwnProperty(i)) {
      addNote(
        notes[i].title,
        notes[i].description,
        notes[i].date,
        notes[i].color,
        "none",
        true,
        notes[i].id,
        notes[i].position
      );
    }
  }
}

$(function() {
  $("#datetimepicker4").datetimepicker({
    format: "YYYY/MM/DD HH:mm"
  });
});

("use strict");

// Test button event listener
document.getElementById("test-div").addEventListener("click", function() {
  document.getElementById("test-buttons-div").style.visibility = "visible";
  document.getElementById("test-div").style.visibility = "hidden";
});

// Test function that passes validation
function testAdd() {
  var titleInput = randomString();
  var decriptionInput =
    randomString() +
    " " +
    randomString() +
    " " +
    randomString() +
    " " +
    randomString() +
    " " +
    randomString();
  var dateInput =
    randomInt(2018, 2029) +
    "/0" +
    randomInt(1, 9) +
    "/" +
    randomInt(0, 2) +
    randomInt(1, 9) +
    " " +
    randomInt(0, 2) +
    randomInt(1, 4) +
    ":" +
    randomInt(10, 59); // 2017/07/03 05:44
  var colorInput =
    "hsl(" +
    randomInt(0, 360) +
    ", " +
    randomInt(20, 95) +
    "%, " +
    randomInt(55, 80) +
    "%)";
  addNote(titleInput, decriptionInput, dateInput, colorInput, "bounceIn");
}

function testDel(all) {
  var trashButton = document.getElementsByClassName("trash-button");
  if (trashButton[0] !== undefined) {
    trashButton[0].click();
    if (all) {
      for (var i = 0; i < trashButton.length; i++) {
        trashButton[i].click();
      }
    }
  }
}

// n notes to add function
function nNotesToAdd() {
  var count = document.getElementById("test-add-number").value;
  if (document.getElementById("test-add-number").value <= 50) {
    for (var i = 0; i < count; i++) {
      testAdd();
    }
    document.getElementById("test-add-number").value = "";
  }
}

function randomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function randomString() {
  return (
    Math.random().toString(36).substring(7) +
    Math.random().toString(36).substring(7)
  );
}

("use strict");

var globalCounter = 0;
var notes = {};

//------------MAIN VALIDATION FUNCTION ----------------//
function noteValidation(titleInput, decriptionInput, dateInput) {
  var titleError = document.getElementsByClassName("validation-error")[0];
  var dateError = document.getElementsByClassName("validation-error")[1];
  var descriptionError = document.getElementsByClassName("validation-error")[2];

  // Title Validation
  var titleValidation = (function() {
    var titleValue = titleInput;
    if (titleValue === "") {
      titleError.innerHTML = "Title can't be empty";
      titleError.style.visibility = "visible";
      console.log("Title is bad");
      return false;
    }
    if (titleValue.length < 2) {
      titleError.innerHTML = "Title is too short";
      titleError.style.visibility = "visible";
      console.log("Title is bad");
      return false;
    }
    titleError.style.visibility = "hidden";
    console.log("Title is ok");
    return true;
  })();

  // Description Validation
  var descriptionValidation = (function() {
    var descriptionValue = decriptionInput;
    if (descriptionValue === "") {
      descriptionError.innerHTML = "Description can't be empty";
      descriptionError.style.visibility = "visible";
      console.log("Description is bad");
      return false;
    }
    if (descriptionValue.length < 4) {
      descriptionError.innerHTML = "Description is too short";
      descriptionError.style.visibility = "visible";
      console.log("Description is bad");
      return false;
    }
    descriptionError.style.visibility = "hidden";
    console.log("Description is ok");
    return true;
  })();

  // Date Validation
  var dateValidation = (function() {
    var dateValue = dateInput;
    if (!isNaN(dateValue) || dateValue === "") {
      dateError.innerHTML = "Please specify date and time";
      dateError.style.visibility = "visible";
      console.log("Date is bad");
      return false;
    }

    if (Date.parse(dateValue) < Date.now()) {
      dateError.innerHTML = "Date and Time cannot be in the past";
      dateError.style.visibility = "visible";
      console.log("Date is bad");
      return false;
    }

    if (Date.parse(dateValue) - 300000 < Date.now()) {
      dateError.innerHTML = "Can only be set to 5 minutes from now";
      dateError.style.visibility = "visible";
      console.log("Date is bad");
      return false;
    }

    if (Date.parse(dateValue) > 1893456000000) {
      dateError.innerHTML = "Date have to be before year 2030";
      dateError.style.visibility = "visible";
      console.log("Date is bad");
      return false;
    }

    if (isNaN(Date.parse(dateValue))) {
      dateError.innerHTML = "Please enter a real date and time";
      dateError.style.visibility = "visible";
      console.log("Date is bad");
      return false;
    }

    dateError.style.visibility = "hidden";
    console.log("Date is ok");
    return true;
  })();

  if (!titleValidation || !descriptionValidation || !dateValidation) {
    return false;
  }
  return true;
}

//-------- CREATING NOTE FUNCTION ---------------//
function addNote(titleInput, decriptionInput, dateInput, colorInput, animationInput, skipValidation, idInput, position) {

  // Skipping validation option for localStorage restoration
  if (!skipValidation) {
    // If activation passes continus on..
    if (!noteValidation(titleInput, decriptionInput, dateInput)) {
      // prevents closure of the modal if the validation check failed
      $("#input-modal").one('hide.bs.modal', function (e) {
        e.preventDefault();
      });
      return;
    }
  }

  var innerDiv = document.getElementById("inner-board");
  var noteDiv = document.createElement("div");
  noteDiv.className = "note wscroll";
  noteDiv.style.zIndex = globalCounter;
  noteDiv.style.backgroundColor = colorInput;
  noteDiv.style.animationName = animationInput;

  // Saving positions
  if (typeof position !== 'undefined') {
    // noteDiv.style.left = position.left + 'px';
    // noteDiv.style.top = position.top + 'px';
        $(noteDiv).css(position);
      
  }


  // Avoiding id's added from DOM to repeat id's from localStorage
  if (!skipValidation) {
    for (var i = 50; i > 0; i--) {
      if (document.getElementById(i) !== null) {
        globalCounter = parseInt(document.getElementById(i).id);
        break;
      }
    }
    noteDiv.id = globalCounter += 1;
  } else {
    noteDiv.id = idInput; // localStorage restoration command
  }

  // Creating trash button
  var trash = document.createElement("div");
  trash.className = "trash-button glyphicon glyphicon-trash";
  trash.addEventListener("click", function () {
    delete notes['note' + this.parentNode.id]; // took two hours to figure out :)
    this.parentNode.style.animationName = "rotateOutDownRight";
    this.parentNode.style.animationDuration = "1s";
    this.parentNode.style.animationPlayState = "running";
    this.parentNode.style.zIndex = this.parentNode.style.zIndex + 1;
    setTimeout(function () {
      trash.parentNode.parentNode.removeChild(this.parentNode);
    }.bind(this), 950);
  });

  // Adding Title to the note
  var title = document.createElement("div");
  title.className = "title";
  title.innerHTML = titleInput;

  // Adding description to the note
  var description = document.createElement("div");
  description.className = "description wscroll";
  description.innerHTML = decriptionInput;

  // Adding date to the note
  var date = document.createElement("div");
  date.className = "date";
  date.innerHTML = dateInput;

  // Assembling the note
  noteDiv.appendChild(trash);
  noteDiv.appendChild(title);
  noteDiv.appendChild(description);
  noteDiv.appendChild(date);
  innerDiv.insertBefore(noteDiv, innerDiv.childNodes[0]);


  $(noteDiv).draggable({
    containment: "#inner-board",
    stack: ".note",
    handle: title,
    stop: function (event, ui) {
      notes['note' + this.id].position = ui.position;
      notes['note' + this.id].position["z-index"] = noteDiv.style.zIndex;
    }
  });


  // Defining note's objects
  if (!skipValidation) {
    notes['note' + globalCounter] = {
      id: noteDiv.id,
      title: title.innerHTML,
      description: description.innerHTML,
      date: date.innerHTML,
      color: colorInput,
    };
  }
  clearInputValues();
}

              
            
!
999px

Console