Skip to content

Instantly share code, notes, and snippets.

@ericf
Created April 13, 2012 18:37
Show Gist options
  • Select an option

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

Select an option

Save ericf/2379047 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Y.App + Y.TabView</title>
</head>
<body class="yui3-skin-sam">
<script src="http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js"></script>
<script>
YUI({
// filter: 'raw',
// combine: false
}).use('app-base', 'tabview', function (Y) {
Y.MainView = Y.Base.create('view', Y.View, [], {
initializer: function () {
this.tabView = new Y.TabView({
children: [{
label : 'foo',
content: '<p>foo content</p>'
}, {
label : 'bar',
content: '<p>bar content</p>'
}, {
label : 'baz',
content: '<p>baz content</p>'
}]
});
this.tabView.addTarget(this);
},
render: function () {
this.tabView.render(this.get('container'));
return this;
}
});
var app = new Y.App({
root : '/',
serverRouting: false,
views: {
main: {
type : 'MainView',
preserve: true
}
}
});
app.route('*', function (req) {
var label = req.path.substring(1);
this.showView('main', null, function (view) {
var tabView = view.tabView;
tabView.some(function (tab, index) {
if (tab.get('label') === label) {
tabView.selectChild(index);
return true;
}
});
});
});
app.after('*:selectionChange', function (e) {
this.navigate(e.newVal.get('label'));
});
app.render().dispatch();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment