cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <section id="todoapp">
  <header id="header">
    <h1>todos</h1>
    <input id="new-todo" data-bind="enter: saveTodo, value: newTodo" placeholder="What needs to be done?" autofocus>
  </header>
  <section id="main" data-bind="attr: { class : isVisible }">
    <input id="toggle-all" type="checkbox" data-bind="events: { click: toggleAll }, checked: allCompleted">
    <label for="toggle-all">Mark all as complete</label>
    <ul id="todo-list" data-template="item-template" data-bind="source: todos"></ul>
  </section>
  <footer id="footer" class="hidden" data-bind="attr: { class: isVisible }">
    <span id="todo-count">
      <strong data-bind="text: activeCount"></strong>
      <span data-bind="text: activeCountText"></span> left
    </span>
    <ul id="filters">
      <li><a href="#/" data-bind="attr: { class: allFilterClass }">All</a></li>
      <li><a href="#/active" data-bind="attr: { class: activeFilterClass }">Active</a></li>
      <li><a href="#/completed" data-bind="attr: { class: completedFilterClass }">Completed</a></li>
    </ul>
    <button id="clear-completed" data-bind="click: destroyCompleted, visible: completedCount, text: clearCompletedText">
    </button>
  </footer>
</section>
<div id="info">
  <p>Double-click to edit a todo</p>
  <p>Credits <a href="https://github.com/bsatrom">Brandon Satrom</a>, <a href="https://github.com/burkeholland">Burke Holland</a>, <a href="https://github.com/akorchev">Atanas Korchev</a>, &amp; <a href="https://github.com/jbristowe">John Bristowe</a></p>
  <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</div>
<script type="text/template" id="item-template">
  <li data-bind="attr: { class: todoItemClass }">
    <div class="view">
      <input class="toggle" type="checkbox" data-bind="checked: completed, events: { change: sync }">
      <label data-bind="text: title, events: { dblclick: startEdit } "></label>
      <button class="destroy" data-bind="click: destroy">
      </button>
    </div>
    <input class="edit" data-bind="value: title, events: { blur: endEdit, change: endEdit }, enter: endEdit, escape: cancelEdit">
  </li>
</script>

            
          
!
            
              var app = app || {};

(function ($, kendo) {
	'use strict';

	var filterBase = {
		field: 'completed',
		operator: 'eq'
	};

	// Route object to manage filtering the todo item list
	var router = new kendo.Router();

	router.route('/', function () {
		app.todoData.filter({});
		app.todoViewModel.set('filter', '');
	});

	router.route('/active', function () {
		filterBase.value = false;
		app.todoData.filter(filterBase);
		app.todoViewModel.set('filter', 'active');
	});
	
	router.route('/completed', function () {
		filterBase.value = true;
		app.todoData.filter(filterBase);
		app.todoViewModel.set('filter', 'completed');
	});

	// Todo Model Object
	app.Todo = kendo.data.Model.define({
		id: 'id',
		fields: {
			id: { editable: false, nullable: true },
			title: { type: 'string' },
			completed: { type: 'boolean', nullable: false, defaultValue: false },
			edit: { type: 'boolean', nullable: false, defaultValue: false }
		}
	});

    app.todoData = new kendo.data.DataSource({
      autoSync: true,
      schema: {
        model: app.Todo
      },
      transport: {
        firebase: {
          url: "https://fiery-fire-4452.firebaseio.com/"
        }
      },
      type: "firebase"
	});

	// The core ViewModel for our todo app
	app.todoViewModel = kendo.observable({
		todos: app.todoData,
		filter: null,

		// Main element visibility handler
		isVisible: function () {
			return this.get('todos').data().length ? '' : 'hidden';
		},

		// new todo value
		newTodo: null,
		
		// Core CRUD Methods
		saveTodo: function () {
			var todos = this.get('todos');
			var newTodo = this.get('newTodo');

			var todo = new app.Todo({
				title: newTodo.trim(),
				completed: false,
				edit: false
			});

			todos.add(todo);

			this.set('newTodo', null);
		},

		toggleAll: function () {
			console.log("toggleAll");

			var completed = this.completedTodos().length === this.get('todos').data().length;
			
			console.log(completed);

			$.grep(this.get('todos').data(), function (el) {
				el.set('completed', !completed);
			});
		},
		startEdit: function (e) {
			e.data.set('edit', true);
			this.set('titleCache', e.data.get('title'));
			$(e.target).closest('li').find('input').focus();
		},
		endEdit: function (e) {
			var editData = e,
				title;

			if (e.data) {
				editData = e.data;
				title = e.data.get('title');

				// If the todo has a title, set it's edit property
				// to false. Otherwise, delete it.
				if (editData.title.trim()) {
					editData.set('title', title.trim());
				} else {
					this.destroy(e);
				}
			}

			editData.set('edit', false);
		},
		cancelEdit: function (e) {
			e.set('title', this.get('titleCache'));
			e.set('edit', false);
		},

		destroy: function (e) {
			this.todos.remove(e.data);
		},
		destroyCompleted: function () {
			$.each(this.completedTodos(), function (index, value) {
				this.todos.remove(value);
			}.bind(this));
		},

		// Methods for retrieving filtered todos and count values
		activeTodos: function () {
			return $.grep(this.get('todos').data(), function (el) {
				return !el.get('completed');
			});
		},
		activeCount: function () {
			return this.activeTodos().length;
		},
		completedTodos: function () {
			return $.grep(this.get('todos').data(), function (el) {
				return el.get('completed');
			});
		},
		completedCount: function () {
			return this.completedTodos().length;
		},

		allCompleted: false,
		
		// Text value bound methods
		activeCountText: function () {
			return this.activeCount() === 1 ? 'item' : 'items';
		},
		clearCompletedText: function () {
			return 'Clear completed (' + this.completedCount() + ')';
		},

		// Class attribute bound methods
		todoItemClass: function (item) {
			if (item.get('edit')) {
				return 'editing';
			}
			return (item.get('completed') ? 'completed' : 'active');
		},
		allFilterClass: function () {
			return this.get('filter') ? '' : 'selected';
		},
		activeFilterClass: function () {
			return this.get('filter') === 'active' ? 'selected' : '';
		},
		completedFilterClass: function () {
			return this.get('filter') === 'completed' ? 'selected' : '';
		}
	});

	// Bind the ViewModel to the todoapp DOM element
	kendo.bind($('#todoapp'), app.todoViewModel);
	router.start();

}($, kendo));
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console