2 'libs/text!./templates/main.html',
\r
3 'libs/text!./templates/handle.html',
\r
4 'libs/underscore-min',
\r
6 ], function(mainTemplate, handleTemplate, _, Backbone) {
\r
9 var View = Backbone.View.extend({
\r
10 className: 'rng-view-tabs',
\r
13 'click ul a': '_onTabTitleClicked'
\r
16 initialize: function() {
\r
17 this.template = _.template(mainTemplate),
\r
18 this.handleTemplate = _.template(handleTemplate);
\r
20 this.selectedTab = null;
\r
23 render: function() {
\r
24 this.$el.html(this.template());
\r
26 tabBar: this.$('.rng-view-tabs-tabBar'),
\r
27 content: this.$('.rng-view-tabs-content')
\r
31 addTab: function(title, slug, content) {
\r
32 if(this.contents[slug])
\r
34 this.contents[slug] = content;
\r
35 this.nodes.tabBar.append(this.handleTemplate({title:title, slug: slug}));
\r
36 if(!this.selectedTab)
\r
37 this.selectTab(slug);
\r
40 selectTab: function(slug) {
\r
41 if(slug !== this.selectedTab && this.contents[slug]) {
\r
42 this.trigger('leaving', this.selectedTab);
\r
44 if(this.selectedTab)
\r
45 this.contents[this.selectedTab].detach();
\r
46 this.nodes.content.append(this.contents[slug]);
\r
47 this.nodes.tabBar.find('.active').removeClass('active');
\r
48 this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active');
\r
50 this.selectedTab = slug;
\r
51 this.trigger('tabSelected', slug);
\r
57 _onTabTitleClicked: function(e) {
\r
59 var slug = $(e.target).attr('href').substr(1);
\r
60 this.selectTab(slug);
\r