Skip to content

Instantly share code, notes, and snippets.

@ericf
Created June 12, 2012 00:32
Show Gist options
  • Select an option

  • Save ericf/2913659 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/2913659 to your computer and use it in GitHub Desktop.
YUI().use('app-base', function (Y) {
Y.BasicView = Y.Base.create('basicView', Y.View, [], {
render: function () {
this.get('container').set('text', this.get('text'));
return this;
}
});
Y.CompositeView = Y.Base.create('compositeView', Y.View, [], {
initializer: function () {
this.after(['sidebarChange', 'mainChange'], this.render, this);
},
render: function () {
var container = this.get('container');
container.get('children').remove();
container.append(this.get('sidebar').get('container'));
container.append(this.get('main').get('container'));
return this;
}
});
var app = new Y.App({
serverRouting: false,
linkSelector : '#nav a',
views: {
sidebar: {type: 'BasicView'},
main : {type: 'BasicView'},
page: {
type : 'CompositeView',
preserve: true
}
}
});
app.route('*', function (req, res, next) {
var sidebar = this.get('sidebar');
if (!sidebar) {
sidebar = this.createView('sidebar', {text: 'Sidebar'});
this.set('sidebar', sidebar.render());
}
next();
});
app.route('/', function (req, res) {
this.showPage(this.createView('main', {text: 'Home'}));
});
app.route('/foo', function (req, res) {
this.showPage(this.createView('main', {text: 'Foo'}));
});
app.showPage = function (mainView) {
this.showView('page', {
sidebar: this.get('sidebar'),
main : mainView.render()
}, {
update: true
});
};
app.render().dispatch();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment