define( ['jquery', 'backbone', 'collections/list', 'views/task', 'data/demo' ], function ( $, Backbone, List, TaskView, demoData ) { var ListView = Backbone.View.extend({ el: $("#main .children"), events: { 'click #add': 'addTask' }, initialize: function () { Tasks = this.collection = new List(); this.listenTo(this.collection, 'add', this.renderTask); /** Load demo data and warn users **/ function loadDemoData() { for (var i = 0; i < demoData.length; i++) { var task = Tasks.add(demoData[i]); task.save(); } } function success(data) { // load demo data if the server returns nothing if (data.length === 0) loadDemoData(); } this.collection.fetch({ success: success, error: function () { // switch to localforage database if server isn't present window.hackflowyOffline=true; $('#header').append('