Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created April 2, 2010 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/353465 to your computer and use it in GitHub Desktop.
Save ryanflorence/353465 to your computer and use it in GitHub Desktop.
// app reflects server-side pages
var App = {
Store: {
Index: {},
Product: {},
Category: {},
ContentPage: {}
}
};
// A class for each page
App.Store.Index = new Class({ /* class logic goes here */ });
App.Store.Product = new Class({ /* class logic goes here */ });
App.Store.Category = new Class({ /* class logic goes here */ });
App.Store.ContentPage = new Class({ /* class logic goes here */ });
var App = new Class({
Implements: [Options,Events],
options: {
// options, sometimes put selectors for 'nodes' up here
},
initialize: function(options){
// elements on the page
this.nodes = {
nav: $('main-nav'),
slideshows: $$('.slideshow'),
sidebar: $('sidebar')
};
// bound events so I can remove them later (and keep things more organized)
this.bound = {
navClick: this.navClick.bind(this),
showComplete: this.showComplete.bind(this),
hideSidebar: this.hideSidebar.bind(this)
};
// properties
this.property = 0;
// stuff to run up front
this.build().setup().attach();
},
build: function(){
// create new elements with javascript
return this;
},
setup: function(){
// instantiate other objects, and do any other random stuff
this.nodes.slideshows.each(function(element){
this.slideshows.push(new Slideshow(element,{ duration: 3000, transition: 'crossFade' }));
}, this);
return this;
},
attach: function(){
// element events
this.nodes.sidebar.addEvent('click', this.bound.hideSidebar);
this.nodes.nav.each(function(element){
element.addEvent('click', this.bound.navClick);
}, this);
// instance events
this.slideshows.each(function(slideshow){
slideshow.addEvent('showComplete', this.bound.showComplete);
}, this);
return this;
},
// event handlers
navClick: function(){
// logic when the nav is clicked
return this;
},
showComplete: function(){
// logic to do whenever a slideshow is complete
return this;
},
sidebarHide: function(){
this.nodes.sidebar.hide();
return this;
},
// any other helper methods
tellTheTruth: function(){
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment