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, i': '_onTabTitleClicked'
\r
16 initialize: function(options) {
\r
17 this.options = options || {};
\r
18 this.template = _.template(mainTemplate),
\r
19 this.handleTemplate = _.template(handleTemplate);
\r
21 this.selectedTab = null;
\r
24 render: function() {
\r
25 this.$el.html(this.template());
\r
27 tabBar: this.$('.rng-view-tabs-tabBar'),
\r
28 content: this.$('.rng-view-tabs-content')
\r
31 if(this.options.stacked) {
\r
32 this.nodes.tabBar.addClass('nav-stacked nav-pills').removeClass('nav-tabs');
\r
34 if(this.options.position === 'right') {
\r
35 this.$el.addClass('tabs-right');
\r
36 this.nodes.content.addClass('tab-content');
\r
41 addTab: function(title, slug, content) {
\r
42 if(this.contents[slug]) {
\r
43 this.contents[slug].detach();
\r
45 this.contents[slug] = content;
\r
47 var text = (typeof title === 'string') ? title : (title.text || '');
\r
48 var icon = title.icon || null;
\r
50 if(!this.tabExists(slug))
\r
51 this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug}));
\r
52 if(!this.selectedTab)
\r
53 this.selectTab(slug);
\r
56 selectTab: function(slug) {
\r
57 if(slug !== this.selectedTab && this.contents[slug]) {
\r
58 this.trigger('leaving', this.selectedTab);
\r
60 if(this.selectedTab)
\r
61 this.contents[this.selectedTab].detach();
\r
62 this.nodes.content.append(this.contents[slug]);
\r
63 this.nodes.tabBar.find('.active').removeClass('active');
\r
64 this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active');
\r
66 var prevSlug = this.selectedTab;
\r
67 this.selectedTab = slug;
\r
68 this.trigger('tabSelected', {slug: slug, prevSlug: prevSlug});
\r
72 getAsView: function() {
\r
76 getCurrentSlug: function() {
\r
77 return this.selectedTab;
\r
80 tabExists: function(slug) {
\r
81 return this.nodes.tabBar.find('a[href="#'+ slug + '"]').length > 0;
\r
86 _onTabTitleClicked: function(e) {
\r
88 var target = $(e.target);
\r
90 target = target.parent();
\r
91 var slug = target.attr('href').substr(1);
\r
92 this.selectTab(slug);
\r