X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/b1836c20d64490bf23d3fb12e35dc755e174acd6..0ca7242564aa1a2bdc1ab6891d46cae7d44dd889:/views/tabs/tabs.js diff --git a/views/tabs/tabs.js b/views/tabs/tabs.js index 52c8160..7c94938 100644 --- a/views/tabs/tabs.js +++ b/views/tabs/tabs.js @@ -31,18 +31,24 @@ define([ if(this.options.stacked) { this.nodes.tabBar.addClass('nav-stacked nav-pills').removeClass('nav-tabs'); } + if(this.options.position === 'right') { + this.$el.addClass('tabs-right'); + this.nodes.content.addClass('tab-content'); + } return this; }, addTab: function(title, slug, content) { - if(this.contents[slug]) - return false; + if(this.contents[slug]) { + this.contents[slug].detach(); + } this.contents[slug] = content; var text = (typeof title === 'string') ? title : (title.text || ''); var icon = title.icon || null; - this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug})); + if(!this.tabExists(slug)) + this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug})); if(!this.selectedTab) this.selectTab(slug); }, @@ -57,8 +63,9 @@ define([ this.nodes.tabBar.find('.active').removeClass('active'); this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active'); + var prevSlug = this.selectedTab; this.selectedTab = slug; - this.trigger('tabSelected', slug); + this.trigger('tabSelected', {slug: slug, prevSlug: prevSlug}); } }, @@ -66,6 +73,14 @@ define([ return this.$el; }, + getCurrentSlug: function() { + return this.selectedTab; + }, + + tabExists: function(slug) { + return this.nodes.tabBar.find('a[href="#'+ slug + '"]').length > 0; + }, + /* Events */ _onTabTitleClicked: function(e) {