Hello Backbone.js

Size
3,017 Kb
Views
46,552

How do I make an hello backbone.js?

Via http://arturadib.com/hello-backbonejs/. What is a hello backbone.js? How do you make a hello backbone.js? This script and codes were developed by Christian Fleschhut on 11 August 2022, Thursday.

Hello Backbone.js Previews

Hello Backbone.js - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Hello Backbone.js</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <p> <small> via <a href='http://arturadib.com/hello-backbonejs/'> http://arturadib.com/hello-backbonejs/ </a> </small>
</p>
<div id='app'></div>
<script id='tpl_list' type='text/template'> <p> <button class='btn btn-sm btn-info' id='add'> Add list item </button> </p> <ul></ul>
</script>
<script id='tpl_list_item' type='text/template'> <span> <%= part1 %> <%= part2 %> <i class='swap fa fa-arrows-h'></i> <i class='delete fa fa-trash-o'></i> </span>
</script> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Hello Backbone.js - Script Codes CSS Codes

body { padding: 20px;
}
.swap,
.delete { cursor: pointer;
}

Hello Backbone.js - Script Codes JS Codes

(function($) { // Model var Item = Backbone.Model.extend({ defaults: { part1: 'hello', part2: 'world' } }); // Collection var List = Backbone.Collection.extend({ model: Item }); // Views var ItemView = Backbone.View.extend({ tagName: 'li', template: _.template($('#tpl_list_item').html()), events: { 'click .swap': 'swap', 'click .delete': 'remove' }, initialize: function() { _.bindAll(this, 'render', 'unrender', 'swap', 'remove'); this.model.on('change', this.render); this.model.on('remove', this.unrender); }, render: function() { this.$el.html(this.template(this.model.attributes)); return this; }, unrender: function() { this.$el.remove(); }, swap: function() { var swapped = { part1: this.model.get('part2'), part2: this.model.get('part1') }; this.model.set(swapped); }, remove: function() { this.model.destroy(); } }); var ListView = Backbone.View.extend({ el: $('#app'), template: _.template($('#tpl_list').html()), events: { 'click #add': 'addItem' }, initialize: function() { _.bindAll(this, 'render', 'addItem', 'appendItem'); this.collection = new List(); this.collection.on('add', this.appendItem); this.counter = 0; this.render(); }, render: function() { this.$el.append(this.template()); return this; }, addItem: function() { this.counter++; var item = new Item(); item.set({ part2: item.get('part2') + ' ' + this.counter }); this.collection.add(item); }, appendItem: function(item) { var itemView = new ItemView({ model: item }); $('ul', this.el).append(itemView.render().el); } }); var listView = new ListView();
})(jQuery);
Hello Backbone.js - Script Codes
Hello Backbone.js - Script Codes
Home Page Home
Developer Christian Fleschhut
Username cfleschhut
Uploaded August 11, 2022
Rating 3
Size 3,017 Kb
Views 46,552
Do you need developer help for Hello Backbone.js?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Christian Fleschhut (cfleschhut) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!