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

              
                <body>
  <div class="container">
    <header class="todo-header">
      <h3>Sample Todo App</h3>
    </header>
    <section class="panel">
      <h3>할 일 추가하기</h3>
      <form class="new-todo">
        <input type="text" id="todo-title" placeholder="할 일을 입력하세요!"> 
        <button class="btn btn-add pull-right">추가</button>
      </form>
    </section>
    <section class="panel">
      <h3>해야 할 일</h3>
      <ul class="todos-inprogress">
        <!-- 반복되는 부분 -->        
      </ul>
    </section>
    <section class="panel">
      <h3>완료한 일<button class="btn btn-default inline pull-right todo-complete-clear-button">비우기</button></h3>
      <ul class="todos todos-completed">
        <!-- 반복되는 부분 -->        
      </ul>
    </section>
    <aside class="panel todo-info">
      <strong class="todo-total-count">3</strong>개 중 <strong class="todo-complete-count">2</strong>개를 완료했습니다.
    </aside>
  </div>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="script.js"></script>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                'use strict';
(function($){
  var todos = [];
  
  // localStorage에서 저장된 todos 로딩
  if(window.localStorage && window.localStorage.todos !== undefined){
    todos = JSON.parse(window.localStorage.todos);
    console.log(localStorage.todos);
    console.log(todos.length)
  }
  
  function sync(){
    window.localStorage.todos = JSON.stringify(todos);  
    console.log(localStorage.todos);
  }
  
  function updateTodoInfo(){
    var todoCompleteCount = 0;
    for(var i = 0; i < todos.length; i++){
      if(todos[i].isComplete){
        todoCompleteCount = todoCompleteCount + 1;
      }
    }
    
    // dom 접근해서 값 변경
    $('.todo-complete-count').text(todoCompleteCount);
    $('.todo-total-count').text(todos.length);
  }
  
  $(document).ready(function(){
    // todos render
    for(var i = 0; i < todos.length; i++){
      if(todos[i].isComplete){
        $('.todos-completed').append(
        '<li class="panel todo" id="todo-' + todos[i].id + '">' +
          todos[i].title + 
        '</li>'
        );
      }else{
        $('.todos-inprogress').append(
          '<li class="panel todo" id="todo-' + todos[i].id + '">' +
            '<label>' +
              '<input type="checkbox" class="todo-complete">' + todos[i].title + 
            '</label>' +
            '<button class="btn btn-remove pull-right">삭제</button>' +
          '</li>'
          );  
      } 
    }
    updateTodoInfo();
    
    // add event binding
    $('.new-todo').on('submit', function(event){
      var $todoTitle = $('#todo-title');
      var todoTitle = $todoTitle.val();
      var todo = {
        title: todoTitle, 
        id: new Date().getTime(),
        isComplete: false
      };
      $('.todos-inprogress').append(
        '<li class="panel todo" id="todo-' + todo.id + '">' +
          '<label>' +
            '<input type="checkbox" class="todo-complete">' + todo.title + 
          '</label>' +
          '<button class="btn btn-remove pull-right">삭제</button>' +
        '</li>'  
      );
      $todoTitle.val('');
      
      todos.push(todo);
      sync();
      updateTodoInfo();
      
      event.preventDefault();
    });
    
    // todo complete event
    $('.todos-inprogress').on('click', '.todo-complete', function(){
      var $completeTodo = $(this).parents('.todo');
      var todoId = $completeTodo.attr('id').replace('todo-', '');
      var todo, i;
      
      // 완료 처리
      for(i = 0; i < todos.length; i++){
        todo = todos[i];
        if(todo.id === parseInt(todoId)){
          todo.isComplete = true;
          break;
        }
      }
      
      $completeTodo.find('input[type=checkbox]').remove();
      $completeTodo.find('.btn-remove').remove();
      $('.todos-completed').append($completeTodo);
      
      sync();
      updateTodoInfo();
    });
    
    // remove event binding
    $('.todos-inprogress').on('click', '.btn-remove', function(){
      var $deleteTodo = $(this).parents('.todo');
      var todoId = $deleteTodo.attr('id').replace('todo-', '');
      $(this).parents('.todo').remove();
      
      for(i = 0; i < todos.length; i++){
        todo = todos[i];
        if(todo.id === parseInt(todoId)){
          todos.splice(i, 1);
          break;
        }
      }
      
      sync();
      updateTodoInfo();
    });
   
    $('.todo').on('click', '.btn-remove', function(){
      var $removeTargetTodo = $(this).parents('.todo');
      todos.splice($removeTargetTodo.index(), 1);
      $removeTargetTodo.remove();
      
      sync();
      updateTodoInfo();      
    });
    // completed remove all event
    $('.todo-complete-clear-button').on('click', function(){
      var inprogressTodos = [], i;
      for(i = 0; i < todos.length; i++){
        if(!todos[i].isComplete){
          inprogressTodos.push(todos[i]);
        }
      }
      
      todos = inprogressTodos;
      
      // html 비우기
      $('.todos-completed').html('');
      
      sync();
      updateTodoInfo();
    });
  });
})(jQuery);
  
              
            
!
999px

Console