X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a5871ab5512d87a33e7e95451d26ee7d3e789742..969ec45041c117313a69c01d49edcc971d46d4b8:/modules/tabsManager.js diff --git a/modules/tabsManager.js b/modules/tabsManager.js index a57a47e..1dd857d 100644 --- a/modules/tabsManager.js +++ b/modules/tabsManager.js @@ -6,16 +6,28 @@ rng.modules.tabsManager = function(sandbox) { var tabContent = {}; - function selectTab(tabCode) { - var tabBar = $(view, '#rng-main-tabs'); - var prevTabCode = tabBar.find('li.active a').attr('href').substr(1); + function selectTab(slug) { + var tabBar = view.find('#rng-tabsManager-tabBar'); + + var prevActive = tabBar.find('li.active'); + var prevSlug; + if(prevActive.length) + prevSlug = prevActive.find('a').attr('href').substr(1); + + if(prevSlug == slug) + return; + tabBar.find('li').removeClass('active'); - tabBar.find('a[href=#' + tabCode + ']').parent().addClass('active'); - $(view, '.rng-tab-content').hide(); - $(view, '#rng-tab-content-' + tabCode).show(); + tabBar.find('a[href=#' + slug + ']').parent().addClass('active'); + + if(prevSlug) + tabContent[prevSlug].detach(); + tabContent[slug].appendTo(view.find('#rng-tabsManager-content')); } + + - $('#rng-main-tabs li a').click(function(e) { + view.on('click', 'li a', function(e) { selectTab($(e.target).attr('href').substr(1)); }); @@ -28,8 +40,11 @@ rng.modules.tabsManager = function(sandbox) { return view; }, - addTab: function(title, view) { - tabContent[title] = view; + addTab: function(title, slug, contentView) { + tabContent[slug] = contentView; + view.find('#rng-tabsManager-tabBar').append(sandbox.getTemplate('tabHandle')({title: title, slug: slug})); + if(_.values(tabContent).length === 1) + selectTab(slug); } }