<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.stickit/0.8.0/backbone.stickit.min.js"></script>
<script src="main.js"></script>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<div id="Menu"></div>
<ol id="Items"></ol>
<div id="main"></div>
</body>
</html>
(function($){
'use strict';
var Data = Backbone.Model.extend({
defaults: {
title: "Default Title"
},
});
var ItemForm = Backbone.View.extend({
template: _.template("<p>Your title: <%= title %></p><input name='title' value=<%= title %> /> <button name='close'>Close</button>"),
events: {
'click [name=close]':'closeEditForm'
},
bindings: {
'input[name=title]': {
observe: 'title',
events: ['blur']
}
},
initialize: function () {
this.listenTo(this.model,'change',this.render);
},
render: function() {
this.$el.html( this.template( this.model.toJSON() ) );
this.stickit();
return this;
},
closeEditForm: function () {
// this.undelegateEvents();
this.unstickit();
this.remove();
delete this.$el; // Delete the jQuery wrapped object variable
delete this.el; // Delete the variable reference to this node
}
});
var Item = Backbone.View.extend({
tagName: 'li',
template: _.template("<%=title %> <button name='removeItem'>Remove</button> <button name='editItem'>Edit</button>"),
events: {
'click [name=removeItem]':'removeItem',
'click [name=editItem]':'editItem'
},
initialize: function () {
this.listenTo(this.model,'change',this.render);
this.render();
},
render: function() {
this.$el.html( this.template( this.model.toJSON() ) );
this.stickit();
return this;
},
removeItem: function () {
// this.undelegateEvents();
this.unstickit();
this.remove();
delete this.$el; // Delete the jQuery wrapped object variable
delete this.el; // Delete the variable reference to this node
},
editItem: function() {
$('#main').append( new ItemForm({model: this.model }).render().el );
}
});
var Menu = Backbone.View.extend({
el: '#Menu',
template: "<button name='add'>ADD NEW</button>",
events: {
'click [name=add]': '_add'
},
initialize: function() {
this.render();
},
render: function(){
this.$el.html( this.template );
return this;
},
_add: function(){
var item = new Item({
model: new Data()
});
$('#Items').append( item.el );
}
});
$(document).ready(function() {
var manu = new Menu();
});
})(jQuery);
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |