cssAudio - Activefile-genericCSS - 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.

            
              <main class='container'>
  <h1>Jitter</h1>
  <p class='lead'>
    A simple Twitter-like single page demo application using Backbone.js
    <span class='small'>
      || by
      <a href='http://jannypie.github.io'>Jan Dennison</a>
    </span>
  </p>
  <hr>
  <div class='col-sm-4'>
    <h3>Add an Update</h3>
    <div class='well'>
      <form id='composeForm'>
        <div>
          <label for='new-post'>Compose</label>
          <!-- TODO: why does backbone break required? -->
          <textarea id='new-post' name='new-post' autofocus required ></textarea>
        </div>
        <div>
          <input id='add-jitter' type='submit' value='Submit' class="button">
        </div>
      </form>
    </div>
  </div>
  <div class='col-sm-8'>
    <h3>Jitterstream</h3>
    <div class='well' id='jitterstream-container'>
      <ul class='list-group' id='jitters-list'></ul>
    </div>
  </div>
</main>
<!-- Single Jitter Template -->
<script id='jitter-template' type='text/template'>
  <p class='jitter_template--text'>
    <img alt='User icon' class='jitter_template--image' src='http://i.imgur.com/q6QcOhY.png'>
    <%= content %>
  </p>
  <p class='small'>
    <%= username %>
  </p>
</script>
            
          
!
            
              label
  display: block

textarea
  width: 100%
  height: 5em

.small
  color: silver
  a
    color: silver
    border-bottom: 1px solid silver
    
.jitter_template--image
  float: left
  margin-right: 1em
  
            
          
!
            
              // app.js
$(function() {

  // models/jitter.js
  var Jitter = Backbone.Model.extend({
    defaults: {
      username: 'anonymous',
      content: ''
    }
  });

  // collections/jitters.js
  var JittersColl = Backbone.Collection.extend({
    model: Jitter
  });

  // views/jitter.js
  var JitterView = Backbone.View.extend({
    tagName: 'li',
    attributes: function() {
      return {
        class: 'list-group-item'
      };
    },
    template: _.template($("#jitter-template").html(), {}),
    initialize: function() {
      this.listenTo(this.model, 'change', this.render);
      this.container = $('#jitterstream-container');
    },
    render: function() {
      this.$el.html(this.template(this.model.attributes));
    }
  });

  // views/compose.js
  var ComposeView = Backbone.View.extend({
    el: $('#composeForm'),
    initialize: function() {
      this.render();
    },
    events: {
      "click #add-jitter": "addJitter"
    },
    addJitter: function(e) {
      e.preventDefault();
      var newContent = $('#new-post').val();
      var newJitter = new Jitter({
        content: newContent
      });
      jitterArray.add(newJitter);
      this.$el[0].reset();
    }
  });

  // views/stream.js
  // The main view of the application
  var StreamView = Backbone.View.extend({
    el: $('#jitters-list'),
    initialize: function() {
      this.listenTo(this.collection, 'add', this.addOne);
      this.container = $('#jitterstream-container');
    },
    addOne: function(jitter) {
      var view = new JitterView({
        model: jitter
      });
      view.render();
      this.$el.prepend(view.el);
      return this;
    },
    addAll: function() {
      this.collection.each(function(jitter) {
        this.addOne(jitter);
      }, this);

      return this;
    },
    render: function() {
      this.container.append(this.$el);
      this.addAll();

      return this;
    }
  });

  // seed data
  var jitterArray = new JittersColl([
    new Jitter({
      username: 'anonymous',
      content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    }),
    new Jitter({
      username: 'anonymous',
      content: 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
    }),
    new Jitter({
      username: 'anonymous',
      content: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
    }),
    new Jitter({
      username: 'anonymous',
      content: 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
    })
  ]);

  // init.js
  $(document).ready(function() {
    new StreamView({
      collection: jitterArray
    }).render();
    new ComposeView();
  });

});
            
          
!
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