Skip to content

Instantly share code, notes, and snippets.

@nathanpalmer
Created July 31, 2011 02:13
Show Gist options
  • Save nathanpalmer/1116274 to your computer and use it in GitHub Desktop.
Save nathanpalmer/1116274 to your computer and use it in GitHub Desktop.
var ClickCollection = Spine.Model.setup("Click", [
"numberOfClicks"
]);
ClickCollection.include({
hasClickedTooManyTimes: function() {
return this.numberOfClicks >= 3;
},
canClick: function() {
return !this.hasClickedTooManyTimes();
}
});
var ClickController = Spine.Controller.create({
events: {
"click #clicker": "registerClick",
"click #resetter": "resetClicks"
},
proxied: [ "registerClick" ],
bindings: {
"text #clicks": "numberOfClicks",
"enable #clicker": "canClick",
"visible #reset": "hasClickedTooManyTimes"
},
init: function() {
this.initializeBindings(this.model);
},
registerClick: function() {
this.model.updateAttribute("numberOfClicks", this.model.numberOfClicks+1);
},
resetClicks: function() {
this.model.updateAttribute("numberOfClicks", 0)
}
});
ClickController.include(Spine.DataBind);
var Clicker = ClickCollection.create({ numberOfClicks: 0 });
var Controller = ClickController.init({ el: 'body', model:Clicker });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment