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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console