X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6384a81fa481cb43fddca23742e37761592be66d..bb42027c8fd9ed17234381d3c366c387a20592f0:/views/tabs/tabs.js diff --git a/views/tabs/tabs.js b/views/tabs/tabs.js index de776c6..2a0bfb9 100644 --- a/views/tabs/tabs.js +++ b/views/tabs/tabs.js @@ -26,23 +26,29 @@ define([ this.nodes = { tabBar: this.$('.rng-view-tabs-tabBar'), content: this.$('.rng-view-tabs-content') - } + }; 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); }, @@ -51,9 +57,16 @@ define([ if(slug !== this.selectedTab && this.contents[slug]) { this.trigger('leaving', this.selectedTab); - if(this.selectedTab) - this.contents[this.selectedTab].detach(); + if(this.selectedTab) { + var toDetach = this.contents[this.selectedTab]; + if(toDetach.onHide) + toDetach.onHide(); + toDetach.detach(); + } this.nodes.content.append(this.contents[slug]); + if(this.contents[slug].onShow) { + this.contents[slug].onShow(); + } this.nodes.tabBar.find('.active').removeClass('active'); this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active'); @@ -71,6 +84,10 @@ define([ return this.selectedTab; }, + tabExists: function(slug) { + return this.nodes.tabBar.find('a[href="#'+ slug + '"]').length > 0; + }, + /* Events */ _onTabTitleClicked: function(e) { @@ -86,7 +103,7 @@ define([ return { View: View - } + }; }); \ No newline at end of file