Pen Settings

HTML

CSS

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

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

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.

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

              
                
<main id="calendar">
  <header id="header" class="header">
    <div class="header__arrow arrow--left">
      <div class="arrow__circle">
        <div class="arrow__arrow">
          <div class="arrow__pipe"></div>
          <div class="arrow__triangle"></div>
        </div>
      </div>
    </div>
    <div class="header__main-date">
      <div class="main-date__container"><span class="main-date__container__day"></span>
        <div class="day__month__wrapper"><span class="main-date__container__month"></span><span class="main-date__container__year"></span></div>
      </div>
    </div>
    <div class="header__arrow arrow--right">
      <div class="arrow__circle">
        <div class="arrow__arrow">
          <div class="arrow__pipe"></div>
          <div class="arrow__triangle"></div>
        </div>
      </div>
    </div>
  </header>
  <section id="days" class="days"></section>
  <section id="daysgrid" class="daysgrid"></section>
</main>

<script type="text/x-handlebars-template" id="days_template">
  {{#each days}}
  <div class="days__day"><span>{{this}}</span></div>
  {{/each}}
</script>

<script type="text/x-handlebars-template" id="cal">
  {{#each days}}
    {{#unless this.first}}
      {{#if this.newWeek}}
      </div>
      {{/if}}
    {{/unless}}
    {{#if this.newWeek}}
    <div class="daysgrid__week">
    {{/if}}
    {{#if this.today}}
        <div class="daysgrid__day daysgrid__day--today" data-date="{{this.date}}">
    {{else}}
        <div class="daysgrid__day " data-date="{{this.date}}">
    {{/if}}
        {{#if this.has_tasks}}
          <div class="day__status day__status--undone"></div>
        {{else if this.done}}
          <div class="day__status day__status--done"></div>
        {{else}}
          <div class="day__status"></div>
        {{/if}}
          <div class="day__number">{{this.number}}</div>
      </div>
  {{/each}}
</script>

<script type="text/x-handlebars-template" id="tasks">
  <div class="daysgrid__tasks" data-tasksfor="{{this.date}}">
    <ul class="tasks">
      {{#each tasks}}
      <li class="tasks__task" data-taskid="{{this.id}}">
        {{#if this.done}}
          <input type="checkbox" id="{{this.id}}" checked="true"/>
        {{else}}
          <input type="checkbox" id="{{this.id}}" />
        {{/if}}
        <label for="{{this.id}}">{{this.title}}</label>
        <button class="btn"><i class="cross"></i></button>
      </li>
      {{/each}}
    </ul>
    <input type="text" id="task_input" placeholder="Add task" name="task"/>
  </div>
</script>

<script type="text/x-handlebars-template" id="task">
  <li class="tasks__task">
    <input type="checkbox" id="{{this.id}}" />
    <label for="{{this.id}}">{{this.title}}</label>
    <button class="btn"><i class="cross"></i></button>
  </li>
</script>

              
            
!

CSS

              
                @import bourbon
@import neat
  
$peterRiver: #4aa3df
$wetAsphalt: #34495e
$belizaHole: #2980b9
$midnightBlue: #2c3e50
$clouds: #ecf0f1
$silver: #bdc3c7
$alzarin: #e74c3c
$emerald: #2ecc71

html,
body
  +size(100vw 100vh)
  max-width: 100%
  color: $clouds
  font-family: "Source Sans Pro"
  background: #eee

#calendar
  min-width: em(260)
  box-shadow: 0px 0px 8px 0px rgba($midnightBlue, 0.4)
  background: #fff

// ==================
// HEADER
// ==================

.header
  +size(100% 6em)
  +display(table)
  background: $peterRiver

.header__main-date,
.header__arrow,
  +display(table-cell)
  text-align: center
  vertical-align: middle

.header__arrow
  +size(15% auto)
  
.main-date__container
  +size(70% auto)
  +margin(0 auto)
  +clearfix

.main-date__container__day
  font-size: modular-scale(4)
  display: inline-block

.day__month__wrapper
  display: inline-block

.main-date__container__month,
.main-date__container__year
  font-size: 1.2em
  text-transform: uppercase
  display: block

.arrow__arrow
  +clearfix
  +position(absolute, 50% null null 50%)
  +transform(translate3d(-50%, -50%, 0))
  
.arrow--left
  text-align: right
  
.arrow--right
  text-align: left
  
.arrow__circle
  +display(inline-block)
  +position(relative)
  +size(2em 2em)
  +background($clouds)
  cursor: pointer
  border-radius: 50%
  
.arrow__pipe
  +size(em(8) em(6))
  +margin(em(5) 0 0 0)
  background: $belizaHole
  
.arrow--left
  .arrow__pipe
    float: right
  .arrow__triangle
    float: right
    +triangle(em(16), $belizaHole, left)
      
.arrow--right
  .arrow__pipe
    float: left
  .arrow__triangle
    float: left
    +triangle(em(16), $belizaHole, right)

      
// ==================
//  DAY NAMES ROW
// ==================

.days
  +size(100% 2.5em)
  +display(table)
  text-align: center
  background: $emerald

.days__day
  +size(14.28571% auto)
  display: table-cell
  vertical-align: middle
  text-transform: capitalize
  
      
// ===================
// DAYS GRID
// ===================

.daysgrid
  color: $midnightBlue

.daysgrid__week
  +clearfix

.daysgrid__day
  +display(table)
  +size(14.28571% 3em)
  +position(relative)
  float: left
  cursor: pointer
  text-align: center

.day__number
  +display(table-cell)
  vertical-align: middle

.day__status
  +position(absolute, 10% 0 0 10%)
  +size(em(10) em(10))
  border-radius: 50%
  background: none
  
.daysgrid__day--today
  &:after
    content: ""
    +position(absolute, 50% null null 50%)
    +transform(translate3d(-50%, -50%, 0))
    +size(2em 2em)
    border-radius: 50%
    z-index: -1
    background: rgba($silver, 0.3)
  
.daysgrid__tasks
  +clearfix
  position: relative
  width: 100%
  min-height: 6em
  background: $clouds
  box-shadow: inset 0px 0px 1px 0px rgba($midnightBlue, 0.1)
  
  input[type="text"]
    +size(70% null)
    +margin(0.5em 15%)
    +display(block)
    +position(relative, null null 1em null)
    +padding(0.5em)
    font-size: modular-scale(0)
    border: 0
    outline: 0
    background: none
    border-bottom: 2px solid $silver
    
  ul
    list-tyle: none
    width: 80%
    margin: 0 auto
    padding: 1em 0
    
    li
      +clearfix
      position: relative
      display: block
      
      font-size: modular-scale(0)
      padding: 0.1em
      color: $wetAsphalt
      
      label
        width: 80%
        display: inline-block
        float: left
      
      input[type="checkbox"]
        position: relative
        display: inline-block
        float: left

.btn
  position: relative
  padding: 0.7em
  font-size: modular-scale(-1)
  background: none
  border: 0
  cursor: pointer
  opacity: 0.6
  float: right

  &:hover
    opacity: 1
    
.cross
  position: relative
  display: block
  
  &:after, &:before
    content: ""
    position: absolute
    +size(15px 1px)
    left: -8px
    background: $midnightBlue
    
  &:after
    +transform(rotate(45deg))
  
  &:before
    +transform(rotate(-45deg))
  
.day__status--taskopen
  &:after
    content: ""
    +display(block)
    +position(absolute, null null 0 50%)
    +transform(translateX(-50%))
    +triangle(em(12px), $clouds, up)

.day__status--done
  background: $emerald
.day__status--undone
  background: $alzarin

// =============
// TASKS
// =============

#calendar
  +media(min-width em(480), 12)
    +position(absolute, 50% null null 50%)
    +transform(perspective(1px) translateZ(0) translate(-50%, -50%))
    width: em(480)
              
            
!

JS

              
                /** 
 ** SPAGHETTI :x
 ** REWRITE WITH OBSERVER or SUBSCRIBE / PUBLISH
 ** OO MAYBE?
 **/

(function () {
  window.addEventListener('load', documentReady, false);
  
  function documentReady(event) {
    window.removeEventListener('load', documentReady, false);
    main();
  }
  
  function setHeader(date) {
    var header = document.getElementById('header');
    var now = moment(date);
    var left = header.querySelector('.arrow--left');
    var right = header.querySelector('.arrow--right');

    left.dataset.next = now.subtract(1, 'month').format('YYYY-MM-DD');
    now.add(1, 'month');
    right.dataset.next = now.add(1, 'month').format('YYYY-MM-DD');
    now.subtract(1, 'month');

    header.querySelector('.main-date__container__day').textContent = now.date();
    header.querySelector('.main-date__container__month').textContent = now.format('MMMM');
    header.querySelector('.main-date__container__year').textContent = now.year();
  }
  
  function getTasks(date) {
    var all = JSON.parse(localStorage.getItem('tasks'));
    if (all) {
      return all[date];
    }
  }
  
  function createCalendar(date, container) {
    var date = moment(date);
    var now_date = moment();
    
    var days = date.daysInMonth();
    var firstDay = date.set('date', 1).isoWeekday();
    var skipDays = firstDay - 1;
    var calTemplate = Handlebars.compile(document.getElementById('cal').innerHTML);
    var data = { days: [] }
    
    for(i = 1; i <= days + skipDays; i++) {
      var day = {};
      if (i === 1) day.first = true;
      if (i === days) day.last = true;
      if (((i-1) % 7) === 0) {
        day.newWeek = true;
      }
      if (i - skipDays > 0) {
        day.number = i - skipDays;
        var date_string = date.format('YYYY-MM-DD');
        day.date = date_string;
        if (now_date.isSame(date, 'day')) {
          day.today = true;
        }
        var tasks = getTasks(date.format('YYYY-MM-DD'));
        if (tasks) {
          var undone = tasks.filter(function (t) { return t.done === false; });
          if (undone.length > 0) {
              day.has_tasks = true;
              day.done = false;
          } else {
            day.has_tasks = false;
            day.done = true;
          }
        } else {
          day.has_tasks = false;
          day.done = false;
        }
        date.add(1, 'day');
      }
      data.days.push(day);
    }
    container.innerHTML = calTemplate(data);
  }
  
  function createTaskContainer(date) {
    var container = document.createElement('div');
    var tasksTemplate = Handlebars.compile(document.getElementById('tasks').innerHTML);
    
    var data = { tasks: getTasks(date), date: date };
    container.innerHTML = tasksTemplate(data);
    
    return container.firstElementChild;
  }
  
  function daysGridClick(event) {
    var day = parseInt(event.target.textContent);
    var inputEventBind;
    
    if (day) {
      var date = event.target.offsetParent.dataset.date;
      var container = createTaskContainer(date);

      if (!event.target.classList.contains('day__status--taskopen')) {
        [].slice.call(document.querySelectorAll('.day__status--taskopen')).forEach(function (el) {
          el.classList.remove('day__status--taskopen');
        });
        [].slice.call(document.querySelectorAll('.daysgrid__tasks')).forEach(function (el) {
          el.parentNode.removeChild(el);
        });
        inputEventBind = bindInput(container);
        event.target.classList.add('day__status--taskopen');
        event.target.parentNode.parentNode.parentNode.insertBefore(container, event.target.parentNode.parentNode.nextSibling);
      } else {
        if (inputEventBind) inputEventBind.removeEventListener('keyup', inputKeyUp, false);
        event.target.classList.remove('day__status--taskopen')
        event.target.parentNode.parentNode.parentNode.removeChild(event.target.parentNode.parentNode.nextSibling);
      }
    } else if (event.target.classList.contains('btn')) {
      var date = event.target.parentNode.parentNode.parentNode.dataset.tasksfor;
      var id = event.target.parentNode.dataset.taskid;
      var ul = event.target.parentNode.parentNode;
      
      ul.removeChild(event.target.parentNode);

      var lis = getLiData(ul);
      updateStorage(date, lis);
      updateDay(date, lis);
    
    } else if (event.target.type === "checkbox") {
      var date = event.target.parentNode.parentNode.parentNode.dataset.tasksfor;
      var id = event.target.parentNode.dataset.taskid;
      var ul = event.target.parentNode.parentNode;

      var lis = getLiData(ul);
      updateStorage(date, lis);
      updateDay(date, lis);     
    }
  }
  
  function getLiData(ul) {
    var data = [];
    var lis = [].slice.call(ul.querySelectorAll('li'));
    
    lis.forEach(function(li) {
      var temp = {};
      if (!!li.querySelector('input').checked === true) temp.done = true;
      else temp.done = false;
      temp.id = li.querySelector('input').id;
      temp.title = li.querySelector('label').textContent;
      data.push(temp);
    });

    return data;
  }
  
  function updateStorage(date, lis) {
    var data = (JSON.parse(localStorage.getItem('tasks')) || {});
    if (lis.length === 0) delete data[date];
    else data[date] = lis;
    localStorage.setItem('tasks', JSON.stringify(data));    
  }
  
  function updateDay(date, lis) {
    var day = document.querySelector('div[data-date="' + date + '"]');
    var status = day.querySelector('.day__status');
    var undone = lis.filter(function (li) { return li.done === false; });
    
    status.classList.remove('day__status--done');
    status.classList.remove('day__status--undone');
    
    if (lis.length > 0) {
      if (undone.length > 0) {
        status.classList.remove('day__status--done');
        status.classList.add('day__status--undone');
      } else {
        status.classList.remove('day__status--undone');
        status.classList.add('day__status--done');
      }
    }
  }
  
  function loadMonth(event) {
    var newDate = this.dataset.next;
    var daysGrid = document.getElementById('daysgrid');
    setHeader(newDate);
    createCalendar(newDate, daysGrid);
  }
  
  function bindInput(taskList) {
    var input = taskList.querySelector('#task_input');
    input.addEventListener('keyup', inputKeyUp, false);
    return input;
  }
  
  function createId() {
    return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 8);
  }
  
  function addTask(container, title) {
    var cont = document.createElement('ul');
    var date = container.parentNode.dataset.tasksfor;
    var taskTemplate = Handlebars.compile(document.getElementById('task').innerHTML);
    var id = createId();

    cont.innerHTML = taskTemplate({id: id, title: title, done: false});
    container.appendChild(cont.firstElementChild);

    var lis = getLiData(container);
    updateStorage(date, lis)
    updateDay(date, lis);
  }
  
  function inputKeyUp(event) {
    var taskList = event.target.parentNode.querySelector('ul');
    var text;
    
    if (event.keyCode === 0x0D) {
      event.preventDefault();
      text = event.target.value;
      event.target.value = '';
      if (!!text) addTask(taskList, text);
    }
  }
  
  function createDays(container, days) {
    var daysTemplate = Handlebars.compile(document.getElementById('days_template').innerHTML);
    container.innerHTML = daysTemplate({ days: days });
  }
  
  function main() {
    var data = new Date();
    var daysGrid = document.getElementById('daysgrid');
    var prev = document.querySelector('.arrow--left');
    var next = document.querySelector('.arrow--right');
    
    moment.locale(window.navigator.language || 'en');
    var days = moment.weekdaysShort();
    var first_day = days[0];
    days = days.slice(1).concat(first_day);

    daysGrid.addEventListener('click', daysGridClick, false);
    prev.addEventListener('click', loadMonth, false);
    next.addEventListener('click', loadMonth, false);
    
    setHeader(data);
    createDays(document.getElementById('days'), days);
    createCalendar(data, daysGrid);
  };
}());



              
            
!
999px

Console