GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fullstack-javascript/board/app.js at master · leroyg/fullstack-javascript Expand file tree/ Copy pathapp.jsMore file actions 101 lines (93 loc) · 2.26 KB / Copy pathapp.jsFile metadata and controls101 lines (93 loc) · 2.26 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 /* Rapid Prototyping with JS is a JavaScript and Node.js book that will teach you how to build mobile and web apps fast. — Read more at http://rapidprototypingwithjs.com. */ // var URL = 'http://localhost:5000/' var URL ='http://your-app-name.herokuapp.com/' require([ 'libs/text!header.html', 'libs/text!home.html', 'libs/text!footer.html'], function ( headerTpl, homeTpl, footerTpl) { var ApplicationRouter = Backbone.Router.extend({ routes: { '': 'home', '*actions': 'home' }, initialize: function() { this.headerView = new HeaderView() this.headerView.render() this.footerView = new FooterView() this.footerView.render() }, home: function() { this.homeView = new HomeView() this.homeView.render() } }) HeaderView = Backbone.View.extend({ el: '#header', templateFileName: 'header.html', template: headerTpl, initialize: function() { }, render: function() { $(this.el).html(_.template(this.template)) } }) FooterView = Backbone.View.extend({ el: '#footer', template: footerTpl, render: function() { this.$el.html(_.template(this.template)) } }) Message = Backbone.Model.extend({ url: URL + 'messages/create.json' }) MessageBoard = Backbone.Collection.extend ({ model: Message, url: URL + 'messages/list.json' }) HomeView = Backbone.View.extend({ el: '#content', template: homeTpl, events: { 'click #send': 'saveMessage' }, initialize: function() { this.collection = new MessageBoard() this.collection.bind('all', this.render, this) this.collection.fetch() this.collection.on('add', function(message) { message.save(null, { success: function(message) { console.log('saved '+message) }, error: function(message) { console.log('error') } }) console.log('saved'+message) }) }, saveMessage: function(){ var newMessageForm=$('#new-message') var username=newMessageForm.find('[name="username"]').val() var message=newMessageForm.find('[name="message"]').val() this.collection.add({ 'username': username, 'message': message }) }, render: function() { console.log(this.collection) $(this.el).html(_.template(this.template, this.collection)) } }) app = new ApplicationRouter() Backbone.history.start() }) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |