Skip to content

Instantly share code, notes, and snippets.

@phillbaker
Created March 21, 2012 15:30
Show Gist options
  • Save phillbaker/2148481 to your computer and use it in GitHub Desktop.
Save phillbaker/2148481 to your computer and use it in GitHub Desktop.
Phonegap-JQuery app boilerplate
(function(){
// Geo namespace
var App;
if (typeof exports !== 'undefined') {
App = exports;
} else {
App = this.App = {};
}
// options
App.options = {
foo: "bar",
apikey: '00000000000000000000000000000'
};
// contains set of helpers
App.Service = (function(key) {
// api clients
var apiClient = new example.ApiClient(apikey);
// public api
return {
// different functions
fetch: function(foo, bar, callbacks) {
}
}
});
// init
App.init = function(ops) {
_.extend(App.options, ops);
// create views
new FooView({collection: locations, model: currentLocation});
}
// represents a model
var Foo = Backbone.Model.extend({
// functions
foo: function() {
return 'bar';
},
phone: function() {
var phone = this.get('phone');
if (typeof phone !== "undefined") {
phone = phone.replace('+1', '');
}
return phone;
}
});
// represents a collection
var Foos = Backbone.Collection.extend({
model: Foo
});
// a Foo view
var FooView = Backbone.View.extend({
initialize: function() {
this.el = $('#elem');
_.bindAll(this, "render");
var renderDeb = _.debounce(this.render, 400);
this.collection.bind('add', renderDeb);
},
render: function() {
//var foo = this.collection.at(0);
//this.el.html("<ol><li>"+foo.get('foo')+"</li></ol>");
var self = this;
this.el.html('');
this.collection.each(function(location, index) {
_.extend(location.attributes, {index: index});
self.el.append(self.template(location.attributes));
});
}
});
})(this);
$(function(){
App.init({search: "coffee"});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment