This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Exercise</title> | |
<link rel="stylesheet" href="style/jquery.mobile-1.0.css" /> | |
<script src="js/vendor/jquery-1.6.4.min.js"></script> | |
<script src="js/vendor/jquery.mobile-1.0.min.js"></script> | |
<script src="js/vendor/underscore.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id":1, | |
"date": "12/12/2011", | |
"type": "Run", | |
"distance": "3 miles", | |
"comments": "This was really hard", | |
"minutes": 36 | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-role="page" id="activities"> | |
<div data-role="header"> | |
<h1>Activities</h1> | |
<a href="#" data-role="button" data-icon="add" id="add-button">Add</a> | |
</div> | |
<div data-role="content"> | |
<!-- the contents of the list view will be rendered via the backbone view --> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exercise.Activity = Backbone.Model.extend({ | |
}); | |
exercise.Activities = Backbone.Collection.extend({ | |
model: exercise.Activity, | |
url: "exercise.json" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exercise.initData = function(){ | |
exercise.activities = new exercise.Activities(); | |
exercise.activities.fetch({async: false}); // use async false to have the app wait for data before rendering the list | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/template" id="activity-list-item-template"> | |
<li><a href="#activity-details" identifier="<%= id %>"><%= date %> - <%= type %></a></li> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exercise.ActivityListView = Backbone.View.extend({ | |
tagName: 'ul', | |
id: 'activities-list', | |
attributes: {"data-role": 'listview'}, | |
initialize: function() { | |
this.template = _.template($('#activity-list-item-template').html()); | |
}, | |
render: function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#activities').live('pageinit', function(event){ | |
var activitiesListContainer = $('#activities').find(":jqmData(role='content')"), | |
activitiesListView; | |
exercise.initData(); | |
activitiesListView = new exercise.ActivityListView({collection: exercise.activities, viewContainer: activitiesListContainer}); | |
activitiesListView.render(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add: function(item) { | |
var activitiesList = $('#activities-list'), | |
template = this.template; | |
activitiesList.append(template(item.toJSON())); | |
activitiesList.listview('refresh'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#add-button').live('click', function(){ | |
exercise.activities.add({id: 6, date: '12/15/2011', type: 'Walk', distance: '2 miles', comments: 'Wow...that was easy.'}); | |
}); |
OlderNewer