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
# Mac OS X Finder and whatnot | |
.DS_Store | |
# XCode (and ancestors) per-user config (very noisy, and not relevant) | |
*.mode1 | |
*.mode1v3 | |
*.mode2v3 | |
*.perspective | |
*.perspectivev3 |
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
$('#activity-details').live('pagebeforeshow', function(){ | |
var activitiesDetailsContainer = $('#activity-details').find(":jqmData(role='content')"), | |
activityDetailsView, | |
activityId = $('#activity-details').jqmData('activityId'), | |
activityModel = exercise.activities.get(activityId); | |
activityDetailsView = new exercise.ActivityDetailsView({model: activityModel, viewContainer: activitiesDetailsContainer}); | |
activityDetailsView.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
activities.each(function(activity){ | |
var renderedItem = template(activity.toJSON()), | |
$renderedItem = $(renderedItem); //convert the html into an jQuery object | |
$renderedItem.jqmData('activityId', activity.get('id')); //set the data on it for use in the click event | |
$renderedItem.bind('click', function(){ | |
//set the activity id on the page element for use in the details pagebeforeshow event | |
$('#activity-details').jqmData('activityId', $(this).jqmData('activityId')); //'this' represents the element being clicked | |
}); | |
listView.append($renderedItem); | |
}); |
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.ActivityDetailsView = Backbone.View.extend({ | |
//since this template will render inside a div, we don't need to specify a tagname | |
initialize: function() { | |
this.template = _.template($('#activity-details-template').html()); | |
}, | |
render: function() { | |
var container = this.options.viewContainer, | |
activity = this.model, | |
renderedContent = this.template(this.model.toJSON()); |
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-details-template"> | |
<h3><%= type %></h3> | |
<ul data-role="listview" id="activitiy-fields" data-inset="true"> | |
<li>Date: <%= date %></li> | |
<li>Minutes: <%= minutes %></li> | |
<li>Distance: <%= distance %></li> | |
<li>Comments: <%= comments %></li> | |
</ul> | |
</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
<div data-role="page" id="activity-details" data-add-back-btn="true"> | |
<div data-role="header"> | |
<a href="#" data-role="button" data-icon="arrow-d" id="edit-activity-button" class="ui-btn-right">Edit</a> | |
<h1>Activity Details</h1> | |
</div> | |
<div data-role="content" id="activity-details-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.ActivityListView = Backbone.View.extend({ | |
tagName: 'ul', | |
id: 'activities-list', | |
attributes: {"data-role": 'listview'}, | |
initialize: function() { | |
this.collection.bind('add', this.render, this); | |
this.template = _.template($('#activity-list-item-template').html()); | |
}, | |
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.collection.bind('add', this.add, this); | |
this.template = _.template($('#activity-list-item-template').html()); | |
}, | |
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.Activities = Backbone.Collection.extend({ | |
model: exercise.Activity, | |
url: "exercise.json", | |
comparator: function(activity){ | |
var date = new Date(activity.get('date')); | |
return date.getTime(); | |
} | |
}); |
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.'}); | |
}); |
NewerOlder