JSFiddle - React, Tailwind, and code Playground

by the_archer

HTML

<link rel="stylesheet" href="http://backbonejs.org/examples/todos/todos.css">
<script src="http://backbonejs.org/test/vendor/json2.js"></script>
<script src="http://backbonejs.org/test/vendor/jquery.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<script src="https://rawgit.com/mozilla/localForage/master/dist/localforage.min.js"></script>
<script src="https://rawgit.com/mozilla/localForage-backbone/master/dist/localforage.backbone.min.js"></script>
<body>
    <div id="todoapp">
        <header>
             <h1>Todos</h1>

            <input id="new-todo" type="text" placeholder="What needs to be done?">
        </header>
        <section id="main">
            <input id="toggle-all" type="checkbox">
            <label for="toggle-all">Mark all as complete</label>
            <ul id="todo-list"></ul>
        </section>
        <footer> <a id="clear-completed">Clear completed</a>

            <div id="todo-count"></div>
        </footer>
    </div>
    <div id="instructions">Double-click to edit a todo.</div>
    <div id="credits">Created by
        <br /> <a href="http://jgn.me/">J&eacute;r&ocirc;me Gravel-Niquet</a>.
        <br />Rewritten by: <a href="http://addyosmani.github.com/todomvc">TodoMVC</a>.</div>
</body>

  <!-- Templates -->

  <script type="text/template" id="item-template">
    <div class="view">
      <input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
      <label><%- title %></label>
      <a class="destroy"></a>
    </div>
    <input class="edit" type="text" value="<%- title %>" />
  </script>

  <script type="text/template" id="stats-template">
    <% if (done) { %>
      <a id="clear-completed">Clear <%= done %> completed <%= done == 1 ? 'item' : 'items' %></a>
    <% } %>
    <div class="todo-count"><b><%= remaining %></b> <%= remaining == 1 ? 'item' : 'items' %> left</div>
  </script>

JavaScript

// Load the application once the DOM is ready, using `jQuery.ready`:
$(function () {

    //For easy inspection.
    localforage.setDriver('localStorageWrapper');

    // Todo Model
    // ----------

    // Our basic **Todo** model has `title`, `order`, and `done` attributes.
    var Todo = Backbone.Model.extend({

        sync: Backbone.localforage.sync('Item'),

        // Default attributes for the todo item.
        defaults: function () {
            return {
                title: "empty todo...",
                order: Todos.nextOrder(),
                done: false
            };
        },

        // Toggle the `done` state of this todo item.
        toggle: function () {
            this.save({
                done: !this.get("done")
            });
        }

    });

    // Todo Collection
    // ---------------

    // The collection of todos is backed by *localStorage* instead of a remote
    // server.
    var TodoList = Backbone.Collection.extend({

        // Reference to this collection's model.
        model: Todo,

        //Save all models under the 'ItemCollection' namespace
        sync: Backbone.localforage.sync('ItemCollection'),

        // Filter down the list of all todo items that are finished.
        done: function () {
            return this.where({
                done: true
            });
        },

        // Filter down the list to only todo items that are still not finished.
        remaining: function () {
            return this.where({
                done: false
            });
        },

        // We keep the Todos in sequential order, despite being saved by unordered
        // GUID in the database. This generates the next order number for new items.
        nextOrder: function () {
            if (!this.length) return 1;
            return this.last().get('order') + 1;
        },

        // Todos are sorted by their original insertion order.
        comparator: 'order'

    });

    // Create our global...